LocatorMatcher: Introduce LocatorMatcherTaskCreator

Register cpp and lsp matchers for all symbols,
classes and functions.

Change-Id: Id85c8164077ec395dac7e6ff45acc89db9e6ae08
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Jarek Kobus
2023-04-05 08:12:43 +02:00
parent dde4a7ebf5
commit 0c3789726d
6 changed files with 90 additions and 14 deletions

View File

@@ -32,17 +32,6 @@ namespace Internal {
const int MaxResultCount = 10000;
static QList<Client *> clientsForOpenProjects()
{
QSet<Client *> clients;
const QList<Project *> projects = ProjectManager::projects();
for (Project *project : projects) {
if (Client *client = ClangModelManagerSupport::clientForProject(project))
clients << client;
}
return clients.values();
}
class CppLocatorFilter : public CppEditor::CppLocatorFilter
{
public:
@@ -72,7 +61,7 @@ public:
}
void prepareSearch(const QString &entry) override
{
prepareSearchForClients(entry, clientsForOpenProjects());
prepareSearchForClients(entry, ClangModelManagerSupport::clientsForOpenProjects());
}
};
@@ -105,7 +94,7 @@ public:
}
void prepareSearch(const QString &entry) override
{
prepareSearchForClients(entry, clientsForOpenProjects());
prepareSearchForClients(entry, ClangModelManagerSupport::clientsForOpenProjects());
}
};
@@ -138,7 +127,7 @@ public:
}
void prepareSearch(const QString &entry) override
{
prepareSearchForClients(entry, clientsForOpenProjects());
prepareSearchForClients(entry, ClangModelManagerSupport::clientsForOpenProjects());
}
};

View File

@@ -205,6 +205,21 @@ ClangModelManagerSupport::ClangModelManagerSupport()
cppModelManager()->setLocatorFilter(std::make_unique<ClangGlobalSymbolFilter>());
cppModelManager()->setClassesFilter(std::make_unique<ClangClassesFilter>());
cppModelManager()->setFunctionsFilter(std::make_unique<ClangFunctionsFilter>());
// Setup matchers
using WorkspaceMatcherCreator = std::function<Core::LocatorMatcherTask(Client *, int)>;
const auto matcherCreator = [](const WorkspaceMatcherCreator &creator) {
const QList<Client *> clients = clientsForOpenProjects();
QList<LocatorMatcherTask> matchers;
for (Client *client : clients)
matchers << creator(client, 10000);
return matchers;
};
LocatorMatcher::addLocatorMatcherCreator(
[matcherCreator] { return matcherCreator(&LanguageClient::workspaceLocatorMatcher); });
LocatorMatcher::addClassMatcherCreator(
[matcherCreator] { return matcherCreator(&LanguageClient::workspaceClassMatcher); });
LocatorMatcher::addFunctionMatcherCreator(
[matcherCreator] { return matcherCreator(&LanguageClient::workspaceFunctionMatcher); });
EditorManager *editorManager = EditorManager::instance();
connect(editorManager, &EditorManager::editorOpened,
@@ -587,6 +602,17 @@ void ClangModelManagerSupport::updateLanguageClient(Project *project)
m_generatorSynchronizer.addFuture(future);
}
QList<Client *> ClangModelManagerSupport::clientsForOpenProjects()
{
QSet<Client *> clients;
const QList<Project *> projects = ProjectManager::projects();
for (Project *project : projects) {
if (Client *client = ClangModelManagerSupport::clientForProject(project))
clients << client;
}
return clients.values();
}
ClangdClient *ClangModelManagerSupport::clientForProject(const Project *project)
{
if (sessionModeEnabled())

View File

@@ -24,6 +24,7 @@ QT_END_NAMESPACE
namespace Core { class IEditor; }
namespace CppEditor { class RefactoringEngineInterface; }
namespace LanguageClient { class Client; }
namespace TextEditor { class TextEditorWidget; }
namespace ClangCodeModel {
@@ -45,6 +46,7 @@ public:
TextEditor::TextDocument *baseTextDocument) override;
bool usesClangd(const TextEditor::TextDocument *document) const override;
static QList<LanguageClient::Client *> clientsForOpenProjects();
static ClangdClient *clientForProject(const ProjectExplorer::Project *project);
static ClangdClient *clientForFile(const Utils::FilePath &file);