aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/copilot
diff options
context:
space:
mode:
authorhjk <[email protected]>2023-11-21 14:02:59 +0100
committerhjk <[email protected]>2023-11-22 07:10:09 +0000
commit4f97dc7090cb4673123d8fa6188eae99aff9d38f (patch)
tree4a268fd6a2280d9daf3724e9a5a65b93aae813c1 /src/plugins/copilot
parent21beda0b77be7542098ad234ca283d8c90671d62 (diff)
Copilot: Move plugin class definition to .cpp
Change-Id: Ic21b150c08924a273c3d10a3b386fc7dcb9c8e1a Reviewed-by: Christian Stenger <[email protected]>
Diffstat (limited to 'src/plugins/copilot')
-rw-r--r--src/plugins/copilot/CMakeLists.txt2
-rw-r--r--src/plugins/copilot/copilot.qbs1
-rw-r--r--src/plugins/copilot/copilotclient.cpp8
-rw-r--r--src/plugins/copilot/copilotplugin.cpp217
-rw-r--r--src/plugins/copilot/copilotplugin.h31
5 files changed, 119 insertions, 140 deletions
diff --git a/src/plugins/copilot/CMakeLists.txt b/src/plugins/copilot/CMakeLists.txt
index f50890d0fd2..04b80abc3f3 100644
--- a/src/plugins/copilot/CMakeLists.txt
+++ b/src/plugins/copilot/CMakeLists.txt
@@ -6,7 +6,7 @@ add_qtc_plugin(Copilot
copilotclient.cpp copilotclient.h
copilotconstants.h
copilothoverhandler.cpp copilothoverhandler.h
- copilotplugin.cpp copilotplugin.h
+ copilotplugin.cpp
copilotprojectpanel.cpp copilotprojectpanel.h
copilotsettings.cpp copilotsettings.h
copilotsuggestion.cpp copilotsuggestion.h
diff --git a/src/plugins/copilot/copilot.qbs b/src/plugins/copilot/copilot.qbs
index 6d2b2100472..680c29dd14d 100644
--- a/src/plugins/copilot/copilot.qbs
+++ b/src/plugins/copilot/copilot.qbs
@@ -19,7 +19,6 @@ QtcPlugin {
"copilothoverhandler.cpp",
"copilothoverhandler.h",
"copilotplugin.cpp",
- "copilotplugin.h",
"copilotprojectpanel.cpp",
"copilotprojectpanel.h",
"copilotsettings.cpp",
diff --git a/src/plugins/copilot/copilotclient.cpp b/src/plugins/copilot/copilotclient.cpp
index 6b09882dee9..8a2dec3bb29 100644
--- a/src/plugins/copilot/copilotclient.cpp
+++ b/src/plugins/copilot/copilotclient.cpp
@@ -170,11 +170,11 @@ void CopilotClient::requestCompletions(TextEditorWidget *editor)
if (!isEnabled(project))
return;
- Utils::MultiTextCursor cursor = editor->multiTextCursor();
+ MultiTextCursor cursor = editor->multiTextCursor();
if (cursor.hasMultipleCursors() || cursor.hasSelection() || editor->suggestionVisible())
return;
- const Utils::FilePath filePath = editor->textDocument()->filePath();
+ const FilePath filePath = editor->textDocument()->filePath();
GetCompletionRequest request{
{TextDocumentIdentifier(hostPathToServerUri(filePath)),
documentVersion(filePath),
@@ -198,7 +198,7 @@ void CopilotClient::handleCompletions(const GetCompletionRequest::Response &resp
if (const auto requestParams = m_runningRequests.take(editor).params())
requestPosition = requestParams->position().toPositionInDocument(editor->document());
- const Utils::MultiTextCursor cursors = editor->multiTextCursor();
+ const MultiTextCursor cursors = editor->multiTextCursor();
if (cursors.hasMultipleCursors())
return;
@@ -331,7 +331,7 @@ void CopilotClient::proxyAuthenticationFailed()
m_isAskingForPassword = true;
- auto answer = Utils::PasswordDialog::getUserAndPassword(
+ auto answer = PasswordDialog::getUserAndPassword(
Tr::tr("Copilot"),
Tr::tr("Proxy username and password required:"),
Tr::tr("Do not ask again. This will disable Copilot for now."),
diff --git a/src/plugins/copilot/copilotplugin.cpp b/src/plugins/copilot/copilotplugin.cpp
index 2ad525f5f37..78ca70b3fd9 100644
--- a/src/plugins/copilot/copilotplugin.cpp
+++ b/src/plugins/copilot/copilotplugin.cpp
@@ -1,8 +1,6 @@
// 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 "copilotconstants.h"
#include "copiloticons.h"
@@ -15,6 +13,8 @@
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/statusbarmanager.h>
+#include <extensionsystem/iplugin.h>
+
#include <languageclient/languageclientmanager.h>
#include <texteditor/textdocumentlayout.h>
@@ -22,20 +22,20 @@
#include <QAction>
#include <QToolButton>
+#include <QPointer>
using namespace Utils;
using namespace Core;
using namespace ProjectExplorer;
-namespace Copilot {
-namespace Internal {
+namespace Copilot::Internal {
enum Direction { Previous, Next };
-void cycleSuggestion(TextEditor::TextEditorWidget *editor, Direction direction)
+static void cycleSuggestion(TextEditor::TextEditorWidget *editor, Direction direction)
{
QTextBlock block = editor->textCursor().block();
- if (auto *suggestion = dynamic_cast<CopilotSuggestion *>(
+ if (auto suggestion = dynamic_cast<CopilotSuggestion *>(
TextEditor::TextDocumentLayout::suggestion(block))) {
int index = suggestion->currentCompletion();
if (direction == Previous)
@@ -53,108 +53,119 @@ void cycleSuggestion(TextEditor::TextEditorWidget *editor, Direction direction)
}
}
-void CopilotPlugin::initialize()
+class CopilotPlugin final : public ExtensionSystem::IPlugin
{
- ActionBuilder requestAction(this, Constants::COPILOT_REQUEST_SUGGESTION);
- requestAction.setText(Tr::tr("Request Copilot Suggestion"));
- requestAction.setToolTip(Tr::tr(
- "Request Copilot suggestion at the current editor's cursor position."));
- requestAction.setOnTriggered(this, [this] {
- if (auto editor = TextEditor::TextEditorWidget::currentTextEditorWidget()) {
- if (m_client && m_client->reachable())
- m_client->requestCompletions(editor);
- }
- });
-
- ActionBuilder nextSuggestionAction(this, Constants::COPILOT_NEXT_SUGGESTION);
- nextSuggestionAction.setText(Tr::tr("Show Next Copilot Suggestion"));
- nextSuggestionAction.setToolTip(Tr::tr(
- "Cycles through the received Copilot Suggestions showing the next available Suggestion."));
- nextSuggestionAction.setOnTriggered(this, [] {
- if (auto editor = TextEditor::TextEditorWidget::currentTextEditorWidget())
- cycleSuggestion(editor, Next);
- });
-
- ActionBuilder previousSuggestionAction(this, Constants::COPILOT_PREVIOUS_SUGGESTION);
- previousSuggestionAction.setText(Tr::tr("Show Previous Copilot Suggestion"));
- previousSuggestionAction.setToolTip(Tr::tr("Cycles through the received Copilot Suggestions "
- "showing the previous available Suggestion."));
- previousSuggestionAction.setOnTriggered(this, [] {
- if (auto editor = TextEditor::TextEditorWidget::currentTextEditorWidget())
- cycleSuggestion(editor, Previous);
- });
-
- ActionBuilder disableAction(this, Constants::COPILOT_DISABLE);
- disableAction.setText(Tr::tr("Disable Copilot"));
- disableAction.setToolTip(Tr::tr("Disable Copilot."));
- disableAction.setOnTriggered(this, [] {
- settings().enableCopilot.setValue(true);
- settings().apply();
- });
-
- ActionBuilder enableAction(this, Constants::COPILOT_ENABLE);
- enableAction.setText(Tr::tr("Enable Copilot"));
- enableAction.setToolTip(Tr::tr("Enable Copilot."));
- enableAction.setOnTriggered(this, [] {
- settings().enableCopilot.setValue(false);
- settings().apply();
- });
-
- ActionBuilder toggleAction(this, Constants::COPILOT_TOGGLE);
- toggleAction.setText(Tr::tr("Toggle Copilot"));
- toggleAction.setCheckable(true);
- toggleAction.setChecked(settings().enableCopilot());
- toggleAction.setIcon(COPILOT_ICON.icon());
- toggleAction.setOnTriggered(this, [](bool checked) {
- settings().enableCopilot.setValue(checked);
- settings().apply();
- });
-
- QAction *toggleAct = toggleAction.contextAction();
- QAction *requestAct = requestAction.contextAction();
- auto updateActions = [toggleAct, requestAct] {
- const bool enabled = settings().enableCopilot();
- toggleAct->setToolTip(enabled ? Tr::tr("Disable Copilot.") : Tr::tr("Enable Copilot."));
- toggleAct->setChecked(enabled);
- requestAct->setEnabled(enabled);
- };
-
- connect(&settings().enableCopilot, &BaseAspect::changed, this, updateActions);
-
- updateActions();
-
- auto toggleButton = new QToolButton;
- toggleButton->setDefaultAction(toggleAction.contextAction());
- StatusBarManager::addStatusBarWidget(toggleButton, StatusBarManager::RightCorner);
-
- setupCopilotProjectPanel();
-}
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Copilot.json")
+
+public:
+ void initialize() final
+ {
+ ActionBuilder requestAction(this, Constants::COPILOT_REQUEST_SUGGESTION);
+ requestAction.setText(Tr::tr("Request Copilot Suggestion"));
+ requestAction.setToolTip(Tr::tr(
+ "Request Copilot suggestion at the current editor's cursor position."));
+ requestAction.setOnTriggered(this, [this] {
+ if (auto editor = TextEditor::TextEditorWidget::currentTextEditorWidget()) {
+ if (m_client && m_client->reachable())
+ m_client->requestCompletions(editor);
+ }
+ });
+
+ ActionBuilder nextSuggestionAction(this, Constants::COPILOT_NEXT_SUGGESTION);
+ nextSuggestionAction.setText(Tr::tr("Show Next Copilot Suggestion"));
+ nextSuggestionAction.setToolTip(Tr::tr(
+ "Cycles through the received Copilot Suggestions showing the next available Suggestion."));
+ nextSuggestionAction.setOnTriggered(this, [] {
+ if (auto editor = TextEditor::TextEditorWidget::currentTextEditorWidget())
+ cycleSuggestion(editor, Next);
+ });
+
+ ActionBuilder previousSuggestionAction(this, Constants::COPILOT_PREVIOUS_SUGGESTION);
+ previousSuggestionAction.setText(Tr::tr("Show Previous Copilot Suggestion"));
+ previousSuggestionAction.setToolTip(Tr::tr("Cycles through the received Copilot Suggestions "
+ "showing the previous available Suggestion."));
+ previousSuggestionAction.setOnTriggered(this, [] {
+ if (auto editor = TextEditor::TextEditorWidget::currentTextEditorWidget())
+ cycleSuggestion(editor, Previous);
+ });
+
+ ActionBuilder disableAction(this, Constants::COPILOT_DISABLE);
+ disableAction.setText(Tr::tr("Disable Copilot"));
+ disableAction.setToolTip(Tr::tr("Disable Copilot."));
+ disableAction.setOnTriggered(this, [] {
+ settings().enableCopilot.setValue(true);
+ settings().apply();
+ });
+
+ ActionBuilder enableAction(this, Constants::COPILOT_ENABLE);
+ enableAction.setText(Tr::tr("Enable Copilot"));
+ enableAction.setToolTip(Tr::tr("Enable Copilot."));
+ enableAction.setOnTriggered(this, [] {
+ settings().enableCopilot.setValue(false);
+ settings().apply();
+ });
+
+ ActionBuilder toggleAction(this, Constants::COPILOT_TOGGLE);
+ toggleAction.setText(Tr::tr("Toggle Copilot"));
+ toggleAction.setCheckable(true);
+ toggleAction.setChecked(settings().enableCopilot());
+ toggleAction.setIcon(COPILOT_ICON.icon());
+ toggleAction.setOnTriggered(this, [](bool checked) {
+ settings().enableCopilot.setValue(checked);
+ settings().apply();
+ });
+
+ QAction *toggleAct = toggleAction.contextAction();
+ QAction *requestAct = requestAction.contextAction();
+ auto updateActions = [toggleAct, requestAct] {
+ const bool enabled = settings().enableCopilot();
+ toggleAct->setToolTip(enabled ? Tr::tr("Disable Copilot.") : Tr::tr("Enable Copilot."));
+ toggleAct->setChecked(enabled);
+ requestAct->setEnabled(enabled);
+ };
+
+ connect(&settings().enableCopilot, &BaseAspect::changed, this, updateActions);
+
+ updateActions();
+
+ auto toggleButton = new QToolButton;
+ toggleButton->setDefaultAction(toggleAction.contextAction());
+ StatusBarManager::addStatusBarWidget(toggleButton, StatusBarManager::RightCorner);
+
+ setupCopilotProjectPanel();
+ }
-bool CopilotPlugin::delayedInitialize()
-{
- restartClient();
+ bool delayedInitialize() final
+ {
+ restartClient();
- connect(&settings(), &AspectContainer::applied, this, &CopilotPlugin::restartClient);
+ connect(&settings(), &AspectContainer::applied, this, &CopilotPlugin::restartClient);
- return true;
-}
+ return true;
+ }
-void CopilotPlugin::restartClient()
-{
- LanguageClient::LanguageClientManager::shutdownClient(m_client);
+ void restartClient()
+ {
+ LanguageClient::LanguageClientManager::shutdownClient(m_client);
- if (!settings().nodeJsPath().isExecutableFile())
- return;
- m_client = new CopilotClient(settings().nodeJsPath(), settings().distPath());
-}
+ if (!settings().nodeJsPath().isExecutableFile())
+ return;
+ m_client = new CopilotClient(settings().nodeJsPath(), settings().distPath());
+ }
-ExtensionSystem::IPlugin::ShutdownFlag CopilotPlugin::aboutToShutdown()
-{
- if (!m_client)
- return SynchronousShutdown;
- connect(m_client, &QObject::destroyed, this, &IPlugin::asynchronousShutdownFinished);
- return AsynchronousShutdown;
-}
+ ShutdownFlag aboutToShutdown() final
+ {
+ if (!m_client)
+ return SynchronousShutdown;
+ connect(m_client, &QObject::destroyed, this, &IPlugin::asynchronousShutdownFinished);
+ return AsynchronousShutdown;
+ }
+
+private:
+ QPointer<CopilotClient> m_client;
+};
+
+} // Copilot::Internal
-} // namespace Internal
-} // namespace Copilot
+#include "copilotplugin.moc"
diff --git a/src/plugins/copilot/copilotplugin.h b/src/plugins/copilot/copilotplugin.h
deleted file mode 100644
index 9f709b2a101..00000000000
--- a/src/plugins/copilot/copilotplugin.h
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (C) 2023 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-#pragma once
-
-#include "copilotclient.h"
-
-#include <extensionsystem/iplugin.h>
-
-#include <QPointer>
-
-namespace Copilot {
-namespace Internal {
-
-class CopilotPlugin : public ExtensionSystem::IPlugin
-{
- Q_OBJECT
- Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Copilot.json")
-
-public:
- void initialize() override;
- bool delayedInitialize() override;
- void restartClient();
- ShutdownFlag aboutToShutdown() override;
-
-private:
- QPointer<CopilotClient> m_client;
-};
-
-} // namespace Internal
-} // namespace Copilot