forked from qt-creator/qt-creator
ClangGlobalSymbolFilter: Avoid downcasting to WorkspaceLocatorFilter
Store a pointer to WorkspaceLocatorFilter instead of base ILocatorFilter and avoid later downcast to WorkspaceLocatorFilter. Change-Id: I729f60356b287f3b4bddf016e21761a372993928 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
|
using namespace LanguageClient;
|
||||||
using namespace LanguageServerProtocol;
|
using namespace LanguageServerProtocol;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class LspWorkspaceFilter : public LanguageClient::WorkspaceLocatorFilter
|
class LspWorkspaceFilter : public WorkspaceLocatorFilter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LspWorkspaceFilter()
|
LspWorkspaceFilter()
|
||||||
@@ -69,7 +70,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class LspClassesFilter : public LanguageClient::WorkspaceClassLocatorFilter
|
class LspClassesFilter : public WorkspaceClassLocatorFilter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LspClassesFilter() {
|
LspClassesFilter() {
|
||||||
@@ -96,7 +97,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class LspFunctionsFilter : public LanguageClient::WorkspaceMethodLocatorFilter
|
class LspFunctionsFilter : public WorkspaceMethodLocatorFilter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LspFunctionsFilter()
|
LspFunctionsFilter()
|
||||||
@@ -117,7 +118,7 @@ ClangGlobalSymbolFilter::ClangGlobalSymbolFilter()
|
|||||||
}
|
}
|
||||||
|
|
||||||
ClangGlobalSymbolFilter::ClangGlobalSymbolFilter(ILocatorFilter *cppFilter,
|
ClangGlobalSymbolFilter::ClangGlobalSymbolFilter(ILocatorFilter *cppFilter,
|
||||||
ILocatorFilter *lspFilter)
|
WorkspaceLocatorFilter *lspFilter)
|
||||||
: m_cppFilter(cppFilter), m_lspFilter(lspFilter)
|
: m_cppFilter(cppFilter), m_lspFilter(lspFilter)
|
||||||
{
|
{
|
||||||
setId(CppEditor::Constants::LOCATOR_FILTER_ID);
|
setId(CppEditor::Constants::LOCATOR_FILTER_ID);
|
||||||
@@ -136,17 +137,13 @@ ClangGlobalSymbolFilter::~ClangGlobalSymbolFilter()
|
|||||||
void ClangGlobalSymbolFilter::prepareSearch(const QString &entry)
|
void ClangGlobalSymbolFilter::prepareSearch(const QString &entry)
|
||||||
{
|
{
|
||||||
m_cppFilter->prepareSearch(entry);
|
m_cppFilter->prepareSearch(entry);
|
||||||
QList<LanguageClient::Client *> clients;
|
QList<Client *> clients;
|
||||||
for (ProjectExplorer::Project * const project : ProjectExplorer::SessionManager::projects()) {
|
for (ProjectExplorer::Project * const project : ProjectExplorer::SessionManager::projects()) {
|
||||||
if (LanguageClient::Client * const client
|
if (Client * const client = ClangModelManagerSupport::clientForProject(project))
|
||||||
= ClangModelManagerSupport::clientForProject(project)) {
|
|
||||||
clients << client;
|
clients << client;
|
||||||
}
|
}
|
||||||
}
|
if (!clients.isEmpty())
|
||||||
if (!clients.isEmpty()) {
|
m_lspFilter->prepareSearch(entry, clients);
|
||||||
static_cast<LanguageClient::WorkspaceLocatorFilter *>(m_lspFilter)
|
|
||||||
->prepareSearch(entry, clients);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Core::LocatorFilterEntry> ClangGlobalSymbolFilter::matchesFor(
|
QList<Core::LocatorFilterEntry> ClangGlobalSymbolFilter::matchesFor(
|
||||||
@@ -155,16 +152,16 @@ QList<Core::LocatorFilterEntry> ClangGlobalSymbolFilter::matchesFor(
|
|||||||
QList<Core::LocatorFilterEntry> matches = m_cppFilter->matchesFor(future, entry);
|
QList<Core::LocatorFilterEntry> matches = m_cppFilter->matchesFor(future, entry);
|
||||||
const QList<Core::LocatorFilterEntry> lspMatches = m_lspFilter->matchesFor(future, entry);
|
const QList<Core::LocatorFilterEntry> lspMatches = m_lspFilter->matchesFor(future, entry);
|
||||||
if (!lspMatches.isEmpty()) {
|
if (!lspMatches.isEmpty()) {
|
||||||
std::set<std::tuple<Utils::FilePath, int, int>> locations;
|
std::set<std::tuple<FilePath, int, int>> locations;
|
||||||
for (const auto &entry : std::as_const(matches)) {
|
for (const auto &entry : std::as_const(matches)) {
|
||||||
const CppEditor::IndexItem::Ptr item
|
const CppEditor::IndexItem::Ptr item
|
||||||
= qvariant_cast<CppEditor::IndexItem::Ptr>(entry.internalData);
|
= qvariant_cast<CppEditor::IndexItem::Ptr>(entry.internalData);
|
||||||
locations.insert(std::make_tuple(item->filePath(), item->line(), item->column()));
|
locations.insert(std::make_tuple(item->filePath(), item->line(), item->column()));
|
||||||
}
|
}
|
||||||
for (const auto &entry : lspMatches) {
|
for (const auto &entry : lspMatches) {
|
||||||
if (!entry.internalData.canConvert<Utils::Link>())
|
if (!entry.internalData.canConvert<Link>())
|
||||||
continue;
|
continue;
|
||||||
const auto link = qvariant_cast<Utils::Link>(entry.internalData);
|
const auto link = qvariant_cast<Link>(entry.internalData);
|
||||||
if (locations.find(std::make_tuple(link.targetFilePath, link.targetLine,
|
if (locations.find(std::make_tuple(link.targetFilePath, link.targetLine,
|
||||||
link.targetColumn)) == locations.cend()) {
|
link.targetColumn)) == locations.cend()) {
|
||||||
matches << entry; // TODO: Insert sorted?
|
matches << entry; // TODO: Insert sorted?
|
||||||
@@ -205,7 +202,7 @@ ClangFunctionsFilter::ClangFunctionsFilter()
|
|||||||
setDefaultIncludedByDefault(false);
|
setDefaultIncludedByDefault(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
class LspCurrentDocumentFilter : public LanguageClient::DocumentLocatorFilter
|
class LspCurrentDocumentFilter : public DocumentLocatorFilter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LspCurrentDocumentFilter()
|
LspCurrentDocumentFilter()
|
||||||
@@ -228,7 +225,7 @@ private:
|
|||||||
static_cast<SymbolKind>(info.kind()), info.name(),
|
static_cast<SymbolKind>(info.kind()), info.name(),
|
||||||
info.detail().value_or(QString()));
|
info.detail().value_or(QString()));
|
||||||
const Position &pos = info.range().start();
|
const Position &pos = info.range().start();
|
||||||
entry.internalData = QVariant::fromValue(Utils::LineColumn(pos.line(), pos.character()));
|
entry.internalData = QVariant::fromValue(LineColumn(pos.line(), pos.character()));
|
||||||
entry.extraInfo = parent.extraInfo;
|
entry.extraInfo = parent.extraInfo;
|
||||||
if (!entry.extraInfo.isEmpty())
|
if (!entry.extraInfo.isEmpty())
|
||||||
entry.extraInfo.append("::");
|
entry.extraInfo.append("::");
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include <coreplugin/locator/ilocatorfilter.h>
|
#include <coreplugin/locator/ilocatorfilter.h>
|
||||||
|
|
||||||
|
namespace LanguageClient { class WorkspaceLocatorFilter; }
|
||||||
|
|
||||||
namespace ClangCodeModel {
|
namespace ClangCodeModel {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -12,7 +14,8 @@ class ClangGlobalSymbolFilter : public Core::ILocatorFilter
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ClangGlobalSymbolFilter();
|
ClangGlobalSymbolFilter();
|
||||||
ClangGlobalSymbolFilter(Core::ILocatorFilter *cppFilter, Core::ILocatorFilter *lspFilter);
|
ClangGlobalSymbolFilter(Core::ILocatorFilter *cppFilter,
|
||||||
|
LanguageClient::WorkspaceLocatorFilter *lspFilter);
|
||||||
~ClangGlobalSymbolFilter() override;
|
~ClangGlobalSymbolFilter() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -23,7 +26,7 @@ private:
|
|||||||
int *selectionStart, int *selectionLength) const override;
|
int *selectionStart, int *selectionLength) const override;
|
||||||
|
|
||||||
Core::ILocatorFilter * const m_cppFilter;
|
Core::ILocatorFilter * const m_cppFilter;
|
||||||
Core::ILocatorFilter * const m_lspFilter;
|
LanguageClient::WorkspaceLocatorFilter * const m_lspFilter;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ClangClassesFilter : public ClangGlobalSymbolFilter
|
class ClangClassesFilter : public ClangGlobalSymbolFilter
|
||||||
|
|||||||
Reference in New Issue
Block a user