forked from qt-creator/qt-creator
ClangCodeModel: Add clangd-based document locator filter
Change-Id: I2811be80e740cacf57eccd19e47560af746ad0c1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -36,7 +36,7 @@ add_qtc_plugin(ClangCodeModel
|
|||||||
clangfixitoperationsextractor.cpp clangfixitoperationsextractor.h
|
clangfixitoperationsextractor.cpp clangfixitoperationsextractor.h
|
||||||
clangfollowsymbol.cpp clangfollowsymbol.h
|
clangfollowsymbol.cpp clangfollowsymbol.h
|
||||||
clangfunctionhintmodel.cpp clangfunctionhintmodel.h
|
clangfunctionhintmodel.cpp clangfunctionhintmodel.h
|
||||||
clanggloballocatorfilters.cpp clanggloballocatorfilters.h
|
clangdlocatorfilters.cpp clangdlocatorfilters.h
|
||||||
clanghighlightingresultreporter.cpp clanghighlightingresultreporter.h
|
clanghighlightingresultreporter.cpp clanghighlightingresultreporter.h
|
||||||
clanghoverhandler.cpp clanghoverhandler.h
|
clanghoverhandler.cpp clanghoverhandler.h
|
||||||
clangisdiagnosticrelatedtolocation.h
|
clangisdiagnosticrelatedtolocation.h
|
||||||
|
@@ -43,7 +43,7 @@ SOURCES += \
|
|||||||
clangoverviewmodel.cpp \
|
clangoverviewmodel.cpp \
|
||||||
clangdclient.cpp \
|
clangdclient.cpp \
|
||||||
clangdquickfixfactory.cpp \
|
clangdquickfixfactory.cpp \
|
||||||
clanggloballocatorfilters.cpp \
|
clangdlocatorfilters.cpp \
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
clangactivationsequencecontextprocessor.h \
|
clangactivationsequencecontextprocessor.h \
|
||||||
@@ -85,7 +85,7 @@ HEADERS += \
|
|||||||
clangoverviewmodel.h \
|
clangoverviewmodel.h \
|
||||||
clangdclient.h \
|
clangdclient.h \
|
||||||
clangdquickfixfactory.h \
|
clangdquickfixfactory.h \
|
||||||
clanggloballocatorfilters.h \
|
clangdlocatorfilters.h \
|
||||||
|
|
||||||
FORMS += clangprojectsettingswidget.ui
|
FORMS += clangprojectsettingswidget.ui
|
||||||
|
|
||||||
|
@@ -64,6 +64,8 @@ QtcPlugin {
|
|||||||
"clangdiagnosticmanager.h",
|
"clangdiagnosticmanager.h",
|
||||||
"clangdiagnostictooltipwidget.cpp",
|
"clangdiagnostictooltipwidget.cpp",
|
||||||
"clangdiagnostictooltipwidget.h",
|
"clangdiagnostictooltipwidget.h",
|
||||||
|
"clangdlocatorfilters.cpp",
|
||||||
|
"clangdlocatorfilters.h",
|
||||||
"clangdquickfixfactory.cpp",
|
"clangdquickfixfactory.cpp",
|
||||||
"clangdquickfixfactory.h",
|
"clangdquickfixfactory.h",
|
||||||
"clangeditordocumentparser.cpp",
|
"clangeditordocumentparser.cpp",
|
||||||
@@ -78,8 +80,6 @@ QtcPlugin {
|
|||||||
"clangfollowsymbol.h",
|
"clangfollowsymbol.h",
|
||||||
"clangfunctionhintmodel.cpp",
|
"clangfunctionhintmodel.cpp",
|
||||||
"clangfunctionhintmodel.h",
|
"clangfunctionhintmodel.h",
|
||||||
"clanggloballocatorfilters.cpp",
|
|
||||||
"clanggloballocatorfilters.h",
|
|
||||||
"clanghighlightingresultreporter.cpp",
|
"clanghighlightingresultreporter.cpp",
|
||||||
"clanghighlightingresultreporter.h",
|
"clanghighlightingresultreporter.h",
|
||||||
"clanghoverhandler.cpp",
|
"clanghoverhandler.cpp",
|
||||||
|
@@ -978,31 +978,7 @@ ClangdClient::ClangdClient(Project *project, const Utils::FilePath &jsonDbDir)
|
|||||||
};
|
};
|
||||||
const auto hideDiagsHandler = []{ ClangDiagnosticManager::clearTaskHubIssues(); };
|
const auto hideDiagsHandler = []{ ClangDiagnosticManager::clearTaskHubIssues(); };
|
||||||
setDiagnosticsHandlers(textMarkCreator, hideDiagsHandler);
|
setDiagnosticsHandlers(textMarkCreator, hideDiagsHandler);
|
||||||
|
setSymbolStringifier(displayNameFromDocumentSymbol);
|
||||||
static const auto symbolStringifier = [](SymbolKind kind, const QString &name,
|
|
||||||
const QString &detail) -> QString
|
|
||||||
{
|
|
||||||
switch (kind) {
|
|
||||||
case LanguageServerProtocol::SymbolKind::Constructor:
|
|
||||||
return name + detail;
|
|
||||||
case LanguageServerProtocol::SymbolKind::Method:
|
|
||||||
case LanguageServerProtocol::SymbolKind::Function: {
|
|
||||||
const int parenOffset = detail.indexOf(" (");
|
|
||||||
if (parenOffset == -1)
|
|
||||||
return name;
|
|
||||||
return name + detail.mid(parenOffset + 1) + " -> " + detail.mid(0, parenOffset);
|
|
||||||
}
|
|
||||||
case LanguageServerProtocol::SymbolKind::Variable:
|
|
||||||
case LanguageServerProtocol::SymbolKind::Field:
|
|
||||||
case LanguageServerProtocol::SymbolKind::Constant:
|
|
||||||
if (detail.isEmpty())
|
|
||||||
return name;
|
|
||||||
return name + " -> " + detail;
|
|
||||||
default:
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
setSymbolStringifier(symbolStringifier);
|
|
||||||
setSemanticTokensHandler([this](TextDocument *doc, const QList<ExpandedSemanticToken> &tokens) {
|
setSemanticTokensHandler([this](TextDocument *doc, const QList<ExpandedSemanticToken> &tokens) {
|
||||||
d->handleSemanticTokens(doc, tokens);
|
d->handleSemanticTokens(doc, tokens);
|
||||||
});
|
});
|
||||||
@@ -1236,6 +1212,30 @@ bool ClangdClient::testingEnabled() const
|
|||||||
return d->isTesting;
|
return d->isTesting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ClangdClient::displayNameFromDocumentSymbol(SymbolKind kind, const QString &name,
|
||||||
|
const QString &detail)
|
||||||
|
{
|
||||||
|
switch (kind) {
|
||||||
|
case SymbolKind::Constructor:
|
||||||
|
return name + detail;
|
||||||
|
case SymbolKind::Method:
|
||||||
|
case LanguageServerProtocol::SymbolKind::Function: {
|
||||||
|
const int parenOffset = detail.indexOf(" (");
|
||||||
|
if (parenOffset == -1)
|
||||||
|
return name;
|
||||||
|
return name + detail.mid(parenOffset + 1) + " -> " + detail.mid(0, parenOffset);
|
||||||
|
}
|
||||||
|
case SymbolKind::Variable:
|
||||||
|
case SymbolKind::Field:
|
||||||
|
case SymbolKind::Constant:
|
||||||
|
if (detail.isEmpty())
|
||||||
|
return name;
|
||||||
|
return name + " -> " + detail;
|
||||||
|
default:
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ClangdClient::Private::handleFindUsagesResult(quint64 key, const QList<Location> &locations)
|
void ClangdClient::Private::handleFindUsagesResult(quint64 key, const QList<Location> &locations)
|
||||||
{
|
{
|
||||||
const auto refData = runningFindUsages.find(key);
|
const auto refData = runningFindUsages.find(key);
|
||||||
|
@@ -79,6 +79,9 @@ public:
|
|||||||
void enableTesting();
|
void enableTesting();
|
||||||
bool testingEnabled() const;
|
bool testingEnabled() const;
|
||||||
|
|
||||||
|
static QString displayNameFromDocumentSymbol(LanguageServerProtocol::SymbolKind kind,
|
||||||
|
const QString &name, const QString &detail);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void indexingFinished();
|
void indexingFinished();
|
||||||
void foundReferences(const QList<Core::SearchResultItem> &items);
|
void foundReferences(const QList<Core::SearchResultItem> &items);
|
||||||
|
@@ -23,15 +23,17 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "clanggloballocatorfilters.h"
|
#include "clangdlocatorfilters.h"
|
||||||
|
|
||||||
#include "clangdclient.h"
|
#include "clangdclient.h"
|
||||||
#include "clangmodelmanagersupport.h"
|
#include "clangmodelmanagersupport.h"
|
||||||
|
#include "clangcurrentdocumentfilter.h"
|
||||||
|
|
||||||
#include <cppeditor/cppeditorconstants.h>
|
#include <cppeditor/cppeditorconstants.h>
|
||||||
#include <cppeditor/cpplocatorfilter.h>
|
#include <cppeditor/cpplocatorfilter.h>
|
||||||
#include <cppeditor/cppmodelmanager.h>
|
#include <cppeditor/cppmodelmanager.h>
|
||||||
#include <cppeditor/indexitem.h>
|
#include <cppeditor/indexitem.h>
|
||||||
|
#include <languageclient/languageclientutils.h>
|
||||||
#include <languageclient/locatorfilter.h>
|
#include <languageclient/locatorfilter.h>
|
||||||
#include <projectexplorer/session.h>
|
#include <projectexplorer/session.h>
|
||||||
#include <utils/link.h>
|
#include <utils/link.h>
|
||||||
@@ -39,6 +41,8 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
|
using namespace LanguageServerProtocol;
|
||||||
|
|
||||||
namespace ClangCodeModel {
|
namespace ClangCodeModel {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -222,5 +226,104 @@ ClangFunctionsFilter::ClangFunctionsFilter()
|
|||||||
setDefaultIncludedByDefault(false);
|
setDefaultIncludedByDefault(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CppCurrentDocumentFilter : public ClangCurrentDocumentFilter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CppCurrentDocumentFilter()
|
||||||
|
{
|
||||||
|
setId({});
|
||||||
|
setDisplayName({});
|
||||||
|
setDefaultShortcutString({});
|
||||||
|
setEnabled(false);
|
||||||
|
setHidden(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class LspCurrentDocumentFilter : public LanguageClient::DocumentLocatorFilter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LspCurrentDocumentFilter()
|
||||||
|
{
|
||||||
|
setId({});
|
||||||
|
setDisplayName({});
|
||||||
|
setDefaultShortcutString({});
|
||||||
|
setEnabled(false);
|
||||||
|
setHidden(true);
|
||||||
|
forceUse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Core::LocatorFilterEntry generateLocatorEntry(const DocumentSymbol &info,
|
||||||
|
const Core::LocatorFilterEntry &parent) override
|
||||||
|
{
|
||||||
|
Core::LocatorFilterEntry entry;
|
||||||
|
entry.filter = this;
|
||||||
|
entry.displayName = ClangdClient::displayNameFromDocumentSymbol(
|
||||||
|
static_cast<SymbolKind>(info.kind()), info.name(),
|
||||||
|
info.detail().value_or(QString()));
|
||||||
|
const Position &pos = info.range().start();
|
||||||
|
entry.internalData = QVariant::fromValue(Utils::LineColumn(pos.line(), pos.character()));
|
||||||
|
entry.extraInfo = parent.extraInfo;
|
||||||
|
if (!entry.extraInfo.isEmpty())
|
||||||
|
entry.extraInfo.append("::");
|
||||||
|
entry.extraInfo.append(parent.displayName);
|
||||||
|
|
||||||
|
// TODO: Can we extend clangd to send visibility information?
|
||||||
|
entry.displayIcon = LanguageClient::symbolIcon(info.kind());
|
||||||
|
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class ClangdCurrentDocumentFilter::Private
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CppCurrentDocumentFilter cppFilter;
|
||||||
|
LspCurrentDocumentFilter lspFilter;
|
||||||
|
Core::ILocatorFilter *activeFilter = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
ClangdCurrentDocumentFilter::ClangdCurrentDocumentFilter() : d(new Private)
|
||||||
|
{
|
||||||
|
setId(CppEditor::Constants::CURRENT_DOCUMENT_FILTER_ID);
|
||||||
|
setDisplayName(CppEditor::Constants::CURRENT_DOCUMENT_FILTER_DISPLAY_NAME);
|
||||||
|
setDefaultShortcutString(".");
|
||||||
|
setPriority(High);
|
||||||
|
setDefaultIncludedByDefault(false);
|
||||||
|
setEnabled(false);
|
||||||
|
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
|
||||||
|
this, [this](const Core::IEditor *editor) { setEnabled(editor); });
|
||||||
|
}
|
||||||
|
|
||||||
|
ClangdCurrentDocumentFilter::~ClangdCurrentDocumentFilter() { delete d; }
|
||||||
|
|
||||||
|
void ClangdCurrentDocumentFilter::prepareSearch(const QString &entry)
|
||||||
|
{
|
||||||
|
const auto doc = TextEditor::TextDocument::currentTextDocument();
|
||||||
|
QTC_ASSERT(doc, return);
|
||||||
|
if (const ClangdClient * const client = ClangModelManagerSupport::instance()
|
||||||
|
->clientForFile(doc->filePath()); client && client->reachable()) {
|
||||||
|
d->activeFilter = &d->lspFilter;
|
||||||
|
} else {
|
||||||
|
d->activeFilter = &d->cppFilter;
|
||||||
|
}
|
||||||
|
d->activeFilter->prepareSearch(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<Core::LocatorFilterEntry> ClangdCurrentDocumentFilter::matchesFor(
|
||||||
|
QFutureInterface<Core::LocatorFilterEntry> &future, const QString &entry)
|
||||||
|
{
|
||||||
|
QTC_ASSERT(d->activeFilter, return {});
|
||||||
|
return d->activeFilter->matchesFor(future, entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClangdCurrentDocumentFilter::accept(Core::LocatorFilterEntry selection, QString *newText,
|
||||||
|
int *selectionStart, int *selectionLength) const
|
||||||
|
{
|
||||||
|
QTC_ASSERT(d->activeFilter, return);
|
||||||
|
d->activeFilter->accept(selection, newText, selectionStart, selectionLength);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace ClangCodeModel
|
} // namespace ClangCodeModel
|
@@ -60,5 +60,22 @@ public:
|
|||||||
ClangFunctionsFilter();
|
ClangFunctionsFilter();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ClangdCurrentDocumentFilter : public Core::ILocatorFilter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ClangdCurrentDocumentFilter();
|
||||||
|
~ClangdCurrentDocumentFilter() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void prepareSearch(const QString &entry) override;
|
||||||
|
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
||||||
|
const QString &entry) override;
|
||||||
|
void accept(Core::LocatorFilterEntry selection, QString *newText,
|
||||||
|
int *selectionStart, int *selectionLength) const override;
|
||||||
|
|
||||||
|
class Private;
|
||||||
|
Private * const d;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace ClangCodeModel
|
} // namespace ClangCodeModel
|
@@ -26,12 +26,11 @@
|
|||||||
#include "clangmodelmanagersupport.h"
|
#include "clangmodelmanagersupport.h"
|
||||||
|
|
||||||
#include "clangconstants.h"
|
#include "clangconstants.h"
|
||||||
#include "clangcurrentdocumentfilter.h"
|
|
||||||
#include "clangdclient.h"
|
#include "clangdclient.h"
|
||||||
#include "clangdquickfixfactory.h"
|
#include "clangdquickfixfactory.h"
|
||||||
#include "clangeditordocumentprocessor.h"
|
#include "clangeditordocumentprocessor.h"
|
||||||
#include "clangfollowsymbol.h"
|
#include "clangfollowsymbol.h"
|
||||||
#include "clanggloballocatorfilters.h"
|
#include "clangdlocatorfilters.h"
|
||||||
#include "clanghoverhandler.h"
|
#include "clanghoverhandler.h"
|
||||||
#include "clangoverviewmodel.h"
|
#include "clangoverviewmodel.h"
|
||||||
#include "clangprojectsettings.h"
|
#include "clangprojectsettings.h"
|
||||||
@@ -113,8 +112,7 @@ ClangModelManagerSupport::ClangModelManagerSupport()
|
|||||||
m_instance = this;
|
m_instance = this;
|
||||||
|
|
||||||
watchForExternalChanges();
|
watchForExternalChanges();
|
||||||
CppEditor::CppModelManager::instance()->setCurrentDocumentFilter(
|
cppModelManager()->setCurrentDocumentFilter(std::make_unique<ClangdCurrentDocumentFilter>());
|
||||||
std::make_unique<ClangCurrentDocumentFilter>());
|
|
||||||
cppModelManager()->setLocatorFilter(std::make_unique<ClangGlobalSymbolFilter>());
|
cppModelManager()->setLocatorFilter(std::make_unique<ClangGlobalSymbolFilter>());
|
||||||
cppModelManager()->setClassesFilter(std::make_unique<ClangClassesFilter>());
|
cppModelManager()->setClassesFilter(std::make_unique<ClangClassesFilter>());
|
||||||
cppModelManager()->setFunctionsFilter(std::make_unique<ClangFunctionsFilter>());
|
cppModelManager()->setFunctionsFilter(std::make_unique<ClangFunctionsFilter>());
|
||||||
|
@@ -61,6 +61,6 @@ updateCodeActionRefactoringMarker(Client *client,
|
|||||||
const LanguageServerProtocol::CodeAction &action,
|
const LanguageServerProtocol::CodeAction &action,
|
||||||
const LanguageServerProtocol::DocumentUri &uri);
|
const LanguageServerProtocol::DocumentUri &uri);
|
||||||
void updateEditorToolBar(Core::IEditor *editor);
|
void updateEditorToolBar(Core::IEditor *editor);
|
||||||
const QIcon symbolIcon(int type);
|
const QIcon LANGUAGECLIENT_EXPORT symbolIcon(int type);
|
||||||
|
|
||||||
} // namespace LanguageClient
|
} // namespace LanguageClient
|
||||||
|
@@ -63,8 +63,8 @@ void DocumentLocatorFilter::updateCurrentClient()
|
|||||||
|
|
||||||
TextEditor::TextDocument *document = TextEditor::TextDocument::currentTextDocument();
|
TextEditor::TextDocument *document = TextEditor::TextDocument::currentTextDocument();
|
||||||
if (Client *client = LanguageClientManager::clientForDocument(document);
|
if (Client *client = LanguageClientManager::clientForDocument(document);
|
||||||
client && client->locatorsEnabled()) {
|
client && (client->locatorsEnabled() || m_forced)) {
|
||||||
setEnabled(true);
|
setEnabled(!m_forced);
|
||||||
if (m_symbolCache != client->documentSymbolCache()) {
|
if (m_symbolCache != client->documentSymbolCache()) {
|
||||||
disconnect(m_updateSymbolsConnection);
|
disconnect(m_updateSymbolsConnection);
|
||||||
m_symbolCache = client->documentSymbolCache();
|
m_symbolCache = client->documentSymbolCache();
|
||||||
@@ -98,7 +98,7 @@ void DocumentLocatorFilter::resetSymbols()
|
|||||||
m_currentSymbols.reset();
|
m_currentSymbols.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::LocatorFilterEntry generateLocatorEntry(const SymbolInformation &info,
|
static Core::LocatorFilterEntry generateLocatorEntry(const SymbolInformation &info,
|
||||||
Core::ILocatorFilter *filter)
|
Core::ILocatorFilter *filter)
|
||||||
{
|
{
|
||||||
Core::LocatorFilterEntry entry;
|
Core::LocatorFilterEntry entry;
|
||||||
@@ -109,22 +109,31 @@ Core::LocatorFilterEntry generateLocatorEntry(const SymbolInformation &info,
|
|||||||
entry.displayIcon = symbolIcon(info.kind());
|
entry.displayIcon = symbolIcon(info.kind());
|
||||||
entry.internalData = QVariant::fromValue(info.location().toLink());
|
entry.internalData = QVariant::fromValue(info.location().toLink());
|
||||||
return entry;
|
return entry;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Core::LocatorFilterEntry> generateLocatorEntries(const SymbolInformation &info,
|
Core::LocatorFilterEntry DocumentLocatorFilter::generateLocatorEntry(const SymbolInformation &info)
|
||||||
Core::ILocatorFilter *filter,
|
|
||||||
const QRegularExpression ®exp)
|
|
||||||
{
|
{
|
||||||
if (!regexp.match(info.name()).hasMatch())
|
return LanguageClient::generateLocatorEntry(info, this);
|
||||||
return { generateLocatorEntry(info, filter) };
|
}
|
||||||
|
|
||||||
|
QList<Core::LocatorFilterEntry> DocumentLocatorFilter::generateLocatorEntries(
|
||||||
|
const SymbolInformation &info, const QRegularExpression ®exp,
|
||||||
|
const Core::LocatorFilterEntry &parent)
|
||||||
|
{
|
||||||
|
Q_UNUSED(parent)
|
||||||
|
if (regexp.match(info.name()).hasMatch())
|
||||||
|
return {generateLocatorEntry(info)};
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::LocatorFilterEntry generateLocatorEntry(const DocumentSymbol &info,
|
Core::LocatorFilterEntry DocumentLocatorFilter::generateLocatorEntry(
|
||||||
Core::ILocatorFilter *filter)
|
const DocumentSymbol &info,
|
||||||
|
const Core::LocatorFilterEntry &parent)
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(parent)
|
||||||
Core::LocatorFilterEntry entry;
|
Core::LocatorFilterEntry entry;
|
||||||
entry.filter = filter;
|
entry.filter = this;
|
||||||
entry.displayName = info.name();
|
entry.displayName = info.name();
|
||||||
if (Utils::optional<QString> detail = info.detail())
|
if (Utils::optional<QString> detail = info.detail())
|
||||||
entry.extraInfo = detail.value_or(QString());
|
entry.extraInfo = detail.value_or(QString());
|
||||||
@@ -134,16 +143,20 @@ Core::LocatorFilterEntry generateLocatorEntry(const DocumentSymbol &info,
|
|||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Core::LocatorFilterEntry> generateLocatorEntries(const DocumentSymbol &info,
|
QList<Core::LocatorFilterEntry> DocumentLocatorFilter::generateLocatorEntries(
|
||||||
Core::ILocatorFilter *filter,
|
const DocumentSymbol &info, const QRegularExpression ®exp,
|
||||||
const QRegularExpression ®exp)
|
const Core::LocatorFilterEntry &parent)
|
||||||
{
|
{
|
||||||
QList<Core::LocatorFilterEntry> entries;
|
QList<Core::LocatorFilterEntry> entries;
|
||||||
if (regexp.match(info.name()).hasMatch())
|
|
||||||
entries << generateLocatorEntry(info, filter);
|
|
||||||
const QList<DocumentSymbol> children = info.children().value_or(QList<DocumentSymbol>());
|
const QList<DocumentSymbol> children = info.children().value_or(QList<DocumentSymbol>());
|
||||||
|
const bool hasMatch = regexp.match(info.name()).hasMatch();
|
||||||
|
Core::LocatorFilterEntry entry;
|
||||||
|
if (hasMatch || !children.isEmpty())
|
||||||
|
entry = generateLocatorEntry(info, parent);
|
||||||
|
if (hasMatch)
|
||||||
|
entries << entry;
|
||||||
for (const DocumentSymbol &child : children)
|
for (const DocumentSymbol &child : children)
|
||||||
entries << generateLocatorEntries(child, filter, regexp);
|
entries << generateLocatorEntries(child, regexp, entry);
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,7 +174,7 @@ QList<Core::LocatorFilterEntry> DocumentLocatorFilter::generateEntries(const QLi
|
|||||||
return entries;
|
return entries;
|
||||||
|
|
||||||
for (const T &item : list)
|
for (const T &item : list)
|
||||||
entries << generateLocatorEntries(item, this, regexp);
|
entries << generateLocatorEntries(item, regexp, {});
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
#include "languageclient_global.h"
|
||||||
|
|
||||||
#include <coreplugin/locator/ilocatorfilter.h>
|
#include <coreplugin/locator/ilocatorfilter.h>
|
||||||
#include <languageserverprotocol/lsptypes.h>
|
#include <languageserverprotocol/lsptypes.h>
|
||||||
@@ -38,7 +39,7 @@ namespace Core { class IEditor; }
|
|||||||
|
|
||||||
namespace LanguageClient {
|
namespace LanguageClient {
|
||||||
|
|
||||||
class DocumentLocatorFilter : public Core::ILocatorFilter
|
class LANGUAGECLIENT_EXPORT DocumentLocatorFilter : public Core::ILocatorFilter
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
@@ -57,6 +58,8 @@ signals:
|
|||||||
void symbolsUpToDate(QPrivateSignal);
|
void symbolsUpToDate(QPrivateSignal);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void forceUse() { m_forced = true; }
|
||||||
|
|
||||||
QPointer<DocumentSymbolCache> m_symbolCache;
|
QPointer<DocumentSymbolCache> m_symbolCache;
|
||||||
LanguageServerProtocol::DocumentUri m_currentUri;
|
LanguageServerProtocol::DocumentUri m_currentUri;
|
||||||
|
|
||||||
@@ -67,11 +70,25 @@ private:
|
|||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
QList<Core::LocatorFilterEntry> generateEntries(const QList<T> &list, const QString &filter);
|
QList<Core::LocatorFilterEntry> generateEntries(const QList<T> &list, const QString &filter);
|
||||||
|
QList<Core::LocatorFilterEntry> generateLocatorEntries(
|
||||||
|
const LanguageServerProtocol::SymbolInformation &info,
|
||||||
|
const QRegularExpression ®exp,
|
||||||
|
const Core::LocatorFilterEntry &parent);
|
||||||
|
QList<Core::LocatorFilterEntry> generateLocatorEntries(
|
||||||
|
const LanguageServerProtocol::DocumentSymbol &info,
|
||||||
|
const QRegularExpression ®exp,
|
||||||
|
const Core::LocatorFilterEntry &parent);
|
||||||
|
virtual Core::LocatorFilterEntry generateLocatorEntry(
|
||||||
|
const LanguageServerProtocol::DocumentSymbol &info,
|
||||||
|
const Core::LocatorFilterEntry &parent);
|
||||||
|
virtual Core::LocatorFilterEntry generateLocatorEntry(
|
||||||
|
const LanguageServerProtocol::SymbolInformation &info);
|
||||||
|
|
||||||
QMutex m_mutex;
|
QMutex m_mutex;
|
||||||
QMetaObject::Connection m_updateSymbolsConnection;
|
QMetaObject::Connection m_updateSymbolsConnection;
|
||||||
QMetaObject::Connection m_resetSymbolsConnection;
|
QMetaObject::Connection m_resetSymbolsConnection;
|
||||||
Utils::optional<LanguageServerProtocol::DocumentSymbolsResult> m_currentSymbols;
|
Utils::optional<LanguageServerProtocol::DocumentSymbolsResult> m_currentSymbols;
|
||||||
|
bool m_forced = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LANGUAGECLIENT_EXPORT WorkspaceLocatorFilter : public Core::ILocatorFilter
|
class LANGUAGECLIENT_EXPORT WorkspaceLocatorFilter : public Core::ILocatorFilter
|
||||||
|
Reference in New Issue
Block a user