forked from qt-creator/qt-creator
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 <christian.kandeler@qt.io>
This commit is contained in:
@@ -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<Location> &locations)
|
void ClangdClient::Private::handleFindUsagesResult(quint64 key, const QList<Location> &locations)
|
||||||
{
|
{
|
||||||
const auto refData = runningFindUsages.find(key);
|
const auto refData = runningFindUsages.find(key);
|
||||||
|
@@ -52,8 +52,6 @@ public:
|
|||||||
QVersionNumber versionNumber() const;
|
QVersionNumber versionNumber() const;
|
||||||
CppEditor::ClangdSettings::Data settingsData() const;
|
CppEditor::ClangdSettings::Data settingsData() const;
|
||||||
|
|
||||||
void openEditorDocument(TextEditor::BaseTextEditor *editor);
|
|
||||||
|
|
||||||
void openExtraFile(const Utils::FilePath &filePath, const QString &content = {});
|
void openExtraFile(const Utils::FilePath &filePath, const QString &content = {});
|
||||||
void closeExtraFile(const Utils::FilePath &filePath);
|
void closeExtraFile(const Utils::FilePath &filePath);
|
||||||
|
|
||||||
|
@@ -321,7 +321,7 @@ void ClangModelManagerSupport::updateLanguageClient(
|
|||||||
if (Client * const oldClient = clientForProject(project))
|
if (Client * const oldClient = clientForProject(project))
|
||||||
LanguageClientManager::shutdownClient(oldClient);
|
LanguageClientManager::shutdownClient(oldClient);
|
||||||
ClangdClient * const client = createClient(project, jsonDbDir);
|
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;
|
using namespace ProjectExplorer;
|
||||||
if (!SessionManager::hasProject(project))
|
if (!SessionManager::hasProject(project))
|
||||||
return;
|
return;
|
||||||
@@ -333,14 +333,11 @@ void ClangModelManagerSupport::updateLanguageClient(
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Acquaint the client with all open C++ documents for this project.
|
// Acquaint the client with all open C++ documents for this project.
|
||||||
ClangdClient * const fallbackClient = clientForProject(nullptr);
|
|
||||||
bool hasDocuments = false;
|
bool hasDocuments = false;
|
||||||
for (TextEditor::BaseTextEditor * const editor : allCppEditors()) {
|
for (TextEditor::BaseTextEditor * const editor : allCppEditors()) {
|
||||||
if (!project->isKnownFile(editor->textDocument()->filePath()))
|
if (!project->isKnownFile(editor->textDocument()->filePath()))
|
||||||
continue;
|
continue;
|
||||||
if (fallbackClient && fallbackClient->documentOpen(editor->textDocument()))
|
LanguageClientManager::openDocumentWithClient(editor->textDocument(), client);
|
||||||
fallbackClient->closeDocument(editor->textDocument());
|
|
||||||
client->openEditorDocument(editor);
|
|
||||||
ClangEditorDocumentProcessor::clearTextMarks(editor->textDocument()->filePath());
|
ClangEditorDocumentProcessor::clearTextMarks(editor->textDocument()->filePath());
|
||||||
hasDocuments = true;
|
hasDocuments = true;
|
||||||
}
|
}
|
||||||
@@ -498,7 +495,7 @@ void ClangModelManagerSupport::onEditorOpened(Core::IEditor *editor)
|
|||||||
ProjectExplorer::Project * const project
|
ProjectExplorer::Project * const project
|
||||||
= ProjectExplorer::SessionManager::projectForFile(document->filePath());
|
= ProjectExplorer::SessionManager::projectForFile(document->filePath());
|
||||||
if (ClangdClient * const client = clientForProject(project))
|
if (ClangdClient * const client = clientForProject(project))
|
||||||
client->openEditorDocument(qobject_cast<TextEditor::BaseTextEditor *>(editor));
|
LanguageClientManager::openDocumentWithClient(textDocument, client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user