LocatorFilter classes: Use Core namespace

Change-Id: I4fd1b1ed6aa9d844ed49123e80bfb066b9fa7af2
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2023-02-22 19:21:28 +01:00
parent a4fa08f137
commit b364e4a9cd
8 changed files with 259 additions and 268 deletions

View File

@@ -21,6 +21,7 @@
#include <set> #include <set>
#include <tuple> #include <tuple>
using namespace Core;
using namespace LanguageClient; using namespace LanguageClient;
using namespace LanguageServerProtocol; using namespace LanguageServerProtocol;
using namespace Utils; using namespace Utils;
@@ -148,11 +149,11 @@ void ClangGlobalSymbolFilter::prepareSearch(const QString &entry)
m_lspFilter->prepareSearch(entry, clients); m_lspFilter->prepareSearch(entry, clients);
} }
QList<Core::LocatorFilterEntry> ClangGlobalSymbolFilter::matchesFor( QList<LocatorFilterEntry> ClangGlobalSymbolFilter::matchesFor(
QFutureInterface<Core::LocatorFilterEntry> &future, const QString &entry) QFutureInterface<LocatorFilterEntry> &future, const QString &entry)
{ {
QList<Core::LocatorFilterEntry> matches = m_cppFilter->matchesFor(future, entry); QList<LocatorFilterEntry> matches = m_cppFilter->matchesFor(future, entry);
const QList<Core::LocatorFilterEntry> lspMatches = m_lspFilter->matchesFor(future, entry); const QList<LocatorFilterEntry> lspMatches = m_lspFilter->matchesFor(future, entry);
if (!lspMatches.isEmpty()) { if (!lspMatches.isEmpty()) {
std::set<std::tuple<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)) {
@@ -174,7 +175,7 @@ QList<Core::LocatorFilterEntry> ClangGlobalSymbolFilter::matchesFor(
return matches; return matches;
} }
void ClangGlobalSymbolFilter::accept(const Core::LocatorFilterEntry &selection, QString *newText, void ClangGlobalSymbolFilter::accept(const LocatorFilterEntry &selection, QString *newText,
int *selectionStart, int *selectionLength) const int *selectionStart, int *selectionLength) const
{ {
if (qvariant_cast<CppEditor::IndexItem::Ptr>(selection.internalData)) if (qvariant_cast<CppEditor::IndexItem::Ptr>(selection.internalData))
@@ -221,10 +222,10 @@ private:
m_content = TextEditor::TextDocument::currentTextDocument()->plainText(); m_content = TextEditor::TextDocument::currentTextDocument()->plainText();
} }
Core::LocatorFilterEntry generateLocatorEntry(const DocumentSymbol &info, LocatorFilterEntry generateLocatorEntry(const DocumentSymbol &info,
const Core::LocatorFilterEntry &parent) override const LocatorFilterEntry &parent) override
{ {
Core::LocatorFilterEntry entry; LocatorFilterEntry entry;
entry.filter = this; entry.filter = this;
entry.displayName = ClangdClient::displayNameFromDocumentSymbol( entry.displayName = ClangdClient::displayNameFromDocumentSymbol(
static_cast<SymbolKind>(info.kind()), info.name(), static_cast<SymbolKind>(info.kind()), info.name(),
@@ -242,22 +243,22 @@ private:
} }
// Filter out declarations for which a definition is also present. // Filter out declarations for which a definition is also present.
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future, QList<LocatorFilterEntry> matchesFor(QFutureInterface<LocatorFilterEntry> &future,
const QString &entry) override const QString &entry) override
{ {
QList<Core::LocatorFilterEntry> allMatches QList<LocatorFilterEntry> allMatches
= DocumentLocatorFilter::matchesFor(future, entry); = DocumentLocatorFilter::matchesFor(future, entry);
QHash<QString, QList<Core::LocatorFilterEntry>> possibleDuplicates; QHash<QString, QList<LocatorFilterEntry>> possibleDuplicates;
for (const Core::LocatorFilterEntry &e : std::as_const(allMatches)) for (const LocatorFilterEntry &e : std::as_const(allMatches))
possibleDuplicates[e.displayName + e.extraInfo] << e; possibleDuplicates[e.displayName + e.extraInfo] << e;
const QTextDocument doc(m_content); const QTextDocument doc(m_content);
for (auto it = possibleDuplicates.cbegin(); it != possibleDuplicates.cend(); ++it) { for (auto it = possibleDuplicates.cbegin(); it != possibleDuplicates.cend(); ++it) {
const QList<Core::LocatorFilterEntry> &duplicates = it.value(); const QList<LocatorFilterEntry> &duplicates = it.value();
if (duplicates.size() == 1) if (duplicates.size() == 1)
continue; continue;
QList<Core::LocatorFilterEntry> declarations; QList<LocatorFilterEntry> declarations;
QList<Core::LocatorFilterEntry> definitions; QList<LocatorFilterEntry> definitions;
for (const Core::LocatorFilterEntry &candidate : duplicates) { for (const LocatorFilterEntry &candidate : duplicates) {
const auto symbol = qvariant_cast<DocumentSymbol>(candidate.internalData); const auto symbol = qvariant_cast<DocumentSymbol>(candidate.internalData);
const SymbolKind kind = static_cast<SymbolKind>(symbol.kind()); const SymbolKind kind = static_cast<SymbolKind>(symbol.kind());
if (kind != SymbolKind::Class && kind != SymbolKind::Function) if (kind != SymbolKind::Class && kind != SymbolKind::Function)
@@ -283,15 +284,15 @@ private:
} }
if (definitions.size() == 1 if (definitions.size() == 1
&& declarations.size() + definitions.size() == duplicates.size()) { && declarations.size() + definitions.size() == duplicates.size()) {
for (const Core::LocatorFilterEntry &decl : std::as_const(declarations)) for (const LocatorFilterEntry &decl : std::as_const(declarations))
Utils::erase(allMatches, [&decl](const Core::LocatorFilterEntry &e) { Utils::erase(allMatches, [&decl](const LocatorFilterEntry &e) {
return e.internalData == decl.internalData; return e.internalData == decl.internalData;
}); });
} }
} }
// The base implementation expects the position in the internal data. // The base implementation expects the position in the internal data.
for (Core::LocatorFilterEntry &e : allMatches) { for (LocatorFilterEntry &e : allMatches) {
const Position pos = qvariant_cast<DocumentSymbol>(e.internalData).range().start(); const Position pos = qvariant_cast<DocumentSymbol>(e.internalData).range().start();
e.internalData = QVariant::fromValue(Utils::LineColumn(pos.line(), pos.character())); e.internalData = QVariant::fromValue(Utils::LineColumn(pos.line(), pos.character()));
} }
@@ -307,10 +308,10 @@ class ClangdCurrentDocumentFilter::Private
public: public:
~Private() { delete cppFilter; } ~Private() { delete cppFilter; }
Core::ILocatorFilter * const cppFilter ILocatorFilter * const cppFilter
= CppEditor::CppModelManager::createAuxiliaryCurrentDocumentFilter(); = CppEditor::CppModelManager::createAuxiliaryCurrentDocumentFilter();
LspCurrentDocumentFilter lspFilter; LspCurrentDocumentFilter lspFilter;
Core::ILocatorFilter *activeFilter = nullptr; ILocatorFilter *activeFilter = nullptr;
}; };
@@ -322,8 +323,8 @@ ClangdCurrentDocumentFilter::ClangdCurrentDocumentFilter() : d(new Private)
setPriority(High); setPriority(High);
setDefaultIncludedByDefault(false); setDefaultIncludedByDefault(false);
setEnabled(false); setEnabled(false);
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged, connect(EditorManager::instance(), &EditorManager::currentEditorChanged,
this, [this](const Core::IEditor *editor) { setEnabled(editor); }); this, [this](const IEditor *editor) { setEnabled(editor); });
} }
ClangdCurrentDocumentFilter::~ClangdCurrentDocumentFilter() { delete d; } ClangdCurrentDocumentFilter::~ClangdCurrentDocumentFilter() { delete d; }
@@ -346,14 +347,14 @@ void ClangdCurrentDocumentFilter::prepareSearch(const QString &entry)
d->activeFilter->prepareSearch(entry); d->activeFilter->prepareSearch(entry);
} }
QList<Core::LocatorFilterEntry> ClangdCurrentDocumentFilter::matchesFor( QList<LocatorFilterEntry> ClangdCurrentDocumentFilter::matchesFor(
QFutureInterface<Core::LocatorFilterEntry> &future, const QString &entry) QFutureInterface<LocatorFilterEntry> &future, const QString &entry)
{ {
QTC_ASSERT(d->activeFilter, return {}); QTC_ASSERT(d->activeFilter, return {});
return d->activeFilter->matchesFor(future, entry); return d->activeFilter->matchesFor(future, entry);
} }
void ClangdCurrentDocumentFilter::accept(const Core::LocatorFilterEntry &selection, QString *newText, void ClangdCurrentDocumentFilter::accept(const LocatorFilterEntry &selection, QString *newText,
int *selectionStart, int *selectionLength) const int *selectionStart, int *selectionLength) const
{ {
QTC_ASSERT(d->activeFilter, return); QTC_ASSERT(d->activeFilter, return);

View File

@@ -17,6 +17,7 @@
#include <utils/algorithm.h> #include <utils/algorithm.h>
using namespace Core;
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
@@ -64,7 +65,7 @@ void CMakeTargetLocatorFilter::prepareSearch(const QString &entry)
extraData.insert("line", line); extraData.insert("line", line);
extraData.insert("file", path.toString()); extraData.insert("file", path.toString());
Core::LocatorFilterEntry filterEntry(this, target.title, extraData); LocatorFilterEntry filterEntry(this, target.title, extraData);
filterEntry.extraInfo = path.shortNativePath(); filterEntry.extraInfo = path.shortNativePath();
filterEntry.highlightInfo = {index, int(entry.length())}; filterEntry.highlightInfo = {index, int(entry.length())};
filterEntry.filePath = path; filterEntry.filePath = path;
@@ -75,7 +76,8 @@ void CMakeTargetLocatorFilter::prepareSearch(const QString &entry)
} }
} }
QList<Core::LocatorFilterEntry> CMakeTargetLocatorFilter::matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future, const QString &entry) QList<LocatorFilterEntry> CMakeTargetLocatorFilter::matchesFor(
QFutureInterface<LocatorFilterEntry> &future, const QString &entry)
{ {
Q_UNUSED(future) Q_UNUSED(future)
Q_UNUSED(entry) Q_UNUSED(entry)
@@ -85,7 +87,8 @@ QList<Core::LocatorFilterEntry> CMakeTargetLocatorFilter::matchesFor(QFutureInte
void CMakeTargetLocatorFilter::projectListUpdated() void CMakeTargetLocatorFilter::projectListUpdated()
{ {
// Enable the filter if there's at least one CMake project // Enable the filter if there's at least one CMake project
setEnabled(Utils::contains(SessionManager::projects(), [](Project *p) { return qobject_cast<CMakeProject *>(p); })); setEnabled(Utils::contains(SessionManager::projects(),
[](Project *p) { return qobject_cast<CMakeProject *>(p); }));
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@@ -101,10 +104,8 @@ BuildCMakeTargetLocatorFilter::BuildCMakeTargetLocatorFilter()
setPriority(High); setPriority(High);
} }
void BuildCMakeTargetLocatorFilter::accept(const Core::LocatorFilterEntry &selection, void BuildCMakeTargetLocatorFilter::accept(const LocatorFilterEntry &selection, QString *newText,
QString *newText, int *selectionStart, int *selectionLength) const
int *selectionStart,
int *selectionLength) const
{ {
Q_UNUSED(newText) Q_UNUSED(newText)
Q_UNUSED(selectionStart) Q_UNUSED(selectionStart)
@@ -151,7 +152,7 @@ OpenCMakeTargetLocatorFilter::OpenCMakeTargetLocatorFilter()
setPriority(Medium); setPriority(Medium);
} }
void OpenCMakeTargetLocatorFilter::accept(const Core::LocatorFilterEntry &selection, void OpenCMakeTargetLocatorFilter::accept(const LocatorFilterEntry &selection,
QString *newText, QString *newText,
int *selectionStart, int *selectionStart,
int *selectionLength) const int *selectionLength) const
@@ -165,11 +166,9 @@ void OpenCMakeTargetLocatorFilter::accept(const Core::LocatorFilterEntry &select
const auto file = FilePath::fromVariant(extraData.value("file")); const auto file = FilePath::fromVariant(extraData.value("file"));
if (line >= 0) if (line >= 0)
Core::EditorManager::openEditorAt({file, line}, EditorManager::openEditorAt({file, line}, {}, EditorManager::AllowExternalEditor);
{},
Core::EditorManager::AllowExternalEditor);
else else
Core::EditorManager::openEditor(file, {}, Core::EditorManager::AllowExternalEditor); EditorManager::openEditor(file, {}, EditorManager::AllowExternalEditor);
} }
} // CMakeProjectManager::Internal } // CMakeProjectManager::Internal

View File

@@ -15,6 +15,7 @@
#include <QHash> #include <QHash>
#include <QRegularExpression> #include <QRegularExpression>
using namespace Core;
using namespace CPlusPlus; using namespace CPlusPlus;
namespace CppEditor::Internal { namespace CppEditor::Internal {
@@ -35,9 +36,9 @@ CppCurrentDocumentFilter::CppCurrentDocumentFilter(CppModelManager *manager)
connect(manager, &CppModelManager::documentUpdated, connect(manager, &CppModelManager::documentUpdated,
this, &CppCurrentDocumentFilter::onDocumentUpdated); this, &CppCurrentDocumentFilter::onDocumentUpdated);
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged, connect(EditorManager::instance(), &EditorManager::currentEditorChanged,
this, &CppCurrentDocumentFilter::onCurrentEditorChanged); this, &CppCurrentDocumentFilter::onCurrentEditorChanged);
connect(Core::EditorManager::instance(), &Core::EditorManager::editorAboutToClose, connect(EditorManager::instance(), &EditorManager::editorAboutToClose,
this, &CppCurrentDocumentFilter::onEditorAboutToClose); this, &CppCurrentDocumentFilter::onEditorAboutToClose);
} }
@@ -50,11 +51,11 @@ void CppCurrentDocumentFilter::makeAuxiliary()
setHidden(true); setHidden(true);
} }
QList<Core::LocatorFilterEntry> CppCurrentDocumentFilter::matchesFor( QList<LocatorFilterEntry> CppCurrentDocumentFilter::matchesFor(
QFutureInterface<Core::LocatorFilterEntry> &future, const QString & entry) QFutureInterface<LocatorFilterEntry> &future, const QString & entry)
{ {
QList<Core::LocatorFilterEntry> goodEntries; QList<LocatorFilterEntry> goodEntries;
QList<Core::LocatorFilterEntry> betterEntries; QList<LocatorFilterEntry> betterEntries;
const QRegularExpression regexp = createRegExp(entry); const QRegularExpression regexp = createRegExp(entry);
if (!regexp.isValid()) if (!regexp.isValid())
@@ -84,14 +85,14 @@ QList<Core::LocatorFilterEntry> CppCurrentDocumentFilter::matchesFor(
} }
} }
Core::LocatorFilterEntry filterEntry(this, name, id, info->icon()); LocatorFilterEntry filterEntry(this, name, id, info->icon());
filterEntry.extraInfo = extraInfo; filterEntry.extraInfo = extraInfo;
if (match.hasMatch()) { if (match.hasMatch()) {
filterEntry.highlightInfo = highlightInfo(match); filterEntry.highlightInfo = highlightInfo(match);
} else { } else {
match = regexp.match(extraInfo); match = regexp.match(extraInfo);
filterEntry.highlightInfo = filterEntry.highlightInfo =
highlightInfo(match, Core::LocatorFilterEntry::HighlightInfo::ExtraInfo); highlightInfo(match, LocatorFilterEntry::HighlightInfo::ExtraInfo);
} }
if (betterMatch) if (betterMatch)
@@ -104,18 +105,18 @@ QList<Core::LocatorFilterEntry> CppCurrentDocumentFilter::matchesFor(
// entries are unsorted by design! // entries are unsorted by design!
betterEntries += goodEntries; betterEntries += goodEntries;
QHash<QString, QList<Core::LocatorFilterEntry>> possibleDuplicates; QHash<QString, QList<LocatorFilterEntry>> possibleDuplicates;
for (const Core::LocatorFilterEntry &e : std::as_const(betterEntries)) { for (const LocatorFilterEntry &e : std::as_const(betterEntries)) {
const IndexItem::Ptr info = qvariant_cast<IndexItem::Ptr>(e.internalData); const IndexItem::Ptr info = qvariant_cast<IndexItem::Ptr>(e.internalData);
possibleDuplicates[info->scopedSymbolName() + info->symbolType()] << e; possibleDuplicates[info->scopedSymbolName() + info->symbolType()] << e;
} }
for (auto it = possibleDuplicates.cbegin(); it != possibleDuplicates.cend(); ++it) { for (auto it = possibleDuplicates.cbegin(); it != possibleDuplicates.cend(); ++it) {
const QList<Core::LocatorFilterEntry> &duplicates = it.value(); const QList<LocatorFilterEntry> &duplicates = it.value();
if (duplicates.size() == 1) if (duplicates.size() == 1)
continue; continue;
QList<Core::LocatorFilterEntry> declarations; QList<LocatorFilterEntry> declarations;
QList<Core::LocatorFilterEntry> definitions; QList<LocatorFilterEntry> definitions;
for (const Core::LocatorFilterEntry &candidate : duplicates) { for (const LocatorFilterEntry &candidate : duplicates) {
const IndexItem::Ptr info = qvariant_cast<IndexItem::Ptr>(candidate.internalData); const IndexItem::Ptr info = qvariant_cast<IndexItem::Ptr>(candidate.internalData);
if (info->type() != IndexItem::Function) if (info->type() != IndexItem::Function)
break; break;
@@ -126,8 +127,8 @@ QList<Core::LocatorFilterEntry> CppCurrentDocumentFilter::matchesFor(
} }
if (definitions.size() == 1 if (definitions.size() == 1
&& declarations.size() + definitions.size() == duplicates.size()) { && declarations.size() + definitions.size() == duplicates.size()) {
for (const Core::LocatorFilterEntry &decl : std::as_const(declarations)) for (const LocatorFilterEntry &decl : std::as_const(declarations))
Utils::erase(betterEntries, [&decl](const Core::LocatorFilterEntry &e) { Utils::erase(betterEntries, [&decl](const LocatorFilterEntry &e) {
return e.internalData == decl.internalData; return e.internalData == decl.internalData;
}); });
} }
@@ -136,15 +137,14 @@ QList<Core::LocatorFilterEntry> CppCurrentDocumentFilter::matchesFor(
return betterEntries; return betterEntries;
} }
void CppCurrentDocumentFilter::accept(const Core::LocatorFilterEntry &selection, void CppCurrentDocumentFilter::accept(const LocatorFilterEntry &selection, QString *newText,
QString *newText, int *selectionStart, int *selectionStart, int *selectionLength) const
int *selectionLength) const
{ {
Q_UNUSED(newText) Q_UNUSED(newText)
Q_UNUSED(selectionStart) Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength) Q_UNUSED(selectionLength)
IndexItem::Ptr info = qvariant_cast<IndexItem::Ptr>(selection.internalData); IndexItem::Ptr info = qvariant_cast<IndexItem::Ptr>(selection.internalData);
Core::EditorManager::openEditorAt({info->filePath(), info->line(), info->column()}); EditorManager::openEditorAt({info->filePath(), info->line(), info->column()});
} }
void CppCurrentDocumentFilter::onDocumentUpdated(Document::Ptr doc) void CppCurrentDocumentFilter::onDocumentUpdated(Document::Ptr doc)
@@ -154,7 +154,7 @@ void CppCurrentDocumentFilter::onDocumentUpdated(Document::Ptr doc)
m_itemsOfCurrentDoc.clear(); m_itemsOfCurrentDoc.clear();
} }
void CppCurrentDocumentFilter::onCurrentEditorChanged(Core::IEditor *currentEditor) void CppCurrentDocumentFilter::onCurrentEditorChanged(IEditor *currentEditor)
{ {
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
if (currentEditor) if (currentEditor)
@@ -164,7 +164,7 @@ void CppCurrentDocumentFilter::onCurrentEditorChanged(Core::IEditor *currentEdit
m_itemsOfCurrentDoc.clear(); m_itemsOfCurrentDoc.clear();
} }
void CppCurrentDocumentFilter::onEditorAboutToClose(Core::IEditor *editorAboutToClose) void CppCurrentDocumentFilter::onEditorAboutToClose(IEditor *editorAboutToClose)
{ {
if (!editorAboutToClose) if (!editorAboutToClose)
return; return;

View File

@@ -14,6 +14,8 @@
#include <algorithm> #include <algorithm>
#include <numeric> #include <numeric>
using namespace Core;
namespace CppEditor { namespace CppEditor {
CppLocatorFilter::CppLocatorFilter(CppLocatorData *locatorData) CppLocatorFilter::CppLocatorFilter(CppLocatorData *locatorData)
@@ -27,10 +29,10 @@ CppLocatorFilter::CppLocatorFilter(CppLocatorData *locatorData)
CppLocatorFilter::~CppLocatorFilter() = default; CppLocatorFilter::~CppLocatorFilter() = default;
Core::LocatorFilterEntry CppLocatorFilter::filterEntryFromIndexItem(IndexItem::Ptr info) LocatorFilterEntry CppLocatorFilter::filterEntryFromIndexItem(IndexItem::Ptr info)
{ {
const QVariant id = QVariant::fromValue(info); const QVariant id = QVariant::fromValue(info);
Core::LocatorFilterEntry filterEntry(this, info->scopedSymbolName(), id, info->icon()); LocatorFilterEntry filterEntry(this, info->scopedSymbolName(), id, info->icon());
if (info->type() == IndexItem::Class || info->type() == IndexItem::Enum) if (info->type() == IndexItem::Class || info->type() == IndexItem::Enum)
filterEntry.extraInfo = info->shortNativeFilePath(); filterEntry.extraInfo = info->shortNativeFilePath();
else else
@@ -39,10 +41,10 @@ Core::LocatorFilterEntry CppLocatorFilter::filterEntryFromIndexItem(IndexItem::P
return filterEntry; return filterEntry;
} }
QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor( QList<LocatorFilterEntry> CppLocatorFilter::matchesFor(
QFutureInterface<Core::LocatorFilterEntry> &future, const QString &entry) QFutureInterface<LocatorFilterEntry> &future, const QString &entry)
{ {
QList<Core::LocatorFilterEntry> entries[int(MatchLevel::Count)]; QList<LocatorFilterEntry> entries[int(MatchLevel::Count)];
const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry); const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry);
const IndexItem::ItemType wanted = matchTypes(); const IndexItem::ItemType wanted = matchTypes();
@@ -70,7 +72,7 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
} }
if (match.hasMatch()) { if (match.hasMatch()) {
Core::LocatorFilterEntry filterEntry = filterEntryFromIndexItem(info); LocatorFilterEntry filterEntry = filterEntryFromIndexItem(info);
// Highlight the matched characters, therefore it may be necessary // Highlight the matched characters, therefore it may be necessary
// to update the match if the displayName is different from matchString // to update the match if the displayName is different from matchString
@@ -82,7 +84,7 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
if (matchInParameterList && filterEntry.highlightInfo.startsDisplay.isEmpty()) { if (matchInParameterList && filterEntry.highlightInfo.startsDisplay.isEmpty()) {
match = regexp.match(filterEntry.extraInfo); match = regexp.match(filterEntry.extraInfo);
filterEntry.highlightInfo filterEntry.highlightInfo
= highlightInfo(match, Core::LocatorFilterEntry::HighlightInfo::ExtraInfo); = highlightInfo(match, LocatorFilterEntry::HighlightInfo::ExtraInfo);
} else if (matchOffset > 0) { } else if (matchOffset > 0) {
for (int &start : filterEntry.highlightInfo.startsDisplay) for (int &start : filterEntry.highlightInfo.startsDisplay)
start -= matchOffset; start -= matchOffset;
@@ -107,22 +109,21 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
for (auto &entry : entries) { for (auto &entry : entries) {
if (entry.size() < 1000) if (entry.size() < 1000)
Utils::sort(entry, Core::LocatorFilterEntry::compareLexigraphically); Utils::sort(entry, LocatorFilterEntry::compareLexigraphically);
} }
return std::accumulate(std::begin(entries), std::end(entries), QList<Core::LocatorFilterEntry>()); return std::accumulate(std::begin(entries), std::end(entries), QList<LocatorFilterEntry>());
} }
void CppLocatorFilter::accept(const Core::LocatorFilterEntry &selection, void CppLocatorFilter::accept(const LocatorFilterEntry &selection,
QString *newText, int *selectionStart, int *selectionLength) const QString *newText, int *selectionStart, int *selectionLength) const
{ {
Q_UNUSED(newText) Q_UNUSED(newText)
Q_UNUSED(selectionStart) Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength) Q_UNUSED(selectionLength)
IndexItem::Ptr info = qvariant_cast<IndexItem::Ptr>(selection.internalData); IndexItem::Ptr info = qvariant_cast<IndexItem::Ptr>(selection.internalData);
Core::EditorManager::openEditorAt({info->filePath(), info->line(), info->column()}, EditorManager::openEditorAt({info->filePath(), info->line(), info->column()}, {},
{}, EditorManager::AllowExternalEditor);
Core::EditorManager::AllowExternalEditor);
} }
CppClassesFilter::CppClassesFilter(CppLocatorData *locatorData) CppClassesFilter::CppClassesFilter(CppLocatorData *locatorData)
@@ -136,10 +137,10 @@ CppClassesFilter::CppClassesFilter(CppLocatorData *locatorData)
CppClassesFilter::~CppClassesFilter() = default; CppClassesFilter::~CppClassesFilter() = default;
Core::LocatorFilterEntry CppClassesFilter::filterEntryFromIndexItem(IndexItem::Ptr info) LocatorFilterEntry CppClassesFilter::filterEntryFromIndexItem(IndexItem::Ptr info)
{ {
const QVariant id = QVariant::fromValue(info); const QVariant id = QVariant::fromValue(info);
Core::LocatorFilterEntry filterEntry(this, info->symbolName(), id, info->icon()); LocatorFilterEntry filterEntry(this, info->symbolName(), id, info->icon());
filterEntry.extraInfo = info->symbolScope().isEmpty() filterEntry.extraInfo = info->symbolScope().isEmpty()
? info->shortNativeFilePath() ? info->shortNativeFilePath()
: info->symbolScope(); : info->symbolScope();
@@ -158,7 +159,7 @@ CppFunctionsFilter::CppFunctionsFilter(CppLocatorData *locatorData)
CppFunctionsFilter::~CppFunctionsFilter() = default; CppFunctionsFilter::~CppFunctionsFilter() = default;
Core::LocatorFilterEntry CppFunctionsFilter::filterEntryFromIndexItem(IndexItem::Ptr info) LocatorFilterEntry CppFunctionsFilter::filterEntryFromIndexItem(IndexItem::Ptr info)
{ {
const QVariant id = QVariant::fromValue(info); const QVariant id = QVariant::fromValue(info);
@@ -171,7 +172,7 @@ Core::LocatorFilterEntry CppFunctionsFilter::filterEntryFromIndexItem(IndexItem:
extraInfo.append(" (" + info->filePath().fileName() + ')'); extraInfo.append(" (" + info->filePath().fileName() + ')');
} }
Core::LocatorFilterEntry filterEntry(this, name + info->symbolType(), id, info->icon()); LocatorFilterEntry filterEntry(this, name + info->symbolType(), id, info->icon());
filterEntry.extraInfo = extraInfo; filterEntry.extraInfo = extraInfo;
return filterEntry; return filterEntry;

View File

@@ -90,6 +90,7 @@
#include <sstream> #include <sstream>
#endif #endif
using namespace Core;
using namespace CPlusPlus; using namespace CPlusPlus;
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
@@ -155,7 +156,7 @@ public:
class CppModelManagerPrivate class CppModelManagerPrivate
{ {
public: public:
void setupWatcher(const QFuture<void> &future, ProjectExplorer::Project *project, void setupWatcher(const QFuture<void> &future, Project *project,
ProjectData *projectData, CppModelManager *q); ProjectData *projectData, CppModelManager *q);
// Snapshot // Snapshot
@@ -164,15 +165,15 @@ public:
// Project integration // Project integration
QReadWriteLock m_projectLock; QReadWriteLock m_projectLock;
QHash<ProjectExplorer::Project *, ProjectData> m_projectData; QHash<Project *, ProjectData> m_projectData;
QMap<Utils::FilePath, QList<ProjectPart::ConstPtr> > m_fileToProjectParts; QMap<FilePath, QList<ProjectPart::ConstPtr> > m_fileToProjectParts;
QMap<QString, ProjectPart::ConstPtr> m_projectPartIdToProjectProjectPart; QMap<QString, ProjectPart::ConstPtr> m_projectPartIdToProjectProjectPart;
// The members below are cached/(re)calculated from the projects and/or their project parts // The members below are cached/(re)calculated from the projects and/or their project parts
bool m_dirty; bool m_dirty;
Utils::FilePaths m_projectFiles; FilePaths m_projectFiles;
ProjectExplorer::HeaderPaths m_headerPaths; HeaderPaths m_headerPaths;
ProjectExplorer::Macros m_definedMacros; Macros m_definedMacros;
// Editor integration // Editor integration
mutable QMutex m_cppEditorDocumentsMutex; mutable QMutex m_cppEditorDocumentsMutex;
@@ -201,12 +202,12 @@ public:
QTimer m_fallbackProjectPartTimer; QTimer m_fallbackProjectPartTimer;
CppLocatorData m_locatorData; CppLocatorData m_locatorData;
std::unique_ptr<Core::ILocatorFilter> m_locatorFilter; std::unique_ptr<ILocatorFilter> m_locatorFilter;
std::unique_ptr<Core::ILocatorFilter> m_classesFilter; std::unique_ptr<ILocatorFilter> m_classesFilter;
std::unique_ptr<Core::ILocatorFilter> m_includesFilter; std::unique_ptr<ILocatorFilter> m_includesFilter;
std::unique_ptr<Core::ILocatorFilter> m_functionsFilter; std::unique_ptr<ILocatorFilter> m_functionsFilter;
std::unique_ptr<Core::IFindFilter> m_symbolsFindFilter; std::unique_ptr<IFindFilter> m_symbolsFindFilter;
std::unique_ptr<Core::ILocatorFilter> m_currentDocumentFilter; std::unique_ptr<ILocatorFilter> m_currentDocumentFilter;
QList<Document::DiagnosticMessage> m_diagnosticMessages; QList<Document::DiagnosticMessage> m_diagnosticMessages;
}; };
@@ -338,7 +339,7 @@ void CppModelManager::findUsages(const CursorInEditor &data, Backend backend)
void CppModelManager::switchHeaderSource(bool inNextSplit, Backend backend) void CppModelManager::switchHeaderSource(bool inNextSplit, Backend backend)
{ {
const Core::IDocument *currentDocument = Core::EditorManager::currentDocument(); const IDocument *currentDocument = EditorManager::currentDocument();
QTC_ASSERT(currentDocument, return); QTC_ASSERT(currentDocument, return);
instance()->modelManagerSupport(backend)->switchHeaderSource(currentDocument->filePath(), instance()->modelManagerSupport(backend)->switchHeaderSource(currentDocument->filePath(),
inNextSplit); inNextSplit);
@@ -346,16 +347,16 @@ void CppModelManager::switchHeaderSource(bool inNextSplit, Backend backend)
void CppModelManager::showPreprocessedFile(bool inNextSplit) void CppModelManager::showPreprocessedFile(bool inNextSplit)
{ {
const Core::IDocument *doc = Core::EditorManager::currentDocument(); const IDocument *doc = EditorManager::currentDocument();
QTC_ASSERT(doc, return); QTC_ASSERT(doc, return);
static const auto showError = [](const QString &reason) { static const auto showError = [](const QString &reason) {
Core::MessageManager::writeFlashing(Tr::tr("Cannot show preprocessed file: %1") MessageManager::writeFlashing(Tr::tr("Cannot show preprocessed file: %1")
.arg(reason)); .arg(reason));
}; };
static const auto showFallbackWarning = [](const QString &reason) { static const auto showFallbackWarning = [](const QString &reason) {
Core::MessageManager::writeSilently( MessageManager::writeSilently(Tr::tr("Falling back to built-in preprocessor: %1")
Tr::tr("Falling back to built-in preprocessor: %1").arg(reason)); .arg(reason));
}; };
static const auto saveAndOpen = [](const FilePath &filePath, const QByteArray &contents, static const auto saveAndOpen = [](const FilePath &filePath, const QByteArray &contents,
bool inNextSplit) { bool inNextSplit) {
@@ -469,24 +470,24 @@ class FindUnusedActionsEnabledSwitcher
{ {
public: public:
FindUnusedActionsEnabledSwitcher() FindUnusedActionsEnabledSwitcher()
: actions{Core::ActionManager::command("CppTools.FindUnusedFunctions"), : actions{ActionManager::command("CppTools.FindUnusedFunctions"),
Core::ActionManager::command("CppTools.FindUnusedFunctionsInSubProject")} ActionManager::command("CppTools.FindUnusedFunctionsInSubProject")}
{ {
for (Core::Command * const action : actions) for (Command * const action : actions)
action->action()->setEnabled(false); action->action()->setEnabled(false);
} }
~FindUnusedActionsEnabledSwitcher() ~FindUnusedActionsEnabledSwitcher()
{ {
for (Core::Command * const action : actions) for (Command * const action : actions)
action->action()->setEnabled(true); action->action()->setEnabled(true);
} }
private: private:
const QList<Core::Command *> actions; const QList<Command *> actions;
}; };
using FindUnusedActionsEnabledSwitcherPtr = std::shared_ptr<FindUnusedActionsEnabledSwitcher>; using FindUnusedActionsEnabledSwitcherPtr = std::shared_ptr<FindUnusedActionsEnabledSwitcher>;
static void checkNextFunctionForUnused( static void checkNextFunctionForUnused(
const QPointer<Core::SearchResult> &search, const QPointer<SearchResult> &search,
const std::shared_ptr<QFutureInterface<bool>> &findRefsFuture, const std::shared_ptr<QFutureInterface<bool>> &findRefsFuture,
const FindUnusedActionsEnabledSwitcherPtr &actionsSwitcher) const FindUnusedActionsEnabledSwitcherPtr &actionsSwitcher)
{ {
@@ -531,30 +532,28 @@ void CppModelManager::findUnusedFunctions(const FilePath &folder)
const auto actionsSwitcher = std::make_shared<FindUnusedActionsEnabledSwitcher>(); const auto actionsSwitcher = std::make_shared<FindUnusedActionsEnabledSwitcher>();
// Step 1: Employ locator to find all functions // Step 1: Employ locator to find all functions
Core::ILocatorFilter *const functionsFilter ILocatorFilter *const functionsFilter
= Utils::findOrDefault(Core::ILocatorFilter::allLocatorFilters(), = Utils::findOrDefault(ILocatorFilter::allLocatorFilters(),
Utils::equal(&Core::ILocatorFilter::id, Utils::equal(&ILocatorFilter::id,
Id(Constants::FUNCTIONS_FILTER_ID))); Id(Constants::FUNCTIONS_FILTER_ID)));
QTC_ASSERT(functionsFilter, return); QTC_ASSERT(functionsFilter, return);
const QPointer<Core::SearchResult> search const QPointer<SearchResult> search
= Core::SearchResultWindow::instance() = SearchResultWindow::instance()->startNewSearch(Tr::tr("Find Unused Functions"),
->startNewSearch(Tr::tr("Find Unused Functions"),
{}, {},
{}, {},
Core::SearchResultWindow::SearchOnly, SearchResultWindow::SearchOnly,
Core::SearchResultWindow::PreserveCaseDisabled, SearchResultWindow::PreserveCaseDisabled,
"CppEditor"); "CppEditor");
connect(search, &Core::SearchResult::activated, [](const Core::SearchResultItem &item) { connect(search, &SearchResult::activated, [](const SearchResultItem &item) {
Core::EditorManager::openEditorAtSearchResult(item); EditorManager::openEditorAtSearchResult(item);
}); });
Core::SearchResultWindow::instance()->popup(Core::IOutputPane::ModeSwitch SearchResultWindow::instance()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus);
| Core::IOutputPane::WithFocus); const auto locatorWatcher = new QFutureWatcher<LocatorFilterEntry>(search);
const auto locatorWatcher = new QFutureWatcher<Core::LocatorFilterEntry>(search);
functionsFilter->prepareSearch({}); functionsFilter->prepareSearch({});
connect(search, &Core::SearchResult::canceled, locatorWatcher, [locatorWatcher] { connect(search, &SearchResult::canceled, locatorWatcher, [locatorWatcher] {
locatorWatcher->cancel(); locatorWatcher->cancel();
}); });
connect(locatorWatcher, &QFutureWatcher<Core::LocatorFilterEntry>::finished, search, connect(locatorWatcher, &QFutureWatcher<LocatorFilterEntry>::finished, search,
[locatorWatcher, search, folder, actionsSwitcher] { [locatorWatcher, search, folder, actionsSwitcher] {
locatorWatcher->deleteLater(); locatorWatcher->deleteLater();
if (locatorWatcher->isCanceled()) { if (locatorWatcher->isCanceled()) {
@@ -563,7 +562,7 @@ void CppModelManager::findUnusedFunctions(const FilePath &folder)
} }
Links links; Links links;
for (int i = 0; i < locatorWatcher->future().resultCount(); ++i) { for (int i = 0; i < locatorWatcher->future().resultCount(); ++i) {
const Core::LocatorFilterEntry &entry = locatorWatcher->resultAt(i); const LocatorFilterEntry &entry = locatorWatcher->resultAt(i);
static const QStringList prefixBlacklist{"main(", "~", "qHash(", "begin()", "end()", static const QStringList prefixBlacklist{"main(", "~", "qHash(", "begin()", "end()",
"cbegin()", "cend()", "constBegin()", "constEnd()"}; "cbegin()", "cend()", "constBegin()", "constEnd()"};
if (Utils::anyOf(prefixBlacklist, [&entry](const QString &prefix) { if (Utils::anyOf(prefixBlacklist, [&entry](const QString &prefix) {
@@ -593,12 +592,11 @@ void CppModelManager::findUnusedFunctions(const FilePath &folder)
})); }));
search->setUserData(remainingAndActiveLinks); search->setUserData(remainingAndActiveLinks);
const auto findRefsFuture = std::make_shared<QFutureInterface<bool>>(); const auto findRefsFuture = std::make_shared<QFutureInterface<bool>>();
Core::FutureProgress *const progress FutureProgress *const progress = ProgressManager::addTask(findRefsFuture->future(),
= Core::ProgressManager::addTask(findRefsFuture->future(),
Tr::tr("Finding Unused Functions"), Tr::tr("Finding Unused Functions"),
"CppEditor.FindUnusedFunctions"); "CppEditor.FindUnusedFunctions");
connect(progress, connect(progress,
&Core::FutureProgress::canceled, &FutureProgress::canceled,
search, search,
[search, future = std::weak_ptr<QFutureInterface<bool>>(findRefsFuture)] { [search, future = std::weak_ptr<QFutureInterface<bool>>(findRefsFuture)] {
search->finishSearch(true); search->finishSearch(true);
@@ -608,7 +606,7 @@ void CppModelManager::findUnusedFunctions(const FilePath &folder)
} }
}); });
findRefsFuture->setProgressRange(0, links.size()); findRefsFuture->setProgressRange(0, links.size());
connect(search, &Core::SearchResult::canceled, [findRefsFuture] { connect(search, &SearchResult::canceled, [findRefsFuture] {
findRefsFuture->cancel(); findRefsFuture->cancel();
findRefsFuture->reportFinished(); findRefsFuture->reportFinished();
}); });
@@ -620,12 +618,12 @@ void CppModelManager::findUnusedFunctions(const FilePath &folder)
checkNextFunctionForUnused(search, findRefsFuture, actionsSwitcher); checkNextFunctionForUnused(search, findRefsFuture, actionsSwitcher);
}); });
locatorWatcher->setFuture( locatorWatcher->setFuture(
Utils::runAsync([functionsFilter](QFutureInterface<Core::LocatorFilterEntry> &future) { Utils::runAsync([functionsFilter](QFutureInterface<LocatorFilterEntry> &future) {
future.reportResults(functionsFilter->matchesFor(future, {})); future.reportResults(functionsFilter->matchesFor(future, {}));
})); }));
} }
void CppModelManager::checkForUnusedSymbol(Core::SearchResult *search, void CppModelManager::checkForUnusedSymbol(SearchResult *search,
const Link &link, const Link &link,
CPlusPlus::Symbol *symbol, CPlusPlus::Symbol *symbol,
const CPlusPlus::LookupContext &context, const CPlusPlus::LookupContext &context,
@@ -785,62 +783,62 @@ static void setFilter(std::unique_ptr<FilterClass> &filter,
filter = std::move(newFilter); filter = std::move(newFilter);
} }
void CppModelManager::setLocatorFilter(std::unique_ptr<Core::ILocatorFilter> &&filter) void CppModelManager::setLocatorFilter(std::unique_ptr<ILocatorFilter> &&filter)
{ {
setFilter(d->m_locatorFilter, std::move(filter)); setFilter(d->m_locatorFilter, std::move(filter));
} }
void CppModelManager::setClassesFilter(std::unique_ptr<Core::ILocatorFilter> &&filter) void CppModelManager::setClassesFilter(std::unique_ptr<ILocatorFilter> &&filter)
{ {
setFilter(d->m_classesFilter, std::move(filter)); setFilter(d->m_classesFilter, std::move(filter));
} }
void CppModelManager::setIncludesFilter(std::unique_ptr<Core::ILocatorFilter> &&filter) void CppModelManager::setIncludesFilter(std::unique_ptr<ILocatorFilter> &&filter)
{ {
setFilter(d->m_includesFilter, std::move(filter)); setFilter(d->m_includesFilter, std::move(filter));
} }
void CppModelManager::setFunctionsFilter(std::unique_ptr<Core::ILocatorFilter> &&filter) void CppModelManager::setFunctionsFilter(std::unique_ptr<ILocatorFilter> &&filter)
{ {
setFilter(d->m_functionsFilter, std::move(filter)); setFilter(d->m_functionsFilter, std::move(filter));
} }
void CppModelManager::setSymbolsFindFilter(std::unique_ptr<Core::IFindFilter> &&filter) void CppModelManager::setSymbolsFindFilter(std::unique_ptr<IFindFilter> &&filter)
{ {
setFilter(d->m_symbolsFindFilter, std::move(filter)); setFilter(d->m_symbolsFindFilter, std::move(filter));
} }
void CppModelManager::setCurrentDocumentFilter(std::unique_ptr<Core::ILocatorFilter> &&filter) void CppModelManager::setCurrentDocumentFilter(std::unique_ptr<ILocatorFilter> &&filter)
{ {
setFilter(d->m_currentDocumentFilter, std::move(filter)); setFilter(d->m_currentDocumentFilter, std::move(filter));
} }
Core::ILocatorFilter *CppModelManager::locatorFilter() const ILocatorFilter *CppModelManager::locatorFilter() const
{ {
return d->m_locatorFilter.get(); return d->m_locatorFilter.get();
} }
Core::ILocatorFilter *CppModelManager::classesFilter() const ILocatorFilter *CppModelManager::classesFilter() const
{ {
return d->m_classesFilter.get(); return d->m_classesFilter.get();
} }
Core::ILocatorFilter *CppModelManager::includesFilter() const ILocatorFilter *CppModelManager::includesFilter() const
{ {
return d->m_includesFilter.get(); return d->m_includesFilter.get();
} }
Core::ILocatorFilter *CppModelManager::functionsFilter() const ILocatorFilter *CppModelManager::functionsFilter() const
{ {
return d->m_functionsFilter.get(); return d->m_functionsFilter.get();
} }
Core::IFindFilter *CppModelManager::symbolsFindFilter() const IFindFilter *CppModelManager::symbolsFindFilter() const
{ {
return d->m_symbolsFindFilter.get(); return d->m_symbolsFindFilter.get();
} }
Core::ILocatorFilter *CppModelManager::currentDocumentFilter() const ILocatorFilter *CppModelManager::currentDocumentFilter() const
{ {
return d->m_currentDocumentFilter.get(); return d->m_currentDocumentFilter.get();
} }
@@ -880,7 +878,7 @@ CppModelManager *CppModelManager::instance()
void CppModelManager::registerJsExtension() void CppModelManager::registerJsExtension()
{ {
Core::JsExpander::registerGlobalObject("Cpp", [this] { JsExpander::registerGlobalObject("Cpp", [this] {
return new CppToolsJsExtension(&d->m_locatorData); return new CppToolsJsExtension(&d->m_locatorData);
}); });
} }
@@ -888,9 +886,9 @@ void CppModelManager::registerJsExtension()
void CppModelManager::initCppTools() void CppModelManager::initCppTools()
{ {
// Objects // Objects
connect(Core::VcsManager::instance(), &Core::VcsManager::repositoryChanged, connect(VcsManager::instance(), &VcsManager::repositoryChanged,
this, &CppModelManager::updateModifiedSourceFiles); this, &CppModelManager::updateModifiedSourceFiles);
connect(Core::DocumentManager::instance(), &Core::DocumentManager::filesChangedInternally, connect(DocumentManager::instance(), &DocumentManager::filesChangedInternally,
[this](const FilePaths &filePaths) { [this](const FilePaths &filePaths) {
updateSourceFiles(toSet(filePaths)); updateSourceFiles(toSet(filePaths));
}); });
@@ -924,7 +922,7 @@ CppModelManager::CppModelManager()
d->m_enableGC = true; d->m_enableGC = true;
// Visual C++ has 1MiB, macOSX has 512KiB // Visual C++ has 1MiB, macOSX has 512KiB
if (Utils::HostOsInfo::isWindowsHost() || Utils::HostOsInfo::isMacHost()) if (HostOsInfo::isWindowsHost() || HostOsInfo::isMacHost())
d->m_threadPool.setStackSize(2 * 1024 * 1024); d->m_threadPool.setStackSize(2 * 1024 * 1024);
qRegisterMetaType<QSet<QString> >(); qRegisterMetaType<QSet<QString> >();
@@ -940,23 +938,23 @@ CppModelManager::CppModelManager()
d->m_delayedGcTimer.setSingleShot(true); d->m_delayedGcTimer.setSingleShot(true);
connect(&d->m_delayedGcTimer, &QTimer::timeout, this, &CppModelManager::GC); connect(&d->m_delayedGcTimer, &QTimer::timeout, this, &CppModelManager::GC);
auto sessionManager = ProjectExplorer::SessionManager::instance(); auto sessionManager = SessionManager::instance();
connect(sessionManager, &ProjectExplorer::SessionManager::projectAdded, connect(sessionManager, &SessionManager::projectAdded,
this, &CppModelManager::onProjectAdded); this, &CppModelManager::onProjectAdded);
connect(sessionManager, &ProjectExplorer::SessionManager::aboutToRemoveProject, connect(sessionManager, &SessionManager::aboutToRemoveProject,
this, &CppModelManager::onAboutToRemoveProject); this, &CppModelManager::onAboutToRemoveProject);
connect(sessionManager, &ProjectExplorer::SessionManager::aboutToLoadSession, connect(sessionManager, &SessionManager::aboutToLoadSession,
this, &CppModelManager::onAboutToLoadSession); this, &CppModelManager::onAboutToLoadSession);
connect(sessionManager, &ProjectExplorer::SessionManager::startupProjectChanged, connect(sessionManager, &SessionManager::startupProjectChanged,
this, &CppModelManager::onActiveProjectChanged); this, &CppModelManager::onActiveProjectChanged);
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged, connect(EditorManager::instance(), &EditorManager::currentEditorChanged,
this, &CppModelManager::onCurrentEditorChanged); this, &CppModelManager::onCurrentEditorChanged);
connect(Core::DocumentManager::instance(), &Core::DocumentManager::allDocumentsRenamed, connect(DocumentManager::instance(), &DocumentManager::allDocumentsRenamed,
this, &CppModelManager::renameIncludes); this, &CppModelManager::renameIncludes);
connect(Core::ICore::instance(), &Core::ICore::coreAboutToClose, connect(ICore::instance(), &ICore::coreAboutToClose,
this, &CppModelManager::onCoreAboutToClose); this, &CppModelManager::onCoreAboutToClose);
d->m_fallbackProjectPartTimer.setSingleShot(true); d->m_fallbackProjectPartTimer.setSingleShot(true);
@@ -1041,13 +1039,13 @@ FilePaths CppModelManager::internalProjectFiles() const
return files; return files;
} }
ProjectExplorer::HeaderPaths CppModelManager::internalHeaderPaths() const HeaderPaths CppModelManager::internalHeaderPaths() const
{ {
ProjectExplorer::HeaderPaths headerPaths; HeaderPaths headerPaths;
for (const ProjectData &projectData: std::as_const(d->m_projectData)) { for (const ProjectData &projectData: std::as_const(d->m_projectData)) {
for (const ProjectPart::ConstPtr &part : projectData.projectInfo->projectParts()) { for (const ProjectPart::ConstPtr &part : projectData.projectInfo->projectParts()) {
for (const ProjectExplorer::HeaderPath &path : part->headerPaths) { for (const HeaderPath &path : part->headerPaths) {
ProjectExplorer::HeaderPath hp(QDir::cleanPath(path.path), path.type); HeaderPath hp(QDir::cleanPath(path.path), path.type);
if (!headerPaths.contains(hp)) if (!headerPaths.contains(hp))
headerPaths.push_back(std::move(hp)); headerPaths.push_back(std::move(hp));
} }
@@ -1056,8 +1054,7 @@ ProjectExplorer::HeaderPaths CppModelManager::internalHeaderPaths() const
return headerPaths; return headerPaths;
} }
static void addUnique(const ProjectExplorer::Macros &newMacros, static void addUnique(const Macros &newMacros, Macros &macros,
ProjectExplorer::Macros &macros,
QSet<ProjectExplorer::Macro> &alreadyIn) QSet<ProjectExplorer::Macro> &alreadyIn)
{ {
for (const ProjectExplorer::Macro &macro : newMacros) { for (const ProjectExplorer::Macro &macro : newMacros) {
@@ -1068,9 +1065,9 @@ static void addUnique(const ProjectExplorer::Macros &newMacros,
} }
} }
ProjectExplorer::Macros CppModelManager::internalDefinedMacros() const Macros CppModelManager::internalDefinedMacros() const
{ {
ProjectExplorer::Macros macros; Macros macros;
QSet<ProjectExplorer::Macro> alreadyIn; QSet<ProjectExplorer::Macro> alreadyIn;
for (const ProjectData &projectData : std::as_const(d->m_projectData)) { for (const ProjectData &projectData : std::as_const(d->m_projectData)) {
for (const ProjectPart::ConstPtr &part : projectData.projectInfo->projectParts()) { for (const ProjectPart::ConstPtr &part : projectData.projectInfo->projectParts()) {
@@ -1268,8 +1265,8 @@ static QSet<QString> filteredFilesRemoved(const QSet<QString> &files, int fileSi
const QString msg = Tr::tr("C++ Indexer: Skipping file \"%1\" " const QString msg = Tr::tr("C++ Indexer: Skipping file \"%1\" "
"because its path matches the ignore pattern.") "because its path matches the ignore pattern.")
.arg(filePath.displayName()); .arg(filePath.displayName());
QMetaObject::invokeMethod(Core::MessageManager::instance(), QMetaObject::invokeMethod(MessageManager::instance(),
[msg]() { Core::MessageManager::writeSilently(msg); }); [msg] { MessageManager::writeSilently(msg); });
skip = true; skip = true;
break; break;
} }
@@ -1304,7 +1301,7 @@ ProjectInfoList CppModelManager::projectInfos() const
[](const ProjectData &d) { return d.projectInfo; }); [](const ProjectData &d) { return d.projectInfo; });
} }
ProjectInfo::ConstPtr CppModelManager::projectInfo(ProjectExplorer::Project *project) const ProjectInfo::ConstPtr CppModelManager::projectInfo(Project *project) const
{ {
QReadLocker locker(&d->m_projectLock); QReadLocker locker(&d->m_projectLock);
return d->m_projectData.value(project).projectInfo; return d->m_projectData.value(project).projectInfo;
@@ -1424,8 +1421,7 @@ void CppModelManager::recalculateProjectPartMappings()
d->m_symbolFinder.clearCache(); d->m_symbolFinder.clearCache();
} }
void CppModelManagerPrivate::setupWatcher(const QFuture<void> &future, void CppModelManagerPrivate::setupWatcher(const QFuture<void> &future, Project *project,
ProjectExplorer::Project *project,
ProjectData *projectData, CppModelManager *q) ProjectData *projectData, CppModelManager *q)
{ {
projectData->indexer = new QFutureWatcher<void>(q); projectData->indexer = new QFutureWatcher<void>(q);
@@ -1446,10 +1442,10 @@ void CppModelManagerPrivate::setupWatcher(const QFuture<void> &future,
void CppModelManager::updateCppEditorDocuments(bool projectsUpdated) const void CppModelManager::updateCppEditorDocuments(bool projectsUpdated) const
{ {
// Refresh visible documents // Refresh visible documents
QSet<Core::IDocument *> visibleCppEditorDocuments; QSet<IDocument *> visibleCppEditorDocuments;
const QList<Core::IEditor *> editors = Core::EditorManager::visibleEditors(); const QList<IEditor *> editors = EditorManager::visibleEditors();
for (Core::IEditor *editor: editors) { for (IEditor *editor: editors) {
if (Core::IDocument *document = editor->document()) { if (IDocument *document = editor->document()) {
const FilePath filePath = document->filePath(); const FilePath filePath = document->filePath();
if (CppEditorDocumentHandle *theCppEditorDocument = cppEditorDocument(filePath)) { if (CppEditorDocumentHandle *theCppEditorDocument = cppEditorDocument(filePath)) {
visibleCppEditorDocuments.insert(document); visibleCppEditorDocuments.insert(document);
@@ -1459,10 +1455,10 @@ void CppModelManager::updateCppEditorDocuments(bool projectsUpdated) const
} }
// Mark invisible documents dirty // Mark invisible documents dirty
QSet<Core::IDocument *> invisibleCppEditorDocuments QSet<IDocument *> invisibleCppEditorDocuments
= Utils::toSet(Core::DocumentModel::openedDocuments()); = Utils::toSet(DocumentModel::openedDocuments());
invisibleCppEditorDocuments.subtract(visibleCppEditorDocuments); invisibleCppEditorDocuments.subtract(visibleCppEditorDocuments);
for (Core::IDocument *document : std::as_const(invisibleCppEditorDocuments)) { for (IDocument *document : std::as_const(invisibleCppEditorDocuments)) {
const FilePath filePath = document->filePath(); const FilePath filePath = document->filePath();
if (CppEditorDocumentHandle *theCppEditorDocument = cppEditorDocument(filePath)) { if (CppEditorDocumentHandle *theCppEditorDocument = cppEditorDocument(filePath)) {
const CppEditorDocumentHandle::RefreshReason refreshReason = projectsUpdated const CppEditorDocumentHandle::RefreshReason refreshReason = projectsUpdated
@@ -1483,7 +1479,7 @@ QFuture<void> CppModelManager::updateProjectInfo(const ProjectInfo::ConstPtr &ne
QStringList removedProjectParts; QStringList removedProjectParts;
bool filesRemoved = false; bool filesRemoved = false;
ProjectExplorer::Project * const project = projectForProjectInfo(*newProjectInfo); Project * const project = projectForProjectInfo(*newProjectInfo);
if (!project) if (!project)
return {}; return {};
@@ -1589,20 +1585,20 @@ ProjectPart::ConstPtr CppModelManager::projectPartForId(const QString &projectPa
return d->m_projectPartIdToProjectProjectPart.value(projectPartId); return d->m_projectPartIdToProjectProjectPart.value(projectPartId);
} }
QList<ProjectPart::ConstPtr> CppModelManager::projectPart(const Utils::FilePath &fileName) const QList<ProjectPart::ConstPtr> CppModelManager::projectPart(const FilePath &fileName) const
{ {
QReadLocker locker(&d->m_projectLock); QReadLocker locker(&d->m_projectLock);
return d->m_fileToProjectParts.value(fileName.canonicalPath()); return d->m_fileToProjectParts.value(fileName.canonicalPath());
} }
QList<ProjectPart::ConstPtr> CppModelManager::projectPartFromDependencies( QList<ProjectPart::ConstPtr> CppModelManager::projectPartFromDependencies(
const Utils::FilePath &fileName) const const FilePath &fileName) const
{ {
QSet<ProjectPart::ConstPtr> parts; QSet<ProjectPart::ConstPtr> parts;
const Utils::FilePaths deps = snapshot().filesDependingOn(fileName); const FilePaths deps = snapshot().filesDependingOn(fileName);
QReadLocker locker(&d->m_projectLock); QReadLocker locker(&d->m_projectLock);
for (const Utils::FilePath &dep : deps) for (const FilePath &dep : deps)
parts.unite(Utils::toSet(d->m_fileToProjectParts.value(dep.canonicalPath()))); parts.unite(Utils::toSet(d->m_fileToProjectParts.value(dep.canonicalPath())));
return parts.values(); return parts.values();
@@ -1614,7 +1610,7 @@ ProjectPart::ConstPtr CppModelManager::fallbackProjectPart()
return d->m_fallbackProjectPart; return d->m_fallbackProjectPart;
} }
bool CppModelManager::isCppEditor(Core::IEditor *editor) bool CppModelManager::isCppEditor(IEditor *editor)
{ {
return editor->context().contains(ProjectExplorer::Constants::CXX_LANGUAGE_ID); return editor->context().contains(ProjectExplorer::Constants::CXX_LANGUAGE_ID);
} }
@@ -1647,7 +1643,7 @@ void CppModelManager::emitAbstractEditorSupportRemoved(const QString &filePath)
emit abstractEditorSupportRemoved(filePath); emit abstractEditorSupportRemoved(filePath);
} }
void CppModelManager::onProjectAdded(ProjectExplorer::Project *) void CppModelManager::onProjectAdded(Project *)
{ {
QWriteLocker locker(&d->m_projectLock); QWriteLocker locker(&d->m_projectLock);
d->m_dirty = true; d->m_dirty = true;
@@ -1667,7 +1663,7 @@ static QStringList removedProjectParts(const QStringList &before, const QStringL
return Utils::toList(b); return Utils::toList(b);
} }
void CppModelManager::onAboutToRemoveProject(ProjectExplorer::Project *project) void CppModelManager::onAboutToRemoveProject(Project *project)
{ {
QStringList idsOfRemovedProjectParts; QStringList idsOfRemovedProjectParts;
@@ -1689,7 +1685,7 @@ void CppModelManager::onAboutToRemoveProject(ProjectExplorer::Project *project)
delayedGC(); delayedGC();
} }
void CppModelManager::onActiveProjectChanged(ProjectExplorer::Project *project) void CppModelManager::onActiveProjectChanged(Project *project)
{ {
if (!project) if (!project)
return; // Last project closed. return; // Last project closed.
@@ -1711,7 +1707,7 @@ void CppModelManager::onSourceFilesRefreshed() const
} }
} }
void CppModelManager::onCurrentEditorChanged(Core::IEditor *editor) void CppModelManager::onCurrentEditorChanged(IEditor *editor)
{ {
if (!editor || !editor->document()) if (!editor || !editor->document())
return; return;
@@ -1752,7 +1748,7 @@ QSet<QString> CppModelManager::dependingInternalTargets(const FilePath &file) co
return result; return result;
} }
QSet<QString> CppModelManager::internalTargets(const Utils::FilePath &filePath) const QSet<QString> CppModelManager::internalTargets(const FilePath &filePath) const
{ {
const QList<ProjectPart::ConstPtr> projectParts = projectPart(filePath); const QList<ProjectPart::ConstPtr> projectParts = projectPart(filePath);
// if we have no project parts it's most likely a header with declarations only and CMake based // if we have no project parts it's most likely a header with declarations only and CMake based
@@ -1761,14 +1757,13 @@ QSet<QString> CppModelManager::internalTargets(const Utils::FilePath &filePath)
QSet<QString> targets; QSet<QString> targets;
for (const ProjectPart::ConstPtr &part : projectParts) { for (const ProjectPart::ConstPtr &part : projectParts) {
targets.insert(part->buildSystemTarget); targets.insert(part->buildSystemTarget);
if (part->buildTargetType != ProjectExplorer::BuildTargetType::Executable) if (part->buildTargetType != BuildTargetType::Executable)
targets.unite(dependingInternalTargets(filePath)); targets.unite(dependingInternalTargets(filePath));
} }
return targets; return targets;
} }
void CppModelManager::renameIncludes(const Utils::FilePath &oldFilePath, void CppModelManager::renameIncludes(const FilePath &oldFilePath, const FilePath &newFilePath)
const Utils::FilePath &newFilePath)
{ {
if (oldFilePath.isEmpty() || newFilePath.isEmpty()) if (oldFilePath.isEmpty() || newFilePath.isEmpty())
return; return;
@@ -1815,7 +1810,7 @@ void CppModelManager::renameIncludes(const Utils::FilePath &oldFilePath,
const QTextBlock &block = file->document()->findBlockByNumber(loc.second - 1); const QTextBlock &block = file->document()->findBlockByNumber(loc.second - 1);
const int replaceStart = block.text().indexOf(oldFileName); const int replaceStart = block.text().indexOf(oldFileName);
if (replaceStart > -1) { if (replaceStart > -1) {
Utils::ChangeSet changeSet; ChangeSet changeSet;
changeSet.replace(block.position() + replaceStart, changeSet.replace(block.position() + replaceStart,
block.position() + replaceStart + oldFileName.length(), block.position() + replaceStart + oldFileName.length(),
newFileName); newFileName);
@@ -1843,13 +1838,13 @@ static const char *belongingClassName(const Function *function)
return nullptr; return nullptr;
} }
QSet<QString> CppModelManager::symbolsInFiles(const QSet<Utils::FilePath> &files) const QSet<QString> CppModelManager::symbolsInFiles(const QSet<FilePath> &files) const
{ {
QSet<QString> uniqueSymbols; QSet<QString> uniqueSymbols;
const Snapshot cppSnapShot = snapshot(); const Snapshot cppSnapShot = snapshot();
// Iterate over the files and get interesting symbols // Iterate over the files and get interesting symbols
for (const Utils::FilePath &file : files) { for (const FilePath &file : files) {
// Add symbols from the C++ code model // Add symbols from the C++ code model
const CPlusPlus::Document::Ptr doc = cppSnapShot.document(file); const CPlusPlus::Document::Ptr doc = cppSnapShot.document(file);
if (!doc.isNull() && doc->control()) { if (!doc.isNull() && doc->control()) {
@@ -1881,7 +1876,7 @@ QSet<QString> CppModelManager::symbolsInFiles(const QSet<Utils::FilePath> &files
void CppModelManager::onCoreAboutToClose() void CppModelManager::onCoreAboutToClose()
{ {
Core::ProgressManager::cancelTasks(Constants::TASK_INDEX); ProgressManager::cancelTasks(Constants::TASK_INDEX);
d->m_enableGC = false; d->m_enableGC = false;
} }
@@ -1891,27 +1886,27 @@ void CppModelManager::setupFallbackProjectPart()
RawProjectPart rpp; RawProjectPart rpp;
rpp.setMacros(definedMacros()); rpp.setMacros(definedMacros());
rpp.setHeaderPaths(headerPaths()); rpp.setHeaderPaths(headerPaths());
rpp.setQtVersion(Utils::QtMajorVersion::Qt5); rpp.setQtVersion(QtMajorVersion::Qt5);
// Do not activate ObjectiveCExtensions since this will lead to the // Do not activate ObjectiveCExtensions since this will lead to the
// "objective-c++" language option for a project-less *.cpp file. // "objective-c++" language option for a project-less *.cpp file.
Utils::LanguageExtensions langExtensions = Utils::LanguageExtension::All; LanguageExtensions langExtensions = LanguageExtension::All;
langExtensions &= ~Utils::LanguageExtensions(Utils::LanguageExtension::ObjectiveC); langExtensions &= ~LanguageExtensions(LanguageExtension::ObjectiveC);
// TODO: Use different fallback toolchain for different kinds of files? // TODO: Use different fallback toolchain for different kinds of files?
const Kit * const defaultKit = KitManager::isLoaded() ? KitManager::defaultKit() : nullptr; const Kit * const defaultKit = KitManager::isLoaded() ? KitManager::defaultKit() : nullptr;
const ToolChain * const defaultTc = defaultKit const ToolChain * const defaultTc = defaultKit
? ToolChainKitAspect::cxxToolChain(defaultKit) : nullptr; ? ToolChainKitAspect::cxxToolChain(defaultKit) : nullptr;
if (defaultKit && defaultTc) { if (defaultKit && defaultTc) {
Utils::FilePath sysroot = SysRootKitAspect::sysRoot(defaultKit); FilePath sysroot = SysRootKitAspect::sysRoot(defaultKit);
if (sysroot.isEmpty()) if (sysroot.isEmpty())
sysroot = Utils::FilePath::fromString(defaultTc->sysRoot()); sysroot = FilePath::fromString(defaultTc->sysRoot());
Utils::Environment env = defaultKit->buildEnvironment(); Utils::Environment env = defaultKit->buildEnvironment();
tcInfo = ToolChainInfo(defaultTc, sysroot, env); tcInfo = ToolChainInfo(defaultTc, sysroot, env);
const auto macroInspectionWrapper = [runner = tcInfo.macroInspectionRunner]( const auto macroInspectionWrapper = [runner = tcInfo.macroInspectionRunner](
const QStringList &flags) { const QStringList &flags) {
ToolChain::MacroInspectionReport report = runner(flags); ToolChain::MacroInspectionReport report = runner(flags);
report.languageVersion = Utils::LanguageVersion::LatestCxx; report.languageVersion = LanguageVersion::LatestCxx;
return report; return report;
}; };
tcInfo.macroInspectionRunner = macroInspectionWrapper; tcInfo.macroInspectionRunner = macroInspectionWrapper;
@@ -1941,7 +1936,7 @@ void CppModelManager::GC()
filesInEditorSupports << abstractEditorSupport->filePath(); filesInEditorSupports << abstractEditorSupport->filePath();
Snapshot currentSnapshot = snapshot(); Snapshot currentSnapshot = snapshot();
QSet<Utils::FilePath> reachableFiles; QSet<FilePath> reachableFiles;
// The configuration file is part of the project files, which is just fine. // The configuration file is part of the project files, which is just fine.
// If single files are open, without any project, then there is no need to // If single files are open, without any project, then there is no need to
// keep the configuration file around. // keep the configuration file around.
@@ -1964,7 +1959,7 @@ void CppModelManager::GC()
QStringList notReachableFiles; QStringList notReachableFiles;
Snapshot newSnapshot; Snapshot newSnapshot;
for (Snapshot::const_iterator it = currentSnapshot.begin(); it != currentSnapshot.end(); ++it) { for (Snapshot::const_iterator it = currentSnapshot.begin(); it != currentSnapshot.end(); ++it) {
const Utils::FilePath &fileName = it.key(); const FilePath &fileName = it.key();
if (reachableFiles.contains(fileName)) if (reachableFiles.contains(fileName))
newSnapshot.insert(it.value()); newSnapshot.insert(it.value());
@@ -2001,7 +1996,7 @@ TextEditor::BaseHoverHandler *CppModelManager::createHoverHandler() const
} }
void CppModelManager::followSymbol(const CursorInEditor &data, void CppModelManager::followSymbol(const CursorInEditor &data,
const Utils::LinkHandler &processLinkCallback, const LinkHandler &processLinkCallback,
bool resolveTarget, bool inNextSplit, Backend backend) bool resolveTarget, bool inNextSplit, Backend backend)
{ {
instance()->modelManagerSupport(backend)->followSymbol(data, processLinkCallback, instance()->modelManagerSupport(backend)->followSymbol(data, processLinkCallback,
@@ -2009,7 +2004,7 @@ void CppModelManager::followSymbol(const CursorInEditor &data,
} }
void CppModelManager::followSymbolToType(const CursorInEditor &data, void CppModelManager::followSymbolToType(const CursorInEditor &data,
const Utils::LinkHandler &processLinkCallback, const LinkHandler &processLinkCallback,
bool inNextSplit, Backend backend) bool inNextSplit, Backend backend)
{ {
instance()->modelManagerSupport(backend)->followSymbolToType(data, processLinkCallback, instance()->modelManagerSupport(backend)->followSymbolToType(data, processLinkCallback,
@@ -2017,13 +2012,13 @@ void CppModelManager::followSymbolToType(const CursorInEditor &data,
} }
void CppModelManager::switchDeclDef(const CursorInEditor &data, void CppModelManager::switchDeclDef(const CursorInEditor &data,
const Utils::LinkHandler &processLinkCallback, const LinkHandler &processLinkCallback,
Backend backend) Backend backend)
{ {
instance()->modelManagerSupport(backend)->switchDeclDef(data, processLinkCallback); instance()->modelManagerSupport(backend)->switchDeclDef(data, processLinkCallback);
} }
Core::ILocatorFilter *CppModelManager::createAuxiliaryCurrentDocumentFilter() ILocatorFilter *CppModelManager::createAuxiliaryCurrentDocumentFilter()
{ {
const auto filter = new Internal::CppCurrentDocumentFilter(instance()); const auto filter = new Internal::CppCurrentDocumentFilter(instance());
filter->makeAuxiliary(); filter->makeAuxiliary();
@@ -2049,7 +2044,7 @@ FilePaths CppModelManager::projectFiles()
return d->m_projectFiles; return d->m_projectFiles;
} }
ProjectExplorer::HeaderPaths CppModelManager::headerPaths() HeaderPaths CppModelManager::headerPaths()
{ {
QWriteLocker locker(&d->m_projectLock); QWriteLocker locker(&d->m_projectLock);
ensureUpdated(); ensureUpdated();
@@ -2057,13 +2052,13 @@ ProjectExplorer::HeaderPaths CppModelManager::headerPaths()
return d->m_headerPaths; return d->m_headerPaths;
} }
void CppModelManager::setHeaderPaths(const ProjectExplorer::HeaderPaths &headerPaths) void CppModelManager::setHeaderPaths(const HeaderPaths &headerPaths)
{ {
QWriteLocker locker(&d->m_projectLock); QWriteLocker locker(&d->m_projectLock);
d->m_headerPaths = headerPaths; d->m_headerPaths = headerPaths;
} }
ProjectExplorer::Macros CppModelManager::definedMacros() Macros CppModelManager::definedMacros()
{ {
QWriteLocker locker(&d->m_projectLock); QWriteLocker locker(&d->m_projectLock);
ensureUpdated(); ensureUpdated();

View File

@@ -23,6 +23,7 @@
#include <QFutureWatcher> #include <QFutureWatcher>
#include <QRegularExpression> #include <QRegularExpression>
using namespace Core;
using namespace LanguageServerProtocol; using namespace LanguageServerProtocol;
namespace LanguageClient { namespace LanguageClient {
@@ -36,7 +37,7 @@ DocumentLocatorFilter::DocumentLocatorFilter()
setDefaultShortcutString("."); setDefaultShortcutString(".");
setDefaultIncludedByDefault(false); setDefaultIncludedByDefault(false);
setPriority(ILocatorFilter::Low); setPriority(ILocatorFilter::Low);
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged, connect(EditorManager::instance(), &EditorManager::currentEditorChanged,
this, &DocumentLocatorFilter::updateCurrentClient); this, &DocumentLocatorFilter::updateCurrentClient);
} }
@@ -56,7 +57,7 @@ void DocumentLocatorFilter::updateCurrentClient()
m_updateSymbolsConnection = connect(m_symbolCache, &DocumentSymbolCache::gotSymbols, m_updateSymbolsConnection = connect(m_symbolCache, &DocumentSymbolCache::gotSymbols,
this, &DocumentLocatorFilter::updateSymbols); this, &DocumentLocatorFilter::updateSymbols);
} }
m_resetSymbolsConnection = connect(document, &Core::IDocument::contentsChanged, m_resetSymbolsConnection = connect(document, &IDocument::contentsChanged,
this, &DocumentLocatorFilter::resetSymbols); this, &DocumentLocatorFilter::resetSymbols);
m_currentUri = client->hostPathToServerUri(document->filePath()); m_currentUri = client->hostPathToServerUri(document->filePath());
m_pathMapper = client->hostPathMapper(); m_pathMapper = client->hostPathMapper();
@@ -85,11 +86,11 @@ void DocumentLocatorFilter::resetSymbols()
m_currentSymbols.reset(); m_currentSymbols.reset();
} }
static Core::LocatorFilterEntry generateLocatorEntry(const SymbolInformation &info, static LocatorFilterEntry generateLocatorEntry(const SymbolInformation &info,
Core::ILocatorFilter *filter, ILocatorFilter *filter,
DocumentUri::PathMapper pathMapper) DocumentUri::PathMapper pathMapper)
{ {
Core::LocatorFilterEntry entry; LocatorFilterEntry entry;
entry.filter = filter; entry.filter = filter;
entry.displayName = info.name(); entry.displayName = info.name();
if (std::optional<QString> container = info.containerName()) if (std::optional<QString> container = info.containerName())
@@ -99,15 +100,15 @@ static Core::LocatorFilterEntry generateLocatorEntry(const SymbolInformation &in
return entry; return entry;
} }
Core::LocatorFilterEntry DocumentLocatorFilter::generateLocatorEntry(const SymbolInformation &info) LocatorFilterEntry DocumentLocatorFilter::generateLocatorEntry(const SymbolInformation &info)
{ {
QTC_ASSERT(m_pathMapper, return {}); QTC_ASSERT(m_pathMapper, return {});
return LanguageClient::generateLocatorEntry(info, this, m_pathMapper); return LanguageClient::generateLocatorEntry(info, this, m_pathMapper);
} }
QList<Core::LocatorFilterEntry> DocumentLocatorFilter::generateLocatorEntries( QList<LocatorFilterEntry> DocumentLocatorFilter::generateLocatorEntries(
const SymbolInformation &info, const QRegularExpression &regexp, const SymbolInformation &info, const QRegularExpression &regexp,
const Core::LocatorFilterEntry &parent) const LocatorFilterEntry &parent)
{ {
Q_UNUSED(parent) Q_UNUSED(parent)
if (regexp.match(info.name()).hasMatch()) if (regexp.match(info.name()).hasMatch())
@@ -115,12 +116,11 @@ QList<Core::LocatorFilterEntry> DocumentLocatorFilter::generateLocatorEntries(
return {}; return {};
} }
Core::LocatorFilterEntry DocumentLocatorFilter::generateLocatorEntry( LocatorFilterEntry DocumentLocatorFilter::generateLocatorEntry(const DocumentSymbol &info,
const DocumentSymbol &info, const LocatorFilterEntry &parent)
const Core::LocatorFilterEntry &parent)
{ {
Q_UNUSED(parent) Q_UNUSED(parent)
Core::LocatorFilterEntry entry; LocatorFilterEntry entry;
entry.filter = this; entry.filter = this;
entry.displayName = info.name(); entry.displayName = info.name();
if (std::optional<QString> detail = info.detail()) if (std::optional<QString> detail = info.detail())
@@ -131,14 +131,14 @@ Core::LocatorFilterEntry DocumentLocatorFilter::generateLocatorEntry(
return entry; return entry;
} }
QList<Core::LocatorFilterEntry> DocumentLocatorFilter::generateLocatorEntries( QList<LocatorFilterEntry> DocumentLocatorFilter::generateLocatorEntries(
const DocumentSymbol &info, const QRegularExpression &regexp, const DocumentSymbol &info, const QRegularExpression &regexp,
const Core::LocatorFilterEntry &parent) const LocatorFilterEntry &parent)
{ {
QList<Core::LocatorFilterEntry> entries; QList<LocatorFilterEntry> entries;
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();
Core::LocatorFilterEntry entry; LocatorFilterEntry entry;
if (hasMatch || !children.isEmpty()) if (hasMatch || !children.isEmpty())
entry = generateLocatorEntry(info, parent); entry = generateLocatorEntry(info, parent);
if (hasMatch) if (hasMatch)
@@ -149,10 +149,10 @@ QList<Core::LocatorFilterEntry> DocumentLocatorFilter::generateLocatorEntries(
} }
template<class T> template<class T>
QList<Core::LocatorFilterEntry> DocumentLocatorFilter::generateEntries(const QList<T> &list, QList<LocatorFilterEntry> DocumentLocatorFilter::generateEntries(const QList<T> &list,
const QString &filter) const QString &filter)
{ {
QList<Core::LocatorFilterEntry> entries; QList<LocatorFilterEntry> entries;
FuzzyMatcher::CaseSensitivity caseSensitivity FuzzyMatcher::CaseSensitivity caseSensitivity
= ILocatorFilter::caseSensitivity(filter) == Qt::CaseSensitive = ILocatorFilter::caseSensitivity(filter) == Qt::CaseSensitive
? FuzzyMatcher::CaseSensitivity::CaseSensitive ? FuzzyMatcher::CaseSensitivity::CaseSensitive
@@ -175,20 +175,17 @@ void DocumentLocatorFilter::prepareSearch(const QString &/*entry*/)
} }
} }
QList<Core::LocatorFilterEntry> DocumentLocatorFilter::matchesFor( QList<LocatorFilterEntry> DocumentLocatorFilter::matchesFor(
QFutureInterface<Core::LocatorFilterEntry> &future, const QString &entry) QFutureInterface<LocatorFilterEntry> &future, const QString &entry)
{ {
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
if (!m_symbolCache) if (!m_symbolCache)
return {}; return {};
if (!m_currentSymbols.has_value()) { if (!m_currentSymbols.has_value()) {
QEventLoop loop; QEventLoop loop;
connect(this, &DocumentLocatorFilter::symbolsUpToDate, &loop, [&]() { loop.exit(1); }); connect(this, &DocumentLocatorFilter::symbolsUpToDate, &loop, [&] { loop.exit(1); });
QFutureWatcher<Core::LocatorFilterEntry> watcher; QFutureWatcher<LocatorFilterEntry> watcher;
connect(&watcher, connect(&watcher, &QFutureWatcher<LocatorFilterEntry>::canceled, &loop, &QEventLoop::quit);
&QFutureWatcher<Core::LocatorFilterEntry>::canceled,
&loop,
&QEventLoop::quit);
watcher.setFuture(future.future()); watcher.setFuture(future.future());
locker.unlock(); locker.unlock();
if (!loop.exec()) if (!loop.exec())
@@ -206,7 +203,7 @@ QList<Core::LocatorFilterEntry> DocumentLocatorFilter::matchesFor(
return {}; return {};
} }
void DocumentLocatorFilter::accept(const Core::LocatorFilterEntry &selection, void DocumentLocatorFilter::accept(const LocatorFilterEntry &selection,
QString * /*newText*/, QString * /*newText*/,
int * /*selectionStart*/, int * /*selectionStart*/,
int * /*selectionLength*/) const int * /*selectionLength*/) const
@@ -217,11 +214,10 @@ void DocumentLocatorFilter::accept(const Core::LocatorFilterEntry &selection,
const Utils::Link link(m_currentUri.toFilePath(m_pathMapper), const Utils::Link link(m_currentUri.toFilePath(m_pathMapper),
lineColumn.line + 1, lineColumn.line + 1,
lineColumn.column); lineColumn.column);
Core::EditorManager::openEditorAt(link, {}, Core::EditorManager::AllowExternalEditor); EditorManager::openEditorAt(link, {}, EditorManager::AllowExternalEditor);
} else if (selection.internalData.canConvert<Utils::Link>()) { } else if (selection.internalData.canConvert<Utils::Link>()) {
Core::EditorManager::openEditorAt(qvariant_cast<Utils::Link>(selection.internalData), EditorManager::openEditorAt(qvariant_cast<Utils::Link>(selection.internalData), {},
{}, EditorManager::AllowExternalEditor);
Core::EditorManager::AllowExternalEditor);
} }
} }
@@ -283,16 +279,16 @@ void WorkspaceLocatorFilter::prepareSearch(const QString &entry,
} }
} }
QList<Core::LocatorFilterEntry> WorkspaceLocatorFilter::matchesFor( QList<LocatorFilterEntry> WorkspaceLocatorFilter::matchesFor(
QFutureInterface<Core::LocatorFilterEntry> &future, const QString & /*entry*/) QFutureInterface<LocatorFilterEntry> &future, const QString & /*entry*/)
{ {
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
if (!m_pendingRequests.isEmpty()) { if (!m_pendingRequests.isEmpty()) {
QEventLoop loop; QEventLoop loop;
connect(this, &WorkspaceLocatorFilter::allRequestsFinished, &loop, [&]() { loop.exit(1); }); connect(this, &WorkspaceLocatorFilter::allRequestsFinished, &loop, [&] { loop.exit(1); });
QFutureWatcher<Core::LocatorFilterEntry> watcher; QFutureWatcher<LocatorFilterEntry> watcher;
connect(&watcher, connect(&watcher,
&QFutureWatcher<Core::LocatorFilterEntry>::canceled, &QFutureWatcher<LocatorFilterEntry>::canceled,
&loop, &loop,
&QEventLoop::quit); &QEventLoop::quit);
watcher.setFuture(future.future()); watcher.setFuture(future.future());
@@ -315,15 +311,15 @@ QList<Core::LocatorFilterEntry> WorkspaceLocatorFilter::matchesFor(
return Utils::transform(m_results, generateEntry).toList(); return Utils::transform(m_results, generateEntry).toList();
} }
void WorkspaceLocatorFilter::accept(const Core::LocatorFilterEntry &selection, void WorkspaceLocatorFilter::accept(const LocatorFilterEntry &selection,
QString * /*newText*/, QString * /*newText*/,
int * /*selectionStart*/, int * /*selectionStart*/,
int * /*selectionLength*/) const int * /*selectionLength*/) const
{ {
if (selection.internalData.canConvert<Utils::Link>()) if (selection.internalData.canConvert<Utils::Link>()) {
Core::EditorManager::openEditorAt(qvariant_cast<Utils::Link>(selection.internalData), EditorManager::openEditorAt(qvariant_cast<Utils::Link>(selection.internalData), {},
{}, EditorManager::AllowExternalEditor);
Core::EditorManager::AllowExternalEditor); }
} }
void WorkspaceLocatorFilter::handleResponse(Client *client, void WorkspaceLocatorFilter::handleResponse(Client *client,

View File

@@ -33,6 +33,8 @@
#include <QMenu> #include <QMenu>
using namespace Core;
namespace ModelEditor { namespace ModelEditor {
namespace Internal { namespace Internal {
@@ -87,15 +89,14 @@ bool ElementTasks::hasClassDefinition(const qmt::MElement *element) const
? klass->name() ? klass->name()
: klass->umlNamespace() + "::" + klass->name(); : klass->umlNamespace() + "::" + klass->name();
Core::ILocatorFilter *classesFilter ILocatorFilter *classesFilter = CppEditor::CppModelManager::instance()->classesFilter();
= CppEditor::CppModelManager::instance()->classesFilter();
if (!classesFilter) if (!classesFilter)
return false; return false;
QFutureInterface<Core::LocatorFilterEntry> dummyInterface; QFutureInterface<LocatorFilterEntry> dummyInterface;
const QList<Core::LocatorFilterEntry> matches const QList<LocatorFilterEntry> matches
= classesFilter->matchesFor(dummyInterface, qualifiedClassName); = classesFilter->matchesFor(dummyInterface, qualifiedClassName);
for (const Core::LocatorFilterEntry &entry : matches) { for (const LocatorFilterEntry &entry : matches) {
CppEditor::IndexItem::Ptr info = qvariant_cast<CppEditor::IndexItem::Ptr>(entry.internalData); CppEditor::IndexItem::Ptr info = qvariant_cast<CppEditor::IndexItem::Ptr>(entry.internalData);
if (info->scopedSymbolName() != qualifiedClassName) if (info->scopedSymbolName() != qualifiedClassName)
continue; continue;
@@ -124,19 +125,18 @@ void ElementTasks::openClassDefinition(const qmt::MElement *element)
? klass->name() ? klass->name()
: klass->umlNamespace() + "::" + klass->name(); : klass->umlNamespace() + "::" + klass->name();
Core::ILocatorFilter *classesFilter ILocatorFilter *classesFilter = CppEditor::CppModelManager::instance()->classesFilter();
= CppEditor::CppModelManager::instance()->classesFilter();
if (!classesFilter) if (!classesFilter)
return; return;
QFutureInterface<Core::LocatorFilterEntry> dummyInterface; QFutureInterface<LocatorFilterEntry> dummyInterface;
const QList<Core::LocatorFilterEntry> matches const QList<LocatorFilterEntry> matches
= classesFilter->matchesFor(dummyInterface, qualifiedClassName); = classesFilter->matchesFor(dummyInterface, qualifiedClassName);
for (const Core::LocatorFilterEntry &entry : matches) { for (const LocatorFilterEntry &entry : matches) {
CppEditor::IndexItem::Ptr info = qvariant_cast<CppEditor::IndexItem::Ptr>(entry.internalData); CppEditor::IndexItem::Ptr info = qvariant_cast<CppEditor::IndexItem::Ptr>(entry.internalData);
if (info->scopedSymbolName() != qualifiedClassName) if (info->scopedSymbolName() != qualifiedClassName)
continue; continue;
if (Core::EditorManager::instance()->openEditorAt( if (EditorManager::instance()->openEditorAt(
{info->filePath(), info->line(), info->column()})) { {info->filePath(), info->line(), info->column()})) {
return; return;
} }

View File

@@ -12,12 +12,13 @@
#include <numeric> #include <numeric>
using namespace Core;
using namespace QmlJSTools::Internal; using namespace QmlJSTools::Internal;
Q_DECLARE_METATYPE(LocatorData::Entry) Q_DECLARE_METATYPE(LocatorData::Entry)
FunctionFilter::FunctionFilter(LocatorData *data, QObject *parent) FunctionFilter::FunctionFilter(LocatorData *data, QObject *parent)
: Core::ILocatorFilter(parent) : ILocatorFilter(parent)
, m_data(data) , m_data(data)
{ {
setId("Functions"); setId("Functions");
@@ -28,11 +29,10 @@ FunctionFilter::FunctionFilter(LocatorData *data, QObject *parent)
FunctionFilter::~FunctionFilter() = default; FunctionFilter::~FunctionFilter() = default;
QList<Core::LocatorFilterEntry> FunctionFilter::matchesFor( QList<LocatorFilterEntry> FunctionFilter::matchesFor(QFutureInterface<LocatorFilterEntry> &future,
QFutureInterface<Core::LocatorFilterEntry> &future,
const QString &entry) const QString &entry)
{ {
QList<Core::LocatorFilterEntry> entries[int(MatchLevel::Count)]; QList<LocatorFilterEntry> entries[int(MatchLevel::Count)];
const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry); const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry);
const QRegularExpression regexp = createRegExp(entry); const QRegularExpression regexp = createRegExp(entry);
@@ -51,7 +51,7 @@ QList<Core::LocatorFilterEntry> FunctionFilter::matchesFor(
const QRegularExpressionMatch match = regexp.match(info.symbolName); const QRegularExpressionMatch match = regexp.match(info.symbolName);
if (match.hasMatch()) { if (match.hasMatch()) {
QVariant id = QVariant::fromValue(info); QVariant id = QVariant::fromValue(info);
Core::LocatorFilterEntry filterEntry(this, info.displayName, id/*, info.icon*/); LocatorFilterEntry filterEntry(this, info.displayName, id/*, info.icon*/);
filterEntry.extraInfo = info.extraInfo; filterEntry.extraInfo = info.extraInfo;
filterEntry.highlightInfo = highlightInfo(match); filterEntry.highlightInfo = highlightInfo(match);
@@ -67,18 +67,17 @@ QList<Core::LocatorFilterEntry> FunctionFilter::matchesFor(
for (auto &entry : entries) { for (auto &entry : entries) {
if (entry.size() < 1000) if (entry.size() < 1000)
Utils::sort(entry, Core::LocatorFilterEntry::compareLexigraphically); Utils::sort(entry, LocatorFilterEntry::compareLexigraphically);
}
return std::accumulate(std::begin(entries), std::end(entries), QList<LocatorFilterEntry>());
} }
return std::accumulate(std::begin(entries), std::end(entries), QList<Core::LocatorFilterEntry>()); void FunctionFilter::accept(const LocatorFilterEntry &selection,
}
void FunctionFilter::accept(const Core::LocatorFilterEntry &selection,
QString *newText, int *selectionStart, int *selectionLength) const QString *newText, int *selectionStart, int *selectionLength) const
{ {
Q_UNUSED(newText) Q_UNUSED(newText)
Q_UNUSED(selectionStart) Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength) Q_UNUSED(selectionLength)
const LocatorData::Entry entry = qvariant_cast<LocatorData::Entry>(selection.internalData); const LocatorData::Entry entry = qvariant_cast<LocatorData::Entry>(selection.internalData);
Core::EditorManager::openEditorAt({entry.fileName, entry.line, entry.column}); EditorManager::openEditorAt({entry.fileName, entry.line, entry.column});
} }