forked from qt-creator/qt-creator
DocumentLocatorFilter: Make internals reusable in LocatorMatcher
Prepare for LocatorMatcher implementation. Change-Id: I3d78045a06c8ebefacb033f0eabb5f7a2457ab06 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -218,25 +218,23 @@ private:
|
|||||||
};
|
};
|
||||||
QList<Entry> docEntries;
|
QList<Entry> docEntries;
|
||||||
|
|
||||||
const auto docSymbolGenerator = [&](const DocumentSymbol &info,
|
const auto docSymbolModifier = [&docEntries](LocatorFilterEntry &entry,
|
||||||
|
const DocumentSymbol &info,
|
||||||
const LocatorFilterEntry &parent) {
|
const LocatorFilterEntry &parent) {
|
||||||
LocatorFilterEntry entry;
|
|
||||||
entry.displayName = ClangdClient::displayNameFromDocumentSymbol(
|
entry.displayName = ClangdClient::displayNameFromDocumentSymbol(
|
||||||
static_cast<SymbolKind>(info.kind()), info.name(),
|
static_cast<SymbolKind>(info.kind()), info.name(),
|
||||||
info.detail().value_or(QString()));
|
info.detail().value_or(QString()));
|
||||||
entry.linkForEditor = linkForDocSymbol(info);
|
|
||||||
entry.extraInfo = parent.extraInfo;
|
entry.extraInfo = parent.extraInfo;
|
||||||
if (!entry.extraInfo.isEmpty())
|
if (!entry.extraInfo.isEmpty())
|
||||||
entry.extraInfo.append("::");
|
entry.extraInfo.append("::");
|
||||||
entry.extraInfo.append(parent.displayName);
|
entry.extraInfo.append(parent.displayName);
|
||||||
|
|
||||||
// TODO: Can we extend clangd to send visibility information?
|
// TODO: Can we extend clangd to send visibility information?
|
||||||
entry.displayIcon = LanguageClient::symbolIcon(info.kind());
|
|
||||||
docEntries.append({entry, info});
|
docEntries.append({entry, info});
|
||||||
return entry;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QList<LocatorFilterEntry> allMatches = matchesForImpl(future, entry, docSymbolGenerator);
|
const QList<LocatorFilterEntry> allMatches = matchesForImpl(future, entry,
|
||||||
|
docSymbolModifier);
|
||||||
if (docEntries.isEmpty())
|
if (docEntries.isEmpty())
|
||||||
return allMatches; // SymbolInformation case
|
return allMatches; // SymbolInformation case
|
||||||
|
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ void DocumentLocatorFilter::resetSymbols()
|
|||||||
m_currentSymbols.reset();
|
m_currentSymbols.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
static LocatorFilterEntry generateLocatorEntry(const SymbolInformation &info,
|
static LocatorFilterEntry entryForSymbolInfo(const SymbolInformation &info,
|
||||||
DocumentUri::PathMapper pathMapper)
|
DocumentUri::PathMapper pathMapper)
|
||||||
{
|
{
|
||||||
LocatorFilterEntry entry;
|
LocatorFilterEntry entry;
|
||||||
@@ -202,30 +202,37 @@ static LocatorFilterEntry generateLocatorEntry(const SymbolInformation &info,
|
|||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<LocatorFilterEntry> DocumentLocatorFilter::entriesForSymbolsInfo(
|
LocatorFilterEntries entriesForSymbolsInfo(const QList<SymbolInformation> &infoList,
|
||||||
const QList<SymbolInformation> &infoList, const QRegularExpression ®exp)
|
const QRegularExpression ®exp, const DocumentUri::PathMapper &pathMapper)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_pathMapper, return {});
|
QTC_ASSERT(pathMapper, return {});
|
||||||
QList<LocatorFilterEntry> entries;
|
LocatorFilterEntries entries;
|
||||||
for (const SymbolInformation &info : infoList) {
|
for (const SymbolInformation &info : infoList) {
|
||||||
if (regexp.match(info.name()).hasMatch())
|
if (regexp.match(info.name()).hasMatch())
|
||||||
entries << LanguageClient::generateLocatorEntry(info, m_pathMapper);
|
entries << LanguageClient::entryForSymbolInfo(info, pathMapper);
|
||||||
}
|
}
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<LocatorFilterEntry> DocumentLocatorFilter::entriesForDocSymbols(
|
LocatorFilterEntries entriesForDocSymbols(const QList<DocumentSymbol> &infoList,
|
||||||
const QList<DocumentSymbol> &infoList, const QRegularExpression ®exp,
|
const QRegularExpression ®exp, const FilePath &filePath,
|
||||||
const DocSymbolGenerator &docSymbolGenerator, const LocatorFilterEntry &parent)
|
const DocSymbolModifier &docSymbolModifier, const LocatorFilterEntry &parent = {})
|
||||||
{
|
{
|
||||||
QList<LocatorFilterEntry> entries;
|
LocatorFilterEntries entries;
|
||||||
for (const DocumentSymbol &info : infoList) {
|
for (const DocumentSymbol &info : infoList) {
|
||||||
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();
|
const bool hasMatch = regexp.match(info.name()).hasMatch();
|
||||||
const LocatorFilterEntry entry = hasMatch ? docSymbolGenerator(info, parent) : parent;
|
LocatorFilterEntry entry;
|
||||||
if (hasMatch)
|
if (hasMatch) {
|
||||||
|
entry.displayIcon = LanguageClient::symbolIcon(info.kind());
|
||||||
|
const Position &pos = info.range().start();
|
||||||
|
entry.linkForEditor = {filePath, pos.line() + 1, pos.character()};
|
||||||
|
docSymbolModifier(entry, info, parent);
|
||||||
entries << entry;
|
entries << entry;
|
||||||
entries << entriesForDocSymbols(children, regexp, docSymbolGenerator, entry);
|
} else {
|
||||||
|
entry = parent;
|
||||||
|
}
|
||||||
|
entries << entriesForDocSymbols(children, regexp, filePath, docSymbolModifier, entry);
|
||||||
}
|
}
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
@@ -243,29 +250,19 @@ void DocumentLocatorFilter::prepareSearch(const QString &/*entry*/)
|
|||||||
QList<LocatorFilterEntry> DocumentLocatorFilter::matchesFor(
|
QList<LocatorFilterEntry> DocumentLocatorFilter::matchesFor(
|
||||||
QFutureInterface<LocatorFilterEntry> &future, const QString &entry)
|
QFutureInterface<LocatorFilterEntry> &future, const QString &entry)
|
||||||
{
|
{
|
||||||
const auto docSymbolGenerator = [this](const DocumentSymbol &info,
|
const auto docSymbolModifier = [](LocatorFilterEntry &entry, const DocumentSymbol &info,
|
||||||
const LocatorFilterEntry &parent) {
|
const LocatorFilterEntry &parent) {
|
||||||
Q_UNUSED(parent)
|
Q_UNUSED(parent)
|
||||||
LocatorFilterEntry entry;
|
|
||||||
entry.displayName = info.name();
|
entry.displayName = info.name();
|
||||||
if (std::optional<QString> detail = info.detail())
|
if (std::optional<QString> detail = info.detail())
|
||||||
entry.extraInfo = detail.value_or(QString());
|
entry.extraInfo = *detail;
|
||||||
entry.displayIcon = symbolIcon(info.kind());
|
|
||||||
entry.linkForEditor = linkForDocSymbol(info);
|
|
||||||
return entry;
|
|
||||||
};
|
};
|
||||||
return matchesForImpl(future, entry, docSymbolGenerator);
|
return matchesForImpl(future, entry, docSymbolModifier);
|
||||||
}
|
|
||||||
|
|
||||||
Link DocumentLocatorFilter::linkForDocSymbol(const DocumentSymbol &info) const
|
|
||||||
{
|
|
||||||
const Position &pos = info.range().start();
|
|
||||||
return {m_currentFilePath, pos.line() + 1, pos.character()};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<LocatorFilterEntry> DocumentLocatorFilter::matchesForImpl(
|
QList<LocatorFilterEntry> DocumentLocatorFilter::matchesForImpl(
|
||||||
QFutureInterface<LocatorFilterEntry> &future, const QString &entry,
|
QFutureInterface<LocatorFilterEntry> &future, const QString &entry,
|
||||||
const DocSymbolGenerator &docSymbolGenerator)
|
const DocSymbolModifier &docSymbolModifier)
|
||||||
{
|
{
|
||||||
const FuzzyMatcher::CaseSensitivity caseSensitivity
|
const FuzzyMatcher::CaseSensitivity caseSensitivity
|
||||||
= ILocatorFilter::caseSensitivity(entry) == Qt::CaseSensitive
|
= ILocatorFilter::caseSensitivity(entry) == Qt::CaseSensitive
|
||||||
@@ -293,9 +290,9 @@ QList<LocatorFilterEntry> DocumentLocatorFilter::matchesForImpl(
|
|||||||
QTC_ASSERT(m_currentSymbols.has_value(), return {});
|
QTC_ASSERT(m_currentSymbols.has_value(), return {});
|
||||||
|
|
||||||
if (auto list = std::get_if<QList<DocumentSymbol>>(&*m_currentSymbols))
|
if (auto list = std::get_if<QList<DocumentSymbol>>(&*m_currentSymbols))
|
||||||
return entriesForDocSymbols(*list, regExp, docSymbolGenerator);
|
return entriesForDocSymbols(*list, regExp, m_currentFilePath, docSymbolModifier);
|
||||||
else if (auto list = std::get_if<QList<SymbolInformation>>(&*m_currentSymbols))
|
else if (auto list = std::get_if<QList<SymbolInformation>>(&*m_currentSymbols))
|
||||||
return entriesForSymbolsInfo(*list, regExp);
|
return entriesForSymbolsInfo(*list, regExp, m_pathMapper);
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@@ -381,7 +378,7 @@ QList<LocatorFilterEntry> WorkspaceLocatorFilter::matchesFor(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
auto generateEntry = [](const SymbolInfoWithPathMapper &info) {
|
auto generateEntry = [](const SymbolInfoWithPathMapper &info) {
|
||||||
return generateLocatorEntry(info.symbol, info.mapper);
|
return entryForSymbolInfo(info.symbol, info.mapper);
|
||||||
};
|
};
|
||||||
return Utils::transform(m_results, generateEntry).toList();
|
return Utils::transform(m_results, generateEntry).toList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ namespace Core { class IEditor; }
|
|||||||
|
|
||||||
namespace LanguageClient {
|
namespace LanguageClient {
|
||||||
|
|
||||||
|
using DocSymbolModifier = std::function<void(Core::LocatorFilterEntry &,
|
||||||
|
const LanguageServerProtocol::DocumentSymbol &, const Core::LocatorFilterEntry &)>;
|
||||||
|
|
||||||
Core::LocatorMatcherTasks LANGUAGECLIENT_EXPORT workspaceMatchers(const QList<Client *> &clients,
|
Core::LocatorMatcherTasks LANGUAGECLIENT_EXPORT workspaceMatchers(const QList<Client *> &clients,
|
||||||
Core::MatcherType type,
|
Core::MatcherType type,
|
||||||
int maxResultCount = 0);
|
int maxResultCount = 0);
|
||||||
@@ -42,13 +45,9 @@ protected:
|
|||||||
|
|
||||||
Utils::FilePath m_currentFilePath;
|
Utils::FilePath m_currentFilePath;
|
||||||
|
|
||||||
using DocSymbolGenerator = std::function<Core::LocatorFilterEntry(
|
|
||||||
const LanguageServerProtocol::DocumentSymbol &, const Core::LocatorFilterEntry &)>;
|
|
||||||
|
|
||||||
Utils::Link linkForDocSymbol(const LanguageServerProtocol::DocumentSymbol &info) const;
|
|
||||||
QList<Core::LocatorFilterEntry> matchesForImpl(
|
QList<Core::LocatorFilterEntry> matchesForImpl(
|
||||||
QFutureInterface<Core::LocatorFilterEntry> &future, const QString &entry,
|
QFutureInterface<Core::LocatorFilterEntry> &future, const QString &entry,
|
||||||
const DocSymbolGenerator &docSymbolGenerator);
|
const DocSymbolModifier &docSymbolModifier);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateCurrentClient();
|
void updateCurrentClient();
|
||||||
@@ -56,14 +55,6 @@ private:
|
|||||||
const LanguageServerProtocol::DocumentSymbolsResult &symbols);
|
const LanguageServerProtocol::DocumentSymbolsResult &symbols);
|
||||||
void resetSymbols();
|
void resetSymbols();
|
||||||
|
|
||||||
QList<Core::LocatorFilterEntry> entriesForSymbolsInfo(
|
|
||||||
const QList<LanguageServerProtocol::SymbolInformation> &infoList,
|
|
||||||
const QRegularExpression ®exp);
|
|
||||||
QList<Core::LocatorFilterEntry> entriesForDocSymbols(
|
|
||||||
const QList<LanguageServerProtocol::DocumentSymbol> &infoList,
|
|
||||||
const QRegularExpression ®exp, const DocSymbolGenerator &docSymbolGenerator,
|
|
||||||
const Core::LocatorFilterEntry &parent = {});
|
|
||||||
|
|
||||||
QMutex m_mutex;
|
QMutex m_mutex;
|
||||||
QMetaObject::Connection m_updateSymbolsConnection;
|
QMetaObject::Connection m_updateSymbolsConnection;
|
||||||
QMetaObject::Connection m_resetSymbolsConnection;
|
QMetaObject::Connection m_resetSymbolsConnection;
|
||||||
|
|||||||
Reference in New Issue
Block a user