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)) {
|
||||
auto timer = new QTimer(this);
|
||||
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]() {
|
||||
m_scheduledRequests.remove(editor);
|
||||
cancelRunningRequest(editor);
|
||||
@@ -120,9 +123,6 @@ void CopilotClient::requestCompletions(TextEditorWidget *editor)
|
||||
if (cursor.hasMultipleCursors() || cursor.hasSelection())
|
||||
return;
|
||||
|
||||
if (m_scheduledRequests[editor].cursorPosition != cursor.mainCursor().position())
|
||||
return;
|
||||
|
||||
const Utils::FilePath filePath = editor->textDocument()->filePath();
|
||||
GetCompletionRequest request{
|
||||
{TextDocumentIdentifier(hostPathToServerUri(filePath)),
|
||||
|
@@ -6,9 +6,11 @@
|
||||
#include "copilotclient.h"
|
||||
#include "copilotoptionspage.h"
|
||||
#include "copilotsettings.h"
|
||||
#include "copilottr.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <languageclient/languageclientmanager.h>
|
||||
|
||||
@@ -30,6 +32,18 @@ void CopilotPlugin::initialize()
|
||||
&CopilotSettings::applied,
|
||||
this,
|
||||
&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()
|
||||
|
Reference in New Issue
Block a user