LSP: Fix completion assist that could be the wrong provider

When a document is opened that uses a language server, it would not gain
the completion assitance from the language server in some cases.
Instead, the default completion assist provider is used, which in case of
the TextEditor, will only provide basic autocompletion.

The reason is that Client::activateDocument is not called if the document
is not in LanguageClientManager::m_clientForDocument when
Client::openDocument is called. The check is at the end of that function.
When the issue happens, openDocument is called indirectly from
LanguageClientManager::documentOpened.

The fix is to change the order of instructions in
LanguageClientManager::documentOpened so m_clientForDocument is updated
before calling openDocumentWithClient.

This way, the language server's completion assist is really used as it
should.

Change-Id: I0d2b3b8573e97c0c0c4bd517775668d41a4a797b
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Alexis Murzeau
2020-04-26 21:35:49 +02:00
parent 494b9f5287
commit 15419cb145

View File

@@ -458,9 +458,9 @@ void LanguageClientManager::documentOpened(Core::IDocument *document)
clients << startClient(setting); clients << startClient(setting);
} }
for (auto client : clients) { for (auto client : clients) {
openDocumentWithClient(textDocument, client);
if (!m_clientForDocument.contains(textDocument)) if (!m_clientForDocument.contains(textDocument))
m_clientForDocument[textDocument] = client; m_clientForDocument[textDocument] = client;
openDocumentWithClient(textDocument, client);
} }
} }
} }