ClangCodeModel: Make some ClangModelManagerSupport methods static

Change-Id: Ie34a89ae01783631c6482cff8d4866595e757be5
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2022-08-01 18:07:41 +02:00
parent df4155f617
commit 2f169bdfcb
7 changed files with 15 additions and 19 deletions

View File

@@ -158,11 +158,11 @@ void ClangGlobalSymbolFilter::prepareSearch(const QString &entry)
m_cppFilter->prepareSearch(entry); m_cppFilter->prepareSearch(entry);
QList<LanguageClient::Client *> clients; QList<LanguageClient::Client *> clients;
for (ProjectExplorer::Project * const project : ProjectExplorer::SessionManager::projects()) { for (ProjectExplorer::Project * const project : ProjectExplorer::SessionManager::projects()) {
LanguageClient::Client * const client if (LanguageClient::Client * const client
= ClangModelManagerSupport::instance()->clientForProject(project); = ClangModelManagerSupport::clientForProject(project)) {
if (client)
clients << client; clients << client;
} }
}
if (!clients.isEmpty()) { if (!clients.isEmpty()) {
static_cast<LanguageClient::WorkspaceLocatorFilter *>(m_lspFilter) static_cast<LanguageClient::WorkspaceLocatorFilter *>(m_lspFilter)
->prepareSearch(entry, clients); ->prepareSearch(entry, clients);
@@ -296,8 +296,8 @@ void ClangdCurrentDocumentFilter::prepareSearch(const QString &entry)
{ {
const auto doc = TextEditor::TextDocument::currentTextDocument(); const auto doc = TextEditor::TextDocument::currentTextDocument();
QTC_ASSERT(doc, return); QTC_ASSERT(doc, return);
if (const ClangdClient * const client = ClangModelManagerSupport::instance() if (const ClangdClient * const client = ClangModelManagerSupport::clientForFile
->clientForFile(doc->filePath()); client && client->reachable()) { (doc->filePath()); client && client->reachable()) {
d->activeFilter = &d->lspFilter; d->activeFilter = &d->lspFilter;
} else { } else {
d->activeFilter = d->cppFilter; d->activeFilter = d->cppFilter;

View File

@@ -42,7 +42,7 @@ ClangdQuickFixFactory::ClangdQuickFixFactory() = default;
void ClangdQuickFixFactory::match(const CppEditor::Internal::CppQuickFixInterface &interface, void ClangdQuickFixFactory::match(const CppEditor::Internal::CppQuickFixInterface &interface,
QuickFixOperations &result) QuickFixOperations &result)
{ {
const auto client = ClangModelManagerSupport::instance()->clientForFile(interface.filePath()); const auto client = ClangModelManagerSupport::clientForFile(interface.filePath());
if (!client) if (!client)
return; return;

View File

@@ -383,10 +383,8 @@ void doSemanticHighlighting(
} }
QMetaObject::invokeMethod(ClangModelManagerSupport::instance(), QMetaObject::invokeMethod(ClangModelManagerSupport::instance(),
[filePath, virtualRanges, docRevision] { [filePath, virtualRanges, docRevision] {
if (ClangdClient * const client if (ClangdClient * const client = ClangModelManagerSupport::clientForFile(filePath))
= ClangModelManagerSupport::instance()->clientForFile(filePath)) {
client->setVirtualRanges(filePath, virtualRanges, docRevision); client->setVirtualRanges(filePath, virtualRanges, docRevision);
}
}, Qt::QueuedConnection); }, Qt::QueuedConnection);
future.reportResults(QVector<HighlightingResult>(results.cbegin(), results.cend())); future.reportResults(QVector<HighlightingResult>(results.cbegin(), results.cend()));
} }

View File

@@ -64,7 +64,7 @@ ClangEditorDocumentProcessor::ClangEditorDocumentProcessor(TextEditor::TextDocum
connect(parser().data(), &CppEditor::BaseEditorDocumentParser::projectPartInfoUpdated, connect(parser().data(), &CppEditor::BaseEditorDocumentParser::projectPartInfoUpdated,
this, &BaseEditorDocumentProcessor::projectPartInfoUpdated); this, &BaseEditorDocumentProcessor::projectPartInfoUpdated);
setSemanticHighlightingChecker([this] { setSemanticHighlightingChecker([this] {
return !ClangModelManagerSupport::instance()->clientForFile(m_document.filePath()); return !ClangModelManagerSupport::clientForFile(m_document.filePath());
}); });
} }
@@ -75,7 +75,7 @@ void ClangEditorDocumentProcessor::semanticRehighlight()
}; };
if (!Utils::contains(Core::EditorManager::visibleEditors(), matchesEditor)) if (!Utils::contains(Core::EditorManager::visibleEditors(), matchesEditor))
return; return;
if (ClangModelManagerSupport::instance()->clientForFile(m_document.filePath())) if (ClangModelManagerSupport::clientForFile(m_document.filePath()))
return; return;
BuiltinEditorDocumentProcessor::semanticRehighlight(); BuiltinEditorDocumentProcessor::semanticRehighlight();
} }

View File

@@ -499,8 +499,7 @@ void ClangModelManagerSupport::updateLanguageClient(
m_generatorSynchronizer.addFuture(future); m_generatorSynchronizer.addFuture(future);
} }
ClangdClient *ClangModelManagerSupport::clientForProject( ClangdClient *ClangModelManagerSupport::clientForProject(const ProjectExplorer::Project *project)
const ProjectExplorer::Project *project) const
{ {
const QList<Client *> clients = Utils::filtered( const QList<Client *> clients = Utils::filtered(
LanguageClientManager::clientsForProject(project), LanguageClientManager::clientsForProject(project),
@@ -525,7 +524,7 @@ ClangdClient *ClangModelManagerSupport::clientForProject(
return clients.empty() ? nullptr : qobject_cast<ClangdClient *>(clients.first()); return clients.empty() ? nullptr : qobject_cast<ClangdClient *>(clients.first());
} }
ClangdClient *ClangModelManagerSupport::clientForFile(const Utils::FilePath &file) const ClangdClient *ClangModelManagerSupport::clientForFile(const Utils::FilePath &file)
{ {
return qobject_cast<ClangdClient *>(LanguageClientManager::clientForFilePath(file)); return qobject_cast<ClangdClient *>(LanguageClientManager::clientForFilePath(file));
} }

View File

@@ -69,8 +69,8 @@ public:
std::unique_ptr<CppEditor::AbstractOverviewModel> createOverviewModel() override; std::unique_ptr<CppEditor::AbstractOverviewModel> createOverviewModel() override;
bool usesClangd(const TextEditor::TextDocument *document) const override; bool usesClangd(const TextEditor::TextDocument *document) const override;
ClangdClient *clientForProject(const ProjectExplorer::Project *project) const; static ClangdClient *clientForProject(const ProjectExplorer::Project *project);
ClangdClient *clientForFile(const Utils::FilePath &file) const; static ClangdClient *clientForFile(const Utils::FilePath &file);
static ClangModelManagerSupport *instance(); static ClangModelManagerSupport *instance();

View File

@@ -2029,7 +2029,7 @@ void ClangdTestExternalChanges::test()
waitForSignalOrTimeout(ClangModelManagerSupport::instance(), waitForSignalOrTimeout(ClangModelManagerSupport::instance(),
&ClangModelManagerSupport::createdClient, timeOutInMs()); &ClangModelManagerSupport::createdClient, timeOutInMs());
QCOMPARE(client(), oldClient); QCOMPARE(client(), oldClient);
QCOMPARE(client(), ClangModelManagerSupport::instance()->clientForProject(project())); QCOMPARE(client(), ClangModelManagerSupport::clientForProject(project()));
const TextDocument * const curDoc = document("main.cpp"); const TextDocument * const curDoc = document("main.cpp");
QVERIFY(curDoc); QVERIFY(curDoc);
QVERIFY(curDoc->marks().isEmpty()); QVERIFY(curDoc->marks().isEmpty());
@@ -2044,8 +2044,7 @@ void ClangdTestExternalChanges::test()
otherSource.close(); otherSource.close();
QVERIFY(waitForSignalOrTimeout(ClangModelManagerSupport::instance(), QVERIFY(waitForSignalOrTimeout(ClangModelManagerSupport::instance(),
&ClangModelManagerSupport::createdClient, timeOutInMs())); &ClangModelManagerSupport::createdClient, timeOutInMs()));
ClangdClient * const newClient = ClangModelManagerSupport::instance() ClangdClient * const newClient = ClangModelManagerSupport::clientForProject(project());
->clientForProject(project());
QVERIFY(newClient); QVERIFY(newClient);
QVERIFY(newClient != oldClient); QVERIFY(newClient != oldClient);
newClient->enableTesting(); newClient->enableTesting();