Copilot: do not activate the editor when requesting completions

This has unwanted side effects like closing the completion and switching
the current editor.

Change-Id: Ic0e150f2377a731910e409b9edc959fda670cd99
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
David Schulz
2023-03-02 13:12:56 +01:00
committed by hjk
parent 1da18a4b62
commit 517400e7f6

View File

@@ -37,12 +37,13 @@ DocumentWatcher::DocumentWatcher(CopilotClient *client, TextDocument *textDocume
void DocumentWatcher::getSuggestion()
{
Core::IEditor *editor = Core::EditorManager::instance()->activateEditorForDocument(
m_textDocument);
if (!editor)
return;
TextEditor::TextEditorWidget *textEditorWidget = qobject_cast<TextEditor::TextEditorWidget *>(
editor->widget());
TextEditorWidget *textEditorWidget = nullptr;
for (Core::IEditor *editor : Core::DocumentModel::editorsForDocument(m_textDocument)) {
textEditorWidget = qobject_cast<TextEditorWidget *>(editor->widget());
if (textEditorWidget)
break;
}
if (!textEditorWidget)
return;
@@ -50,12 +51,12 @@ void DocumentWatcher::getSuggestion()
if (cursor.hasMultipleCursors() || cursor.hasSelection())
return;
const int currentCursorPos = cursor.cursors().first().position();
const int currentCursorPos = cursor.mainCursor().position();
m_client->requestCompletion(
m_textDocument->filePath(),
m_client->documentVersion(m_textDocument->filePath()),
Position(editor->currentLine() - 1, editor->currentColumn() - 1),
Position(cursor.mainCursor()),
[this, textEditorWidget, currentCursorPos](const GetCompletionRequest::Response &response) {
if (response.error()) {
qDebug() << "ERROR:" << *response.error();