forked from qt-creator/qt-creator
ClangGlobalSymbolFilter: Avoid custom prepareSearch() for aggregate
Delegate prepareSearch() directly to m_lspFilter aggregate inside ClangGlobalSymbolFilter::prepareSearch(). This helps to keep filters' responsibilites more self-contained. Disambiguate different overloads of WorkspaceLocatorFilter::prepareSearch(). Change-Id: I98f25d01ad713a8c209a07bfd0d05b3ddcf16948 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
using namespace Core;
|
||||
using namespace LanguageClient;
|
||||
using namespace LanguageServerProtocol;
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
|
||||
namespace ClangCodeModel {
|
||||
@@ -30,6 +31,17 @@ 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:
|
||||
@@ -56,6 +68,10 @@ public:
|
||||
setHidden(true);
|
||||
setMaxResultCount(MaxResultCount);
|
||||
}
|
||||
void prepareSearch(const QString &entry) override
|
||||
{
|
||||
prepareSearchForClients(entry, clientsForOpenProjects());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -84,6 +100,10 @@ public:
|
||||
setHidden(true);
|
||||
setMaxResultCount(MaxResultCount);
|
||||
}
|
||||
void prepareSearch(const QString &entry) override
|
||||
{
|
||||
prepareSearchForClients(entry, clientsForOpenProjects());
|
||||
}
|
||||
};
|
||||
|
||||
class CppFunctionsFilter : public CppEditor::CppFunctionsFilter
|
||||
@@ -112,6 +132,10 @@ public:
|
||||
setHidden(true);
|
||||
setMaxResultCount(MaxResultCount);
|
||||
}
|
||||
void prepareSearch(const QString &entry) override
|
||||
{
|
||||
prepareSearchForClients(entry, clientsForOpenProjects());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -121,7 +145,7 @@ ClangGlobalSymbolFilter::ClangGlobalSymbolFilter()
|
||||
}
|
||||
|
||||
ClangGlobalSymbolFilter::ClangGlobalSymbolFilter(ILocatorFilter *cppFilter,
|
||||
WorkspaceLocatorFilter *lspFilter)
|
||||
ILocatorFilter *lspFilter)
|
||||
: m_cppFilter(cppFilter), m_lspFilter(lspFilter)
|
||||
{
|
||||
setId(CppEditor::Constants::LOCATOR_FILTER_ID);
|
||||
@@ -139,13 +163,7 @@ ClangGlobalSymbolFilter::~ClangGlobalSymbolFilter()
|
||||
void ClangGlobalSymbolFilter::prepareSearch(const QString &entry)
|
||||
{
|
||||
m_cppFilter->prepareSearch(entry);
|
||||
QList<Client *> clients;
|
||||
for (ProjectExplorer::Project * const project : ProjectExplorer::ProjectManager::projects()) {
|
||||
if (Client * const client = ClangModelManagerSupport::clientForProject(project))
|
||||
clients << client;
|
||||
}
|
||||
if (!clients.isEmpty())
|
||||
m_lspFilter->prepareSearch(entry, clients);
|
||||
m_lspFilter->prepareSearch(entry);
|
||||
}
|
||||
|
||||
QList<LocatorFilterEntry> ClangGlobalSymbolFilter::matchesFor(
|
||||
|
@@ -15,7 +15,7 @@ class ClangGlobalSymbolFilter : public Core::ILocatorFilter
|
||||
public:
|
||||
ClangGlobalSymbolFilter();
|
||||
ClangGlobalSymbolFilter(Core::ILocatorFilter *cppFilter,
|
||||
LanguageClient::WorkspaceLocatorFilter *lspFilter);
|
||||
Core::ILocatorFilter *lspFilter);
|
||||
~ClangGlobalSymbolFilter() override;
|
||||
|
||||
private:
|
||||
@@ -23,7 +23,7 @@ private:
|
||||
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
||||
const QString &entry) override;
|
||||
Core::ILocatorFilter * const m_cppFilter;
|
||||
LanguageClient::WorkspaceLocatorFilter * const m_lspFilter;
|
||||
Core::ILocatorFilter * const m_lspFilter;
|
||||
};
|
||||
|
||||
class ClangClassesFilter : public ClangGlobalSymbolFilter
|
||||
|
@@ -216,21 +216,23 @@ WorkspaceLocatorFilter::WorkspaceLocatorFilter(const QVector<SymbolKind> &filter
|
||||
|
||||
void WorkspaceLocatorFilter::prepareSearch(const QString &entry)
|
||||
{
|
||||
prepareSearch(entry, LanguageClientManager::clients(), false);
|
||||
prepareSearchHelper(entry, LanguageClientManager::clients(), false);
|
||||
}
|
||||
|
||||
void WorkspaceLocatorFilter::prepareSearch(const QString &entry, const QList<Client *> &clients)
|
||||
void WorkspaceLocatorFilter::prepareSearchForClients(const QString &entry, const QList<Client *> &clients)
|
||||
{
|
||||
prepareSearch(entry, clients, true);
|
||||
prepareSearchHelper(entry, clients, true);
|
||||
}
|
||||
|
||||
void WorkspaceLocatorFilter::prepareSearch(const QString &entry,
|
||||
const QList<Client *> &clients,
|
||||
bool force)
|
||||
void WorkspaceLocatorFilter::prepareSearchHelper(const QString &entry,
|
||||
const QList<Client *> &clients, bool force)
|
||||
{
|
||||
m_pendingRequests.clear();
|
||||
m_results.clear();
|
||||
|
||||
if (clients.isEmpty())
|
||||
return;
|
||||
|
||||
WorkspaceSymbolParams params;
|
||||
params.setQuery(entry);
|
||||
if (m_maxResultCount > 0)
|
||||
|
@@ -77,7 +77,7 @@ public:
|
||||
/// request workspace symbols for all clients with enabled locator
|
||||
void prepareSearch(const QString &entry) override;
|
||||
/// force request workspace symbols for all given clients
|
||||
void prepareSearch(const QString &entry, const QList<Client *> &clients);
|
||||
void prepareSearchForClients(const QString &entry, const QList<Client *> &clients);
|
||||
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
||||
const QString &entry) override;
|
||||
signals:
|
||||
@@ -89,7 +89,7 @@ protected:
|
||||
void setMaxResultCount(qint64 limit) { m_maxResultCount = limit; }
|
||||
|
||||
private:
|
||||
void prepareSearch(const QString &entry, const QList<Client *> &clients, bool force);
|
||||
void prepareSearchHelper(const QString &entry, const QList<Client *> &clients, bool force);
|
||||
void handleResponse(Client *client,
|
||||
const LanguageServerProtocol::WorkspaceSymbolRequest::Response &response);
|
||||
|
||||
|
Reference in New Issue
Block a user