Clangd: fix opening document with client for project

Using LanguageClientManager::openDocumentWithClient function to assign a
document to a specific server. This function also takes care of
deactivating the document for the old client and opens it if necessary
in the new client.

Fixes: QTCREATORBUG-26205
Change-Id: I3c3a5fbcd3d07c2e492ebffdf7870e4d2cb517d4
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
David Schulz
2021-09-01 15:31:58 +02:00
parent 27f0dd134f
commit dc40af5fa5

View File

@@ -325,15 +325,11 @@ void ClangModelManagerSupport::updateLanguageClient(ProjectExplorer::Project *pr
return;
// Acquaint the client with all open C++ documents for this project.
ClangdClient * const fallbackClient = clientForProject(nullptr);
bool hasDocuments = false;
for (TextEditor::BaseTextEditor * const editor : allCppEditors()) {
if (!project->isKnownFile(editor->textDocument()->filePath()))
continue;
if (fallbackClient && fallbackClient->documentOpen(editor->textDocument()))
fallbackClient->closeDocument(editor->textDocument());
if (!client->documentOpen(editor->textDocument()))
client->openDocument(editor->textDocument());
LanguageClientManager::openDocumentWithClient(editor->textDocument(), client);
ClangEditorDocumentProcessor::clearTextMarks(editor->textDocument()->filePath());
hasDocuments = true;
}