forked from qt-creator/qt-creator
ClangCodeModel: iterate over documents instead of editors
Makes sure to handle each document just once since we can have multiple editors for the same document. Change-Id: I0d26a9931086d9b6be0c9c93b01f4485716d75e3 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -44,6 +44,7 @@
|
|||||||
#include <coreplugin/messagemanager.h>
|
#include <coreplugin/messagemanager.h>
|
||||||
|
|
||||||
#include <cppeditor/cppcodemodelsettings.h>
|
#include <cppeditor/cppcodemodelsettings.h>
|
||||||
|
#include <cppeditor/cppeditorconstants.h>
|
||||||
#include <cppeditor/cppfollowsymbolundercursor.h>
|
#include <cppeditor/cppfollowsymbolundercursor.h>
|
||||||
#include <cppeditor/cppmodelmanager.h>
|
#include <cppeditor/cppmodelmanager.h>
|
||||||
#include <cppeditor/cppprojectfile.h>
|
#include <cppeditor/cppprojectfile.h>
|
||||||
@@ -93,21 +94,13 @@ static ProjectExplorer::Project *fallbackProject()
|
|||||||
return ProjectExplorer::SessionManager::startupProject();
|
return ProjectExplorer::SessionManager::startupProject();
|
||||||
}
|
}
|
||||||
|
|
||||||
static const QList<TextEditor::BaseTextEditor *> allCppEditors()
|
static const QList<TextEditor::TextDocument *> allCppDocuments()
|
||||||
{
|
{
|
||||||
QList<TextEditor::BaseTextEditor *> cppEditors;
|
const auto isCppDocument = Utils::equal(&Core::IDocument::id,
|
||||||
for (const Core::DocumentModel::Entry * const entry : Core::DocumentModel::entries()) {
|
Utils::Id(CppEditor::Constants::CPPEDITOR_ID));
|
||||||
const auto textDocument = qobject_cast<TextEditor::TextDocument *>(entry->document);
|
const QList<Core::IDocument *> documents
|
||||||
if (!textDocument)
|
= Utils::filtered(Core::DocumentModel::openedDocuments(), isCppDocument);
|
||||||
continue;
|
return Utils::qobject_container_cast<TextEditor::TextDocument *>(documents);
|
||||||
if (const auto cppEditor = qobject_cast<TextEditor::BaseTextEditor *>(Utils::findOrDefault(
|
|
||||||
Core::DocumentModel::editorsForDocument(textDocument), [](Core::IEditor *editor) {
|
|
||||||
return CppEditor::CppModelManager::isCppEditor(editor);
|
|
||||||
}))) {
|
|
||||||
cppEditors << cppEditor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cppEditors;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ClangModelManagerSupport::ClangModelManagerSupport()
|
ClangModelManagerSupport::ClangModelManagerSupport()
|
||||||
@@ -373,13 +366,12 @@ void ClangModelManagerSupport::updateLanguageClient(
|
|||||||
|
|
||||||
// Acquaint the client with all open C++ documents for this project.
|
// Acquaint the client with all open C++ documents for this project.
|
||||||
bool hasDocuments = false;
|
bool hasDocuments = false;
|
||||||
for (TextEditor::BaseTextEditor * const editor : allCppEditors()) {
|
for (TextEditor::TextDocument * const doc : allCppDocuments()) {
|
||||||
TextEditor::TextDocument * const doc = editor->textDocument();
|
|
||||||
const Client * const currentClient = LanguageClientManager::clientForDocument(doc);
|
const Client * const currentClient = LanguageClientManager::clientForDocument(doc);
|
||||||
if (!currentClient || !currentClient->project()
|
if (!currentClient || !currentClient->project()
|
||||||
|| currentClient->state() != Client::Initialized
|
|| currentClient->state() != Client::Initialized
|
||||||
|| project->isKnownFile(doc->filePath())) {
|
|| project->isKnownFile(doc->filePath())) {
|
||||||
LanguageClientManager::openDocumentWithClient(editor->textDocument(), client);
|
LanguageClientManager::openDocumentWithClient(doc, client);
|
||||||
ClangEditorDocumentProcessor::clearTextMarks(doc->filePath());
|
ClangEditorDocumentProcessor::clearTextMarks(doc->filePath());
|
||||||
hasDocuments = true;
|
hasDocuments = true;
|
||||||
}
|
}
|
||||||
@@ -466,15 +458,14 @@ void ClangModelManagerSupport::claimNonProjectSources(ClangdClient *client)
|
|||||||
{
|
{
|
||||||
if (!client)
|
if (!client)
|
||||||
return;
|
return;
|
||||||
for (TextEditor::BaseTextEditor * const editor : allCppEditors()) {
|
for (TextEditor::TextDocument * const doc : allCppDocuments()) {
|
||||||
if (Client * const currentClient = LanguageClientManager::clientForDocument(
|
if (Client * const currentClient = LanguageClientManager::clientForDocument(doc);
|
||||||
editor->textDocument());
|
|
||||||
currentClient && currentClient->state() == Client::Initialized
|
currentClient && currentClient->state() == Client::Initialized
|
||||||
&& (currentClient == client || currentClient->project())) {
|
&& (currentClient == client || currentClient->project())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ClangEditorDocumentProcessor::clearTextMarks(editor->textDocument()->filePath());
|
ClangEditorDocumentProcessor::clearTextMarks(doc->filePath());
|
||||||
client->openDocument(editor->textDocument());
|
client->openDocument(doc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user