From 07cfae77ba8d45c4f334f03c1c2689168cea8361 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Wed, 15 Sep 2021 09:42:41 +0200 Subject: [PATCH] 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: Idbff154a62d12c432a2cb10d547f78a537e63a3c Reviewed-by: Christian Kandeler --- src/plugins/clangcodemodel/clangdclient.cpp | 6 ------ src/plugins/clangcodemodel/clangdclient.h | 2 -- src/plugins/clangcodemodel/clangmodelmanagersupport.cpp | 9 +++------ 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index dcbf45da420..4eced0d6735 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -1091,12 +1091,6 @@ void ClangdClient::enableTesting() }); } -void ClangdClient::openEditorDocument(TextEditor::BaseTextEditor *editor) -{ - if (!documentOpen(editor->textDocument())) - openDocument(editor->textDocument()); -} - void ClangdClient::Private::handleFindUsagesResult(quint64 key, const QList &locations) { const auto refData = runningFindUsages.find(key); diff --git a/src/plugins/clangcodemodel/clangdclient.h b/src/plugins/clangcodemodel/clangdclient.h index 7c8ef426fcc..440c56e1d54 100644 --- a/src/plugins/clangcodemodel/clangdclient.h +++ b/src/plugins/clangcodemodel/clangdclient.h @@ -52,8 +52,6 @@ public: QVersionNumber versionNumber() const; CppEditor::ClangdSettings::Data settingsData() const; - void openEditorDocument(TextEditor::BaseTextEditor *editor); - void openExtraFile(const Utils::FilePath &filePath, const QString &content = {}); void closeExtraFile(const Utils::FilePath &filePath); diff --git a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp index e8eaf1f5af9..54d2a891e39 100644 --- a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp +++ b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp @@ -321,7 +321,7 @@ void ClangModelManagerSupport::updateLanguageClient( if (Client * const oldClient = clientForProject(project)) LanguageClientManager::shutdownClient(oldClient); ClangdClient * const client = createClient(project, jsonDbDir); - connect(client, &Client::initialized, this, [this, client, project, projectInfo, jsonDbDir] { + connect(client, &Client::initialized, this, [client, project, projectInfo, jsonDbDir] { using namespace ProjectExplorer; if (!SessionManager::hasProject(project)) return; @@ -333,14 +333,11 @@ void ClangModelManagerSupport::updateLanguageClient( 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()); - client->openEditorDocument(editor); + LanguageClientManager::openDocumentWithClient(editor->textDocument(), client); ClangEditorDocumentProcessor::clearTextMarks(editor->textDocument()->filePath()); hasDocuments = true; } @@ -498,7 +495,7 @@ void ClangModelManagerSupport::onEditorOpened(Core::IEditor *editor) ProjectExplorer::Project * const project = ProjectExplorer::SessionManager::projectForFile(document->filePath()); if (ClangdClient * const client = clientForProject(project)) - client->openEditorDocument(qobject_cast(editor)); + LanguageClientManager::openDocumentWithClient(textDocument, client); } }