2023-01-20 07:09:01 +01:00
|
|
|
// Copyright (C) 2023 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
|
|
|
|
|
|
|
|
#include "copilotplugin.h"
|
|
|
|
|
|
|
|
|
|
#include "copilotclient.h"
|
|
|
|
|
#include "copilotoptionspage.h"
|
|
|
|
|
#include "copilotsettings.h"
|
2023-03-14 13:07:45 +01:00
|
|
|
#include "copilottr.h"
|
2023-01-20 07:09:01 +01:00
|
|
|
|
2023-03-14 13:07:45 +01:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2023-03-02 13:56:11 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2023-03-14 13:07:45 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2023-03-02 13:56:11 +01:00
|
|
|
|
2023-03-09 11:08:57 +01:00
|
|
|
#include <languageclient/languageclientmanager.h>
|
|
|
|
|
|
2023-03-02 13:56:11 +01:00
|
|
|
#include <texteditor/texteditor.h>
|
2023-01-20 07:09:01 +01:00
|
|
|
|
2023-03-15 14:05:54 +01:00
|
|
|
#include <QAction>
|
|
|
|
|
|
2023-01-20 07:09:01 +01:00
|
|
|
using namespace Utils;
|
2023-03-02 13:56:11 +01:00
|
|
|
using namespace Core;
|
2023-01-20 07:09:01 +01:00
|
|
|
|
|
|
|
|
namespace Copilot {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
void CopilotPlugin::initialize()
|
|
|
|
|
{
|
2023-03-02 13:56:11 +01:00
|
|
|
CopilotSettings::instance().readSettings(ICore::settings());
|
2023-01-20 07:09:01 +01:00
|
|
|
|
2023-03-09 11:08:57 +01:00
|
|
|
restartClient();
|
2023-01-20 07:09:01 +01:00
|
|
|
|
2023-03-09 11:08:57 +01:00
|
|
|
connect(&CopilotSettings::instance(),
|
|
|
|
|
&CopilotSettings::applied,
|
|
|
|
|
this,
|
|
|
|
|
&CopilotPlugin::restartClient);
|
2023-03-14 13:07:45 +01:00
|
|
|
|
|
|
|
|
QAction *action = new QAction(this);
|
|
|
|
|
action->setText(Tr::tr("Request Copilot Suggestion"));
|
|
|
|
|
action->setToolTip(Tr::tr("Request Copilot Suggestion at the current editors cursor position."));
|
|
|
|
|
|
|
|
|
|
QObject::connect(action, &QAction::triggered, this, [this] {
|
|
|
|
|
if (auto editor = TextEditor::TextEditorWidget::currentTextEditorWidget()) {
|
|
|
|
|
if (m_client->reachable())
|
|
|
|
|
m_client->requestCompletions(editor);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
ActionManager::registerAction(action, "Copilot.RequestSuggestion");
|
2023-01-20 07:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CopilotPlugin::extensionsInitialized()
|
|
|
|
|
{
|
2023-04-20 10:40:54 +02:00
|
|
|
(void)CopilotOptionsPage::instance();
|
2023-01-20 07:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-09 11:08:57 +01:00
|
|
|
void CopilotPlugin::restartClient()
|
|
|
|
|
{
|
|
|
|
|
LanguageClient::LanguageClientManager::shutdownClient(m_client);
|
2023-05-15 18:32:22 +02:00
|
|
|
m_client = new CopilotClient(CopilotSettings::instance().nodeJsPath(),
|
|
|
|
|
CopilotSettings::instance().distPath());
|
2023-03-09 11:08:57 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-20 07:09:01 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Copilot
|