77 lines
1.8 KiB
C++
77 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <ktexteditor/cursor.h>
|
|
#include <unordered_map>
|
|
|
|
#include <KTextEditor/MainWindow>
|
|
#include <KTextEditor/Plugin>
|
|
#include <KXMLGUIClient>
|
|
|
|
#include <QList>
|
|
#include <QAction>
|
|
#include <QWebSocket>
|
|
#include <QPointer>
|
|
#include <QtCore>
|
|
|
|
class KateAiPlugin : public KTextEditor::Plugin
|
|
{
|
|
Q_OBJECT
|
|
private:
|
|
QWebSocket m_webSocket;
|
|
QUrl m_serverUrl;
|
|
|
|
private:
|
|
void onConnected();
|
|
|
|
int configPages() const override
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
KTextEditor::ConfigPage *configPage(int number = 0, QWidget *parent = nullptr) override;
|
|
|
|
public:
|
|
explicit KateAiPlugin(QObject *parent = nullptr, const QList<QVariant> & = QList<QVariant>());
|
|
~KateAiPlugin() override;
|
|
|
|
QObject *createView(KTextEditor::MainWindow *mainWindow) override;
|
|
|
|
void readConfig();
|
|
void reconnect();
|
|
Q_SIGNAL void instructChanged();
|
|
};
|
|
|
|
class KateAiPluginView : public QObject, public KXMLGUIClient
|
|
{
|
|
Q_OBJECT
|
|
private:
|
|
struct Request
|
|
{
|
|
KTextEditor::Cursor cursor;
|
|
QPointer<KTextEditor::Document> document;
|
|
};
|
|
|
|
KTextEditor::MainWindow *m_mainWindow;
|
|
QPointer<QWebSocket> m_webSocket;
|
|
QHash<int, Request> m_requests;
|
|
bool m_useInstruct = false;
|
|
|
|
|
|
private:
|
|
void generate();
|
|
void socketMessage(const QString& message);
|
|
static QStringList getIncludePaths(const QString& text);
|
|
QString assembleContext(QPointer<KTextEditor::Document> document, const KTextEditor::Cursor& cursor);
|
|
|
|
QPointer<KTextEditor::Document> activeDocument() const;
|
|
KTextEditor::Cursor getCurrentCursor() const;
|
|
|
|
|
|
public:
|
|
KateAiPluginView(KateAiPlugin *plugin, KTextEditor::MainWindow *mainwindow, QPointer<QWebSocket> webSocket, bool instruct = false);
|
|
~KateAiPluginView() override;
|
|
void setInstruct(bool instruct);
|
|
|
|
Q_SIGNAL void reconnect();
|
|
};
|