forked from qt-creator/qt-creator
Copilot: add command to explicitly request copilot suggestions
Change-Id: I3bf321fc2ebc6d44819c1a799be9207aa3ca59f1 Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -99,7 +99,10 @@ void CopilotClient::scheduleRequest(TextEditorWidget *editor)
|
|||||||
if (!m_scheduledRequests.contains(editor)) {
|
if (!m_scheduledRequests.contains(editor)) {
|
||||||
auto timer = new QTimer(this);
|
auto timer = new QTimer(this);
|
||||||
timer->setSingleShot(true);
|
timer->setSingleShot(true);
|
||||||
connect(timer, &QTimer::timeout, this, [this, editor]() { requestCompletions(editor); });
|
connect(timer, &QTimer::timeout, this, [this, editor]() {
|
||||||
|
if (m_scheduledRequests[editor].cursorPosition == editor->textCursor().position())
|
||||||
|
requestCompletions(editor);
|
||||||
|
});
|
||||||
connect(editor, &TextEditorWidget::destroyed, this, [this, editor]() {
|
connect(editor, &TextEditorWidget::destroyed, this, [this, editor]() {
|
||||||
m_scheduledRequests.remove(editor);
|
m_scheduledRequests.remove(editor);
|
||||||
cancelRunningRequest(editor);
|
cancelRunningRequest(editor);
|
||||||
@@ -120,9 +123,6 @@ void CopilotClient::requestCompletions(TextEditorWidget *editor)
|
|||||||
if (cursor.hasMultipleCursors() || cursor.hasSelection())
|
if (cursor.hasMultipleCursors() || cursor.hasSelection())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (m_scheduledRequests[editor].cursorPosition != cursor.mainCursor().position())
|
|
||||||
return;
|
|
||||||
|
|
||||||
const Utils::FilePath filePath = editor->textDocument()->filePath();
|
const Utils::FilePath filePath = editor->textDocument()->filePath();
|
||||||
GetCompletionRequest request{
|
GetCompletionRequest request{
|
||||||
{TextDocumentIdentifier(hostPathToServerUri(filePath)),
|
{TextDocumentIdentifier(hostPathToServerUri(filePath)),
|
||||||
|
@@ -6,9 +6,11 @@
|
|||||||
#include "copilotclient.h"
|
#include "copilotclient.h"
|
||||||
#include "copilotoptionspage.h"
|
#include "copilotoptionspage.h"
|
||||||
#include "copilotsettings.h"
|
#include "copilotsettings.h"
|
||||||
|
#include "copilottr.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/actionmanager/actionmanager.h>
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
#include <languageclient/languageclientmanager.h>
|
#include <languageclient/languageclientmanager.h>
|
||||||
|
|
||||||
@@ -30,6 +32,18 @@ void CopilotPlugin::initialize()
|
|||||||
&CopilotSettings::applied,
|
&CopilotSettings::applied,
|
||||||
this,
|
this,
|
||||||
&CopilotPlugin::restartClient);
|
&CopilotPlugin::restartClient);
|
||||||
|
|
||||||
|
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CopilotPlugin::extensionsInitialized()
|
void CopilotPlugin::extensionsInitialized()
|
||||||
|
Reference in New Issue
Block a user