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

View File

@@ -17,6 +17,7 @@
#include <utils/algorithm.h>
using namespace Core;
using namespace ProjectExplorer;
using namespace Utils;
@@ -64,7 +65,7 @@ void CMakeTargetLocatorFilter::prepareSearch(const QString &entry)
extraData.insert("line", line);
extraData.insert("file", path.toString());
Core::LocatorFilterEntry filterEntry(this, target.title, extraData);
LocatorFilterEntry filterEntry(this, target.title, extraData);
filterEntry.extraInfo = path.shortNativePath();
filterEntry.highlightInfo = {index, int(entry.length())};
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(entry)
@@ -85,7 +87,8 @@ QList<Core::LocatorFilterEntry> CMakeTargetLocatorFilter::matchesFor(QFutureInte
void CMakeTargetLocatorFilter::projectListUpdated()
{
// 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);
}
void BuildCMakeTargetLocatorFilter::accept(const Core::LocatorFilterEntry &selection,
QString *newText,
int *selectionStart,
int *selectionLength) const
void BuildCMakeTargetLocatorFilter::accept(const LocatorFilterEntry &selection, QString *newText,
int *selectionStart, int *selectionLength) const
{
Q_UNUSED(newText)
Q_UNUSED(selectionStart)
@@ -151,7 +152,7 @@ OpenCMakeTargetLocatorFilter::OpenCMakeTargetLocatorFilter()
setPriority(Medium);
}
void OpenCMakeTargetLocatorFilter::accept(const Core::LocatorFilterEntry &selection,
void OpenCMakeTargetLocatorFilter::accept(const LocatorFilterEntry &selection,
QString *newText,
int *selectionStart,
int *selectionLength) const
@@ -165,11 +166,9 @@ void OpenCMakeTargetLocatorFilter::accept(const Core::LocatorFilterEntry &select
const auto file = FilePath::fromVariant(extraData.value("file"));
if (line >= 0)
Core::EditorManager::openEditorAt({file, line},
{},
Core::EditorManager::AllowExternalEditor);
EditorManager::openEditorAt({file, line}, {}, EditorManager::AllowExternalEditor);
else
Core::EditorManager::openEditor(file, {}, Core::EditorManager::AllowExternalEditor);
EditorManager::openEditor(file, {}, EditorManager::AllowExternalEditor);
}
} // CMakeProjectManager::Internal

View File

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

View File

@@ -14,6 +14,8 @@
#include <algorithm>
#include <numeric>
using namespace Core;
namespace CppEditor {
CppLocatorFilter::CppLocatorFilter(CppLocatorData *locatorData)
@@ -27,10 +29,10 @@ CppLocatorFilter::CppLocatorFilter(CppLocatorData *locatorData)
CppLocatorFilter::~CppLocatorFilter() = default;
Core::LocatorFilterEntry CppLocatorFilter::filterEntryFromIndexItem(IndexItem::Ptr info)
LocatorFilterEntry CppLocatorFilter::filterEntryFromIndexItem(IndexItem::Ptr 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)
filterEntry.extraInfo = info->shortNativeFilePath();
else
@@ -39,10 +41,10 @@ Core::LocatorFilterEntry CppLocatorFilter::filterEntryFromIndexItem(IndexItem::P
return filterEntry;
}
QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
QFutureInterface<Core::LocatorFilterEntry> &future, const QString &entry)
QList<LocatorFilterEntry> CppLocatorFilter::matchesFor(
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 IndexItem::ItemType wanted = matchTypes();
@@ -70,7 +72,7 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
}
if (match.hasMatch()) {
Core::LocatorFilterEntry filterEntry = filterEntryFromIndexItem(info);
LocatorFilterEntry filterEntry = filterEntryFromIndexItem(info);
// Highlight the matched characters, therefore it may be necessary
// 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()) {
match = regexp.match(filterEntry.extraInfo);
filterEntry.highlightInfo
= highlightInfo(match, Core::LocatorFilterEntry::HighlightInfo::ExtraInfo);
= highlightInfo(match, LocatorFilterEntry::HighlightInfo::ExtraInfo);
} else if (matchOffset > 0) {
for (int &start : filterEntry.highlightInfo.startsDisplay)
start -= matchOffset;
@@ -107,22 +109,21 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
for (auto &entry : entries) {
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
{
Q_UNUSED(newText)
Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength)
IndexItem::Ptr info = qvariant_cast<IndexItem::Ptr>(selection.internalData);
Core::EditorManager::openEditorAt({info->filePath(), info->line(), info->column()},
{},
Core::EditorManager::AllowExternalEditor);
EditorManager::openEditorAt({info->filePath(), info->line(), info->column()}, {},
EditorManager::AllowExternalEditor);
}
CppClassesFilter::CppClassesFilter(CppLocatorData *locatorData)
@@ -136,10 +137,10 @@ CppClassesFilter::CppClassesFilter(CppLocatorData *locatorData)
CppClassesFilter::~CppClassesFilter() = default;
Core::LocatorFilterEntry CppClassesFilter::filterEntryFromIndexItem(IndexItem::Ptr info)
LocatorFilterEntry CppClassesFilter::filterEntryFromIndexItem(IndexItem::Ptr 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()
? info->shortNativeFilePath()
: info->symbolScope();
@@ -158,7 +159,7 @@ CppFunctionsFilter::CppFunctionsFilter(CppLocatorData *locatorData)
CppFunctionsFilter::~CppFunctionsFilter() = default;
Core::LocatorFilterEntry CppFunctionsFilter::filterEntryFromIndexItem(IndexItem::Ptr info)
LocatorFilterEntry CppFunctionsFilter::filterEntryFromIndexItem(IndexItem::Ptr info)
{
const QVariant id = QVariant::fromValue(info);
@@ -171,7 +172,7 @@ Core::LocatorFilterEntry CppFunctionsFilter::filterEntryFromIndexItem(IndexItem:
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;
return filterEntry;

View File

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

View File

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

View File

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

View File

@@ -12,12 +12,13 @@
#include <numeric>
using namespace Core;
using namespace QmlJSTools::Internal;
Q_DECLARE_METATYPE(LocatorData::Entry)
FunctionFilter::FunctionFilter(LocatorData *data, QObject *parent)
: Core::ILocatorFilter(parent)
: ILocatorFilter(parent)
, m_data(data)
{
setId("Functions");
@@ -28,11 +29,10 @@ FunctionFilter::FunctionFilter(LocatorData *data, QObject *parent)
FunctionFilter::~FunctionFilter() = default;
QList<Core::LocatorFilterEntry> FunctionFilter::matchesFor(
QFutureInterface<Core::LocatorFilterEntry> &future,
QList<LocatorFilterEntry> FunctionFilter::matchesFor(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 QRegularExpression regexp = createRegExp(entry);
@@ -51,7 +51,7 @@ QList<Core::LocatorFilterEntry> FunctionFilter::matchesFor(
const QRegularExpressionMatch match = regexp.match(info.symbolName);
if (match.hasMatch()) {
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.highlightInfo = highlightInfo(match);
@@ -67,18 +67,17 @@ QList<Core::LocatorFilterEntry> FunctionFilter::matchesFor(
for (auto &entry : entries) {
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 Core::LocatorFilterEntry &selection,
void FunctionFilter::accept(const LocatorFilterEntry &selection,
QString *newText, int *selectionStart, int *selectionLength) const
{
Q_UNUSED(newText)
Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength)
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});
}