From c21774f0a7754d97a7abe8731f185683fa66df35 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 27 Apr 2022 17:59:26 +0200 Subject: [PATCH] ClangCodeModel: Remove libclang-based locator filter Change-Id: I1c588a7bfdee773662d1956e9a998040794b8c9d Reviewed-by: David Schulz --- src/plugins/clangcodemodel/CMakeLists.txt | 1 - src/plugins/clangcodemodel/clangcodemodel.qbs | 2 - .../clangcurrentdocumentfilter.cpp | 177 ------------------ .../clangcurrentdocumentfilter.h | 60 ------ .../clangcodemodel/clangdlocatorfilters.cpp | 21 +-- .../cppeditor/cppcurrentdocumentfilter.cpp | 9 + .../cppeditor/cppcurrentdocumentfilter.h | 2 + src/plugins/cppeditor/cppmodelmanager.cpp | 7 + src/plugins/cppeditor/cppmodelmanager.h | 1 + 9 files changed, 24 insertions(+), 256 deletions(-) delete mode 100644 src/plugins/clangcodemodel/clangcurrentdocumentfilter.cpp delete mode 100644 src/plugins/clangcodemodel/clangcurrentdocumentfilter.h diff --git a/src/plugins/clangcodemodel/CMakeLists.txt b/src/plugins/clangcodemodel/CMakeLists.txt index c040b2c4f04..ea248e7eb61 100644 --- a/src/plugins/clangcodemodel/CMakeLists.txt +++ b/src/plugins/clangcodemodel/CMakeLists.txt @@ -24,7 +24,6 @@ add_qtc_plugin(ClangCodeModel clangcompletionchunkstotextconverter.cpp clangcompletionchunkstotextconverter.h clangcompletioncontextanalyzer.cpp clangcompletioncontextanalyzer.h clangconstants.h - clangcurrentdocumentfilter.cpp clangcurrentdocumentfilter.h clangdclient.cpp clangdclient.h clangdiagnosticfilter.cpp clangdiagnosticfilter.h clangdiagnosticmanager.cpp clangdiagnosticmanager.h diff --git a/src/plugins/clangcodemodel/clangcodemodel.qbs b/src/plugins/clangcodemodel/clangcodemodel.qbs index 1f4cd572595..5ac77198c5f 100644 --- a/src/plugins/clangcodemodel/clangcodemodel.qbs +++ b/src/plugins/clangcodemodel/clangcodemodel.qbs @@ -54,8 +54,6 @@ QtcPlugin { "clangcompletioncontextanalyzer.cpp", "clangcompletioncontextanalyzer.h", "clangconstants.h", - "clangcurrentdocumentfilter.cpp", - "clangcurrentdocumentfilter.h", "clangdclient.cpp", "clangdclient.h", "clangdiagnosticfilter.cpp", diff --git a/src/plugins/clangcodemodel/clangcurrentdocumentfilter.cpp b/src/plugins/clangcodemodel/clangcurrentdocumentfilter.cpp deleted file mode 100644 index 47b4803f894..00000000000 --- a/src/plugins/clangcodemodel/clangcurrentdocumentfilter.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "clangcurrentdocumentfilter.h" - -#include "clangeditordocumentprocessor.h" -#include "clangutils.h" - -#include - -#include -#include - -#include - -#include - -#include - -#include -#include -#include -#include -#include - -#include - -using namespace Utils; - -namespace ClangCodeModel { -namespace Internal { - -ClangCurrentDocumentFilter::ClangCurrentDocumentFilter() -{ - setId(CppEditor::Constants::CURRENT_DOCUMENT_FILTER_ID); - setDisplayName(CppEditor::Constants::CURRENT_DOCUMENT_FILTER_DISPLAY_NAME); - setDefaultShortcutString("."); - setPriority(High); - setDefaultIncludedByDefault(false); - - Core::EditorManager *editorManager = Core::EditorManager::instance(); - connect(editorManager, &Core::EditorManager::currentEditorChanged, - this, &ClangCurrentDocumentFilter::onCurrentEditorChanged); - connect(editorManager, &Core::EditorManager::editorAboutToClose, - this, &ClangCurrentDocumentFilter::onEditorAboutToClose); -} - -static QString addType(const QString &signature, const ClangBackEnd::ExtraInfo &extraInfo) -{ - return signature + QLatin1String(" -> ", 4) + extraInfo.typeSpelling.toString(); -} - -static Core::LocatorFilterEntry makeEntry(Core::ILocatorFilter *filter, - const ClangBackEnd::TokenInfoContainer &info) -{ - const ClangBackEnd::ExtraInfo &extraInfo = info.extraInfo; - QString displayName = extraInfo.token; - LineColumn lineColumn(info.line, info.column); - Core::LocatorFilterEntry entry(filter, displayName, QVariant::fromValue(lineColumn)); - QString extra; - ClangBackEnd::HighlightingType mainType = info.types.mainHighlightingType; - if (mainType == ClangBackEnd::HighlightingType::VirtualFunction - || mainType == ClangBackEnd::HighlightingType::Function - || mainType == ClangBackEnd::HighlightingType::GlobalVariable - || mainType == ClangBackEnd::HighlightingType::Field - || mainType == ClangBackEnd::HighlightingType::QtProperty) { - displayName = addType(displayName, extraInfo); - extra = extraInfo.semanticParentTypeSpelling.toString(); - } else { - extra = extraInfo.typeSpelling.toString(); - } - entry.displayName = displayName; - entry.extraInfo = extra; - entry.displayIcon = CodeModelIcon::iconForType(iconTypeForToken(info)); - return entry; -} - -void ClangCurrentDocumentFilter::prepareSearch(const QString &entry) -{ - Q_UNUSED(entry) - m_preparedPath = m_currentPath; -} - -QList ClangCurrentDocumentFilter::matchesFor( - QFutureInterface &, const QString &entry) -{ - QList goodEntries; - if (m_preparedPath.isEmpty()) - return goodEntries; - - FuzzyMatcher::CaseSensitivity caseSesitivity = caseSensitivity(entry) == Qt::CaseSensitive - ? FuzzyMatcher::CaseSensitivity::CaseSensitive - : FuzzyMatcher::CaseSensitivity::CaseInsensitive; - const QRegularExpression regexp = FuzzyMatcher::createRegExp(entry, caseSesitivity); - if (!regexp.isValid()) - return goodEntries; - - ClangEditorDocumentProcessor *processor = ClangEditorDocumentProcessor::get(m_preparedPath); - if (!processor) - return goodEntries; - - using TokInfoContainer = ClangBackEnd::TokenInfoContainer; - const QVector &infos = processor->tokenInfos(); - - for (const TokInfoContainer &info : infos) { - if (!info.isGlobalDeclaration()) - continue; - QRegularExpressionMatch match = regexp.match(info.extraInfo.token); - if (match.hasMatch()) - goodEntries.push_back(makeEntry(this, info)); - } - - return goodEntries; -} - -void ClangCurrentDocumentFilter::accept(const Core::LocatorFilterEntry &selection, - QString *, int *, int *) const -{ - if (!m_currentEditor) - return; - auto lineColumn = qvariant_cast(selection.internalData); - Core::EditorManager::openEditorAt( - {FilePath::fromString(m_currentPath), lineColumn.line, lineColumn.column - 1}); -} - -void ClangCurrentDocumentFilter::reset(Core::IEditor *newCurrent, const QString &path) -{ - m_currentEditor = newCurrent; - m_currentPath = path; -} - -void ClangCurrentDocumentFilter::onEditorAboutToClose(Core::IEditor *editorAboutToClose) -{ - if (!editorAboutToClose) - return; - - if (m_currentEditor == editorAboutToClose) - reset(); -} - -void ClangCurrentDocumentFilter::onCurrentEditorChanged(Core::IEditor *newCurrent) -{ - if (newCurrent) { - Core::IDocument *document = newCurrent->document(); - QTC_ASSERT(document, reset(); return); - if (auto *textDocument = qobject_cast(document)) { - reset(newCurrent, textDocument->filePath().toString()); - return; - } - } - reset(); -} - -} // namespace Internal -} // namespace ClangCodeModel diff --git a/src/plugins/clangcodemodel/clangcurrentdocumentfilter.h b/src/plugins/clangcodemodel/clangcurrentdocumentfilter.h deleted file mode 100644 index c60d20630f8..00000000000 --- a/src/plugins/clangcodemodel/clangcurrentdocumentfilter.h +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include - -namespace Core { class IEditor; } - -namespace ClangCodeModel { -namespace Internal { - -class ClangCurrentDocumentFilter : public Core::ILocatorFilter -{ - Q_OBJECT - -public: - explicit ClangCurrentDocumentFilter(); - - void prepareSearch(const QString &entry) override; - QList matchesFor(QFutureInterface &future, - const QString &entry) override; - void accept(const Core::LocatorFilterEntry &selection, - QString *newText, int *selectionStart, int *selectionLength) const override; - -private: - void onEditorAboutToClose(Core::IEditor *editors); - void onCurrentEditorChanged(Core::IEditor *newCurrent); - - void reset(Core::IEditor *newCurrent = nullptr, const QString &path = QString()); - - Core::IEditor *m_currentEditor = nullptr; - QString m_currentPath; - QString m_preparedPath; -}; - -} // namespace Internal -} // namespace ClangCodeModel diff --git a/src/plugins/clangcodemodel/clangdlocatorfilters.cpp b/src/plugins/clangcodemodel/clangdlocatorfilters.cpp index dd15db149d2..6a8fd4f6bab 100644 --- a/src/plugins/clangcodemodel/clangdlocatorfilters.cpp +++ b/src/plugins/clangcodemodel/clangdlocatorfilters.cpp @@ -27,7 +27,6 @@ #include "clangdclient.h" #include "clangmodelmanagersupport.h" -#include "clangcurrentdocumentfilter.h" #include #include @@ -226,19 +225,6 @@ ClangFunctionsFilter::ClangFunctionsFilter() setDefaultIncludedByDefault(false); } -class CppCurrentDocumentFilter : public ClangCurrentDocumentFilter -{ -public: - CppCurrentDocumentFilter() - { - setId({}); - setDisplayName({}); - setDefaultShortcutString({}); - setEnabled(false); - setHidden(true); - } -}; - class LspCurrentDocumentFilter : public LanguageClient::DocumentLocatorFilter { public: @@ -278,7 +264,10 @@ private: class ClangdCurrentDocumentFilter::Private { public: - CppCurrentDocumentFilter cppFilter; + ~Private() { delete cppFilter; } + + Core::ILocatorFilter * const cppFilter + = CppEditor::CppModelManager::createAuxiliaryCurrentDocumentFilter(); LspCurrentDocumentFilter lspFilter; Core::ILocatorFilter *activeFilter = nullptr; }; @@ -306,7 +295,7 @@ void ClangdCurrentDocumentFilter::prepareSearch(const QString &entry) ->clientForFile(doc->filePath()); client && client->reachable()) { d->activeFilter = &d->lspFilter; } else { - d->activeFilter = &d->cppFilter; + d->activeFilter = d->cppFilter; } d->activeFilter->prepareSearch(entry); } diff --git a/src/plugins/cppeditor/cppcurrentdocumentfilter.cpp b/src/plugins/cppeditor/cppcurrentdocumentfilter.cpp index 7c83ceaec61..81b95cf424e 100644 --- a/src/plugins/cppeditor/cppcurrentdocumentfilter.cpp +++ b/src/plugins/cppeditor/cppcurrentdocumentfilter.cpp @@ -60,6 +60,15 @@ CppCurrentDocumentFilter::CppCurrentDocumentFilter(CppModelManager *manager) this, &CppCurrentDocumentFilter::onEditorAboutToClose); } +void CppCurrentDocumentFilter::makeAuxiliary() +{ + setId({}); + setDisplayName({}); + setDefaultShortcutString({}); + setEnabled(false); + setHidden(true); +} + QList CppCurrentDocumentFilter::matchesFor( QFutureInterface &future, const QString & entry) { diff --git a/src/plugins/cppeditor/cppcurrentdocumentfilter.h b/src/plugins/cppeditor/cppcurrentdocumentfilter.h index b6c715c70db..0a484dabd25 100644 --- a/src/plugins/cppeditor/cppcurrentdocumentfilter.h +++ b/src/plugins/cppeditor/cppcurrentdocumentfilter.h @@ -45,6 +45,8 @@ public: explicit CppCurrentDocumentFilter(CppModelManager *manager); ~CppCurrentDocumentFilter() override = default; + void makeAuxiliary(); + QList matchesFor(QFutureInterface &future, const QString &entry) override; void accept(const Core::LocatorFilterEntry &selection, diff --git a/src/plugins/cppeditor/cppmodelmanager.cpp b/src/plugins/cppeditor/cppmodelmanager.cpp index df53871c7bc..7a17386ba44 100644 --- a/src/plugins/cppeditor/cppmodelmanager.cpp +++ b/src/plugins/cppeditor/cppmodelmanager.cpp @@ -1680,6 +1680,13 @@ void CppModelManager::switchDeclDef(const CursorInEditor &data, d->m_activeModelManagerSupport->switchDeclDef(data, std::move(processLinkCallback)); } +Core::ILocatorFilter *CppModelManager::createAuxiliaryCurrentDocumentFilter() +{ + const auto filter = new Internal::CppCurrentDocumentFilter(instance()); + filter->makeAuxiliary(); + return filter; +} + BaseEditorDocumentProcessor *CppModelManager::createEditorDocumentProcessor( TextEditor::TextDocument *baseTextDocument) const { diff --git a/src/plugins/cppeditor/cppmodelmanager.h b/src/plugins/cppeditor/cppmodelmanager.h index 102a798b9f5..f66228cc92d 100644 --- a/src/plugins/cppeditor/cppmodelmanager.h +++ b/src/plugins/cppeditor/cppmodelmanager.h @@ -187,6 +187,7 @@ public: bool resolveTarget, bool inNextSplit); void switchDeclDef(const CursorInEditor &data, Utils::ProcessLinkCallback &&processLinkCallback); + static Core::ILocatorFilter *createAuxiliaryCurrentDocumentFilter(); std::unique_ptr createOverviewModel() const;