diff options
author | Marco Bubke <marco.bubke@qt.io> | 2018-04-09 13:30:30 +0200 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2018-04-12 13:12:24 +0000 |
commit | 4b0bcbdcb6b28e806de4ba31fa5fecd06fd9188e (patch) | |
tree | 14acb63657252b111007330cc3568ee063f3cb8e /src | |
parent | 18de1e3fcf4bc2715636c8f69b29e6177bcd552b (diff) | |
download | qt-creator-4b0bcbdcb6b28e806de4ba31fa5fecd06fd9188e.tar.gz |
Clang: Locator filter for the symbol database
There are no symbol queries for the locator filters. The signature
generation is still not implemented but for simple cases it should work.
Change-Id: Ic6b04fbe1e7e057892f194ac139615c47d6ec33f
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Diffstat (limited to 'src')
38 files changed, 266 insertions, 856 deletions
diff --git a/src/libs/clangsupport/clangsupport_global.h b/src/libs/clangsupport/clangsupport_global.h index d675d5fb11..03f4528ee9 100644 --- a/src/libs/clangsupport/clangsupport_global.h +++ b/src/libs/clangsupport/clangsupport_global.h @@ -198,6 +198,17 @@ struct HighlightingTypes { MixinHighlightingTypes mixinHighlightingTypes; }; +enum class SourceLocationKind : uchar +{ + None = 0, + Declaration, + DeclarationReference, + Definition, + MacroDefinition = 128, + MacroUsage, + MacroUndefinition +}; + enum class SymbolKind : uchar { None = 0, @@ -208,6 +219,8 @@ enum class SymbolKind : uchar Macro }; +using SymbolKinds = Utils::SizedArray<SymbolKind, 8>; + enum class SymbolTag : uchar { None = 0, diff --git a/src/libs/clangsupport/refactoringdatabaseinitializer.h b/src/libs/clangsupport/refactoringdatabaseinitializer.h index 1123c7c930..0b212c3a58 100644 --- a/src/libs/clangsupport/refactoringdatabaseinitializer.h +++ b/src/libs/clangsupport/refactoringdatabaseinitializer.h @@ -62,10 +62,11 @@ public: table.setName("symbols"); table.addColumn("symbolId", Sqlite::ColumnType::Integer, Sqlite::Contraint::PrimaryKey); const Sqlite::Column &usrColumn = table.addColumn("usr", Sqlite::ColumnType::Text); - table.addColumn("symbolName", Sqlite::ColumnType::Text); + const Sqlite::Column &symbolNameColumn = table.addColumn("symbolName", Sqlite::ColumnType::Text); const Sqlite::Column &symbolKindColumn = table.addColumn("symbolKind", Sqlite::ColumnType::Integer); + table.addColumn("signature", Sqlite::ColumnType::Text); table.addIndex({usrColumn}); - table.addIndex({symbolKindColumn}); + table.addIndex({symbolKindColumn, symbolNameColumn}); table.initialize(database); } @@ -79,7 +80,9 @@ public: const Sqlite::Column &lineColumn = table.addColumn("line", Sqlite::ColumnType::Integer); const Sqlite::Column &columnColumn = table.addColumn("column", Sqlite::ColumnType::Integer); const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer); + const Sqlite::Column &locationKindColumn = table.addColumn("locationKind", Sqlite::ColumnType::Integer); table.addUniqueIndex({sourceIdColumn, lineColumn, columnColumn}); + table.addIndex({sourceIdColumn, locationKindColumn}); table.initialize(database); } diff --git a/src/libs/utils/sizedarray.h b/src/libs/utils/sizedarray.h index 3be92560d5..af7363b4a5 100644 --- a/src/libs/utils/sizedarray.h +++ b/src/libs/utils/sizedarray.h @@ -54,6 +54,13 @@ public: using std::array<T, MaxSize>::rend; using std::array<T, MaxSize>::crend; + constexpr SizedArray() = default; + constexpr SizedArray(std::initializer_list<T> list) + : m_size(list.size()) + { + std::copy(list.begin(), list.end(), begin()); + } + constexpr size_type size() const { return m_size; diff --git a/src/plugins/clangrefactoring/clangrefactoring-source.pri b/src/plugins/clangrefactoring/clangrefactoring-source.pri index 198f736e43..b12d4a9b98 100644 --- a/src/plugins/clangrefactoring/clangrefactoring-source.pri +++ b/src/plugins/clangrefactoring/clangrefactoring-source.pri @@ -6,10 +6,6 @@ HEADERS += \ $$PWD/clangqueryhighlighter.h \ $$PWD/clangqueryhighlightmarker.h \ $$PWD/clangqueryprojectsfindfilter.h \ - $$PWD/classesfilter.h \ - $$PWD/functionsfilter.h \ - $$PWD/includesfilter.h \ - $$PWD/locatorfilter.h \ $$PWD/projectpartutilities.h \ $$PWD/refactoringclient.h \ $$PWD/refactoringconnectionclient.h \ @@ -20,24 +16,19 @@ HEADERS += \ $$PWD/symbolsfindfilter.h \ $$PWD/symbolqueryinterface.h \ $$PWD/symbol.h \ - $$PWD/class.h \ - $$PWD/enum.h \ - $$PWD/function.h \ - $$PWD/include.h \ - $$PWD/projectpartproviderinterface.h + $$PWD/projectpartproviderinterface.h \ + $$PWD/editormanagerinterface.h \ + $$PWD/locatorfilter.h SOURCES += \ $$PWD/clangqueryexamplehighlighter.cpp \ $$PWD/clangqueryhighlighter.cpp \ $$PWD/clangqueryprojectsfindfilter.cpp \ - $$PWD/classesfilter.cpp \ - $$PWD/functionsfilter.cpp \ - $$PWD/includesfilter.cpp \ - $$PWD/locatorfilter.cpp \ $$PWD/projectpartutilities.cpp \ $$PWD/refactoringclient.cpp \ $$PWD/refactoringconnectionclient.cpp \ $$PWD/refactoringengine.cpp \ $$PWD/refactoringprojectupdater.cpp \ $$PWD/searchhandle.cpp \ - $$PWD/symbolsfindfilter.cpp + $$PWD/symbolsfindfilter.cpp \ + $$PWD/locatorfilter.cpp diff --git a/src/plugins/clangrefactoring/clangrefactoring.pro b/src/plugins/clangrefactoring/clangrefactoring.pro index cad6bac979..e859631cbf 100644 --- a/src/plugins/clangrefactoring/clangrefactoring.pro +++ b/src/plugins/clangrefactoring/clangrefactoring.pro @@ -14,17 +14,14 @@ HEADERS += \ clangqueryprojectsfindfilterwidget.h \ clangquerytexteditorwidget.h \ qtcreatorclangqueryfindfilter.h \ - qtcreatorclassesfilter.h \ - qtcreatorfunctionsfilter.h \ - qtcreatorincludesfilter.h \ - qtcreatorlocatorfilter.h \ qtcreatorsearch.h \ qtcreatorsearchhandle.h \ qtcreatorsymbolsfindfilter.h \ querysqlitestatementfactory.h \ sourcelocations.h \ symbolsfindfilterconfigwidget.h \ - symbolquery.h + symbolquery.h \ + qtcreatoreditormanager.h SOURCES += \ clangrefactoringplugin.cpp \ @@ -34,14 +31,11 @@ SOURCES += \ clangqueryprojectsfindfilterwidget.cpp \ clangquerytexteditorwidget.cpp \ qtcreatorclangqueryfindfilter.cpp \ - qtcreatorclassesfilter.cpp \ - qtcreatorincludesfilter.cpp \ - qtcreatorfunctionsfilter.cpp \ - qtcreatorlocatorfilter.cpp \ qtcreatorsearch.cpp \ qtcreatorsearchhandle.cpp \ qtcreatorsymbolsfindfilter.cpp \ - symbolsfindfilterconfigwidget.cpp + symbolsfindfilterconfigwidget.cpp \ + qtcreatoreditormanager.cpp FORMS += \ clangqueryprojectsfindfilter.ui diff --git a/src/plugins/clangrefactoring/clangrefactoringplugin.cpp b/src/plugins/clangrefactoring/clangrefactoringplugin.cpp index afbc2f1a9c..93dcfa910c 100644 --- a/src/plugins/clangrefactoring/clangrefactoringplugin.cpp +++ b/src/plugins/clangrefactoring/clangrefactoringplugin.cpp @@ -24,11 +24,9 @@ ****************************************************************************/ #include "clangrefactoringplugin.h" -#include "qtcreatorclassesfilter.h" -#include "qtcreatorfunctionsfilter.h" -#include "qtcreatorincludesfilter.h" -#include "qtcreatorlocatorfilter.h" +#include "locatorfilter.h" #include "qtcreatorsymbolsfindfilter.h" +#include "qtcreatoreditormanager.h" #include "querysqlitestatementfactory.h" #include "sqlitedatabase.h" #include "sqlitereadstatement.h" @@ -41,6 +39,7 @@ #include <coreplugin/icore.h> #include <extensionsystem/pluginmanager.h> +#include <cpptools/cpptoolsconstants.h> #include <refactoringdatabaseinitializer.h> #include <filepathcaching.h> @@ -77,11 +76,11 @@ class ClangRefactoringPluginData public: using QuerySqliteReadStatementFactory = QuerySqliteStatementFactory<Sqlite::Database, Sqlite::ReadStatement>; - Sqlite::Database database{Utils::PathString{Core::ICore::userResourcePath() + "/symbol-experimental-v1.db"}, 1000ms}; ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> databaseInitializer{database}; ClangBackEnd::FilePathCaching filePathCache{database}; RefactoringClient refactoringClient; + QtCreatorEditorManager editorManager{filePathCache}; ClangBackEnd::RefactoringConnectionClient connectionClient{&refactoringClient}; QuerySqliteReadStatementFactory statementFactory{database}; SymbolQuery<QuerySqliteReadStatementFactory> symbolQuery{statementFactory}; @@ -110,7 +109,7 @@ static bool useClangFilters() bool ClangRefactoringPlugin::initialize(const QStringList & /*arguments*/, QString * /*errorMessage*/) { - d.reset(new ClangRefactoringPluginData); + d = std::make_unique<ClangRefactoringPluginData>(); d->refactoringClient.setRefactoringEngine(&d->engine); d->refactoringClient.setRefactoringConnectionClient(&d->connectionClient); @@ -175,11 +174,29 @@ void ClangRefactoringPlugin::initializeFilters() return; CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance(); - modelManager->setLocatorFilter(std::make_unique<QtcreatorLocatorFilter>(d->symbolQuery)); - modelManager->setClassesFilter(std::make_unique<QtcreatorClassesFilter>(d->symbolQuery)); - modelManager->setIncludesFilter(std::make_unique<QtcreatorIncludesFilter>(d->symbolQuery)); - modelManager->setFunctionsFilter(std::make_unique<QtcreatorFunctionsFilter>(d->symbolQuery)); - modelManager->setSymbolsFindFilter(std::make_unique<QtcreatorSymbolsFindFilter>()); + modelManager->setClassesFilter(std::make_unique<LocatorFilter>( + d->symbolQuery, + d->editorManager, + ClangBackEnd::SymbolKinds{ClangBackEnd::SymbolKind::Record}, + CppTools::Constants::CLASSES_FILTER_ID, + CppTools::Constants::CLASSES_FILTER_DISPLAY_NAME, + "c")); + modelManager->setFunctionsFilter(std::make_unique<LocatorFilter>( + d->symbolQuery, + d->editorManager, + ClangBackEnd::SymbolKinds{ClangBackEnd::SymbolKind::Function}, + CppTools::Constants::FUNCTIONS_FILTER_ID, + CppTools::Constants::FUNCTIONS_FILTER_DISPLAY_NAME, + "m")); + modelManager->setLocatorFilter(std::make_unique<LocatorFilter>( + d->symbolQuery, + d->editorManager, + ClangBackEnd::SymbolKinds{ClangBackEnd::SymbolKind::Record, + ClangBackEnd::SymbolKind::Enumeration, + ClangBackEnd::SymbolKind::Function}, + CppTools::Constants::LOCATOR_FILTER_ID, + CppTools::Constants::LOCATOR_FILTER_DISPLAY_NAME, + ":")); } } // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/classesfilter.cpp b/src/plugins/clangrefactoring/classesfilter.cpp deleted file mode 100644 index fb8a229afb..0000000000 --- a/src/plugins/clangrefactoring/classesfilter.cpp +++ /dev/null @@ -1,66 +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 "classesfilter.h" - -#include <cpptools/cpptoolsconstants.h> - -#include <utils/algorithm.h> - -namespace ClangRefactoring { - -ClassesFilter::ClassesFilter(SymbolQueryInterface &symbolQuery) - : m_symbolQuery(symbolQuery) -{ - setId(CppTools::Constants::CLASSES_FILTER_ID); - setDisplayName(CppTools::Constants::CLASSES_FILTER_DISPLAY_NAME); - setShortcutString(QLatin1String("c")); - setIncludedByDefault(false); -} - -QList<Core::LocatorFilterEntry> ClassesFilter::matchesFor( - QFutureInterface<Core::LocatorFilterEntry> &, const QString &entry) -{ - using EntryList = QList<Core::LocatorFilterEntry>; - const SymbolString entryString(entry); - const Classes classes = m_symbolQuery.symbolsContaining(SymbolType::Class, entryString); - return Utils::transform<EntryList>(classes, [this](const Class &classInfo) { - Core::LocatorFilterEntry entry{this, - classInfo.name.toQString(), - qVariantFromValue(classInfo)}; - entry.extraInfo = classInfo.path.path().toQString(); - return entry; - }); -} - -void ClassesFilter::accept(Core::LocatorFilterEntry, QString *, int *, int *) const -{ -} - -void ClassesFilter::refresh(QFutureInterface<void> &) -{ -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/classesfilter.h b/src/plugins/clangrefactoring/classesfilter.h deleted file mode 100644 index 00f827dff8..0000000000 --- a/src/plugins/clangrefactoring/classesfilter.h +++ /dev/null @@ -1,49 +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. -** -****************************************************************************/ - -#pragma once - -#include "symbolqueryinterface.h" - -#include <coreplugin/locator/ilocatorfilter.h> - -namespace ClangRefactoring { - -class ClassesFilter : public Core::ILocatorFilter -{ - Q_OBJECT -public: - ClassesFilter(SymbolQueryInterface &symbolQuery); - - QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future, - const QString &entry) override; - void accept(Core::LocatorFilterEntry selection, - QString *newText, int *selectionStart, int *selectionLength) const override; - void refresh(QFutureInterface<void> &future) override; -private: - SymbolQueryInterface &m_symbolQuery; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/class.h b/src/plugins/clangrefactoring/editormanagerinterface.h index 4775c8c8ff..fbb196460e 100644 --- a/src/plugins/clangrefactoring/class.h +++ b/src/plugins/clangrefactoring/editormanagerinterface.h @@ -25,9 +25,29 @@ #pragma once -#include "symbol.h" +#include <filepathid.h> + +#include <utils/linecolumn.h> +#include <utils/smallstringfwd.h> + +namespace Core { +class IEditor; +} namespace ClangRefactoring { -using Class = Symbol; -using Classes = std::vector<Class>; + +class EditorManagerInterface +{ +public: + EditorManagerInterface() = default; + EditorManagerInterface(const EditorManagerInterface&) = delete; + EditorManagerInterface &operator=(const EditorManagerInterface&) = delete; + EditorManagerInterface(EditorManagerInterface&&) = delete; + EditorManagerInterface &operator=(EditorManagerInterface&&) = delete; + + virtual Core::IEditor *openEditorAt(ClangBackEnd::FilePathId filePathId, Utils::LineColumn lineColumn) = 0; + +protected: + ~EditorManagerInterface() = default; +}; } // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/enum.h b/src/plugins/clangrefactoring/enum.h deleted file mode 100644 index 44de3c0b8c..0000000000 --- a/src/plugins/clangrefactoring/enum.h +++ /dev/null @@ -1,33 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 "class.h" - -namespace ClangRefactoring { -using Enum = Class; -using Enums = std::vector<Enum>; -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/functionsfilter.cpp b/src/plugins/clangrefactoring/functionsfilter.cpp deleted file mode 100644 index 4383b0eff0..0000000000 --- a/src/plugins/clangrefactoring/functionsfilter.cpp +++ /dev/null @@ -1,66 +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 "functionsfilter.h" - -#include <cpptools/cpptoolsconstants.h> - -#include <utils/algorithm.h> - -namespace ClangRefactoring { - -FunctionsFilter::FunctionsFilter(SymbolQueryInterface &symbolQuery) - : m_symbolQuery(symbolQuery) -{ - setId(CppTools::Constants::FUNCTIONS_FILTER_ID); - setDisplayName(CppTools::Constants::FUNCTIONS_FILTER_DISPLAY_NAME); - setShortcutString(QString(QLatin1Char('m'))); - setIncludedByDefault(false); -} - -QList<Core::LocatorFilterEntry> FunctionsFilter::matchesFor( - QFutureInterface<Core::LocatorFilterEntry> &, const QString &entry) -{ - using EntryList = QList<Core::LocatorFilterEntry>; - const SymbolString entryString(entry); - const Functions functions = m_symbolQuery.functionsContaining(entryString); - return Utils::transform<EntryList>(functions, [this](const Function &function) { - const auto data = qVariantFromValue(static_cast<const Symbol &>(function)); - Core::LocatorFilterEntry entry{this, function.name.toQString(), data}; - entry.extraInfo = function.path.path().toQString(); - return entry; - }); -} - -void FunctionsFilter::accept(Core::LocatorFilterEntry, QString *, int *, int *) const -{ -} - -void FunctionsFilter::refresh(QFutureInterface<void> &) -{ -} - - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/functionsfilter.h b/src/plugins/clangrefactoring/functionsfilter.h deleted file mode 100644 index 6844350e2c..0000000000 --- a/src/plugins/clangrefactoring/functionsfilter.h +++ /dev/null @@ -1,49 +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. -** -****************************************************************************/ - -#pragma once - -#include "symbolqueryinterface.h" - -#include <coreplugin/locator/ilocatorfilter.h> - -namespace ClangRefactoring { - -class FunctionsFilter : public Core::ILocatorFilter -{ - Q_OBJECT -public: - FunctionsFilter(SymbolQueryInterface &symbolQuery); - - QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future, - const QString &entry) override; - void accept(Core::LocatorFilterEntry selection, - QString *newText, int *selectionStart, int *selectionLength) const override; - void refresh(QFutureInterface<void> &future) override; -private: - SymbolQueryInterface &m_symbolQuery; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/include.h b/src/plugins/clangrefactoring/include.h deleted file mode 100644 index 6f6bc9ebe4..0000000000 --- a/src/plugins/clangrefactoring/include.h +++ /dev/null @@ -1,33 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 "symbol.h" - -namespace ClangRefactoring { -using Include = Symbol; -using Includes = std::vector<Include>; -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/includesfilter.cpp b/src/plugins/clangrefactoring/includesfilter.cpp deleted file mode 100644 index f7a586b312..0000000000 --- a/src/plugins/clangrefactoring/includesfilter.cpp +++ /dev/null @@ -1,67 +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 "includesfilter.h" - -#include <cpptools/cpptoolsconstants.h> - -#include <utils/algorithm.h> - -namespace ClangRefactoring { - -IncludesFilter::IncludesFilter(SymbolQueryInterface &symbolQuery) - : m_symbolQuery(symbolQuery) -{ - setId(CppTools::Constants::INCLUDES_FILTER_ID); - setDisplayName(CppTools::Constants::INCLUDES_FILTER_DISPLAY_NAME); - setShortcutString(QString(QLatin1Char('a'))); - setIncludedByDefault(true); - setPriority(ILocatorFilter::Low); -} - -QList<Core::LocatorFilterEntry> IncludesFilter::matchesFor( - QFutureInterface<Core::LocatorFilterEntry> &, const QString &entry) -{ - using EntryList = QList<Core::LocatorFilterEntry>; - const SymbolString entryString(entry); - const Includes includes = m_symbolQuery.symbolsContaining(SymbolType::Include, entryString); - return Utils::transform<EntryList>(includes, [this](const Include &includeInfo) { - Core::LocatorFilterEntry entry{this, - includeInfo.name.toQString(), - qVariantFromValue(includeInfo)}; - entry.extraInfo = includeInfo.path.path().toQString(); - return entry; - }); -} - -void IncludesFilter::accept(Core::LocatorFilterEntry, QString *, int *, int *) const -{ -} - -void IncludesFilter::refresh(QFutureInterface<void> &) -{ -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/includesfilter.h b/src/plugins/clangrefactoring/includesfilter.h deleted file mode 100644 index e28608dc4f..0000000000 --- a/src/plugins/clangrefactoring/includesfilter.h +++ /dev/null @@ -1,49 +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. -** -****************************************************************************/ - -#pragma once - -#include "symbolqueryinterface.h" - -#include <coreplugin/locator/ilocatorfilter.h> - -namespace ClangRefactoring { - -class IncludesFilter : public Core::ILocatorFilter -{ - Q_OBJECT -public: - IncludesFilter(SymbolQueryInterface &symbolQuery); - - QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future, - const QString &entry) override; - void accept(Core::LocatorFilterEntry selection, - QString *newText, int *selectionStart, int *selectionLength) const override; - void refresh(QFutureInterface<void> &future) override; -private: - SymbolQueryInterface &m_symbolQuery; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/locatorfilter.cpp b/src/plugins/clangrefactoring/locatorfilter.cpp index be50fd008a..15ecbb73d2 100644 --- a/src/plugins/clangrefactoring/locatorfilter.cpp +++ b/src/plugins/clangrefactoring/locatorfilter.cpp @@ -31,50 +31,32 @@ namespace ClangRefactoring { -LocatorFilter::LocatorFilter(SymbolQueryInterface &symbolQuery) - : m_symbolQuery(symbolQuery) -{ - setId(CppTools::Constants::LOCATOR_FILTER_ID); - setDisplayName(CppTools::Constants::LOCATOR_FILTER_DISPLAY_NAME); - setShortcutString(QString(QLatin1Char(':'))); - setIncludedByDefault(false); -} + QList<Core::LocatorFilterEntry> LocatorFilter::matchesFor( - QFutureInterface<Core::LocatorFilterEntry> &, const QString &entry) + QFutureInterface<Core::LocatorFilterEntry> &, const QString &searchTerm) { - SymbolString entryString(entry); - const Classes classes = m_symbolQuery.symbolsContaining(SymbolType::Class, entryString); - const Enums enums = m_symbolQuery.symbolsContaining(SymbolType::Enum, entryString); - const Functions functions = m_symbolQuery.functionsContaining(entryString); - using EntryList = QList<Core::LocatorFilterEntry>; - auto classEntries = Utils::transform<EntryList>(classes, [this](const Class &classInfo) { + Utils::SmallString sqlSearchTerm{searchTerm}; + sqlSearchTerm.replace('*', '%'); + sqlSearchTerm.append("%"); + const Symbols records = m_symbolQuery.symbols(m_symbolKinds, sqlSearchTerm); + return Utils::transform<EntryList>(records, [this](const Symbol &record) { Core::LocatorFilterEntry entry{this, - classInfo.name.toQString(), - qVariantFromValue(classInfo)}; - entry.extraInfo = classInfo.path.path().toQString(); + record.name.toQString(), + QVariant::fromValue(record)}; return entry; }); - auto enumEntries = Utils::transform<EntryList>(enums, [this](const Enum &enumInfo) { - Core::LocatorFilterEntry entry{this, - enumInfo.name.toQString(), - qVariantFromValue(enumInfo)}; - entry.extraInfo = enumInfo.path.path().toQString(); - return entry; - }); - auto functionEntries = Utils::transform<EntryList>(functions, [this](const Function &function) { - const auto data = qVariantFromValue(static_cast<const Symbol &>(function)); - Core::LocatorFilterEntry entry{this, function.name.toQString(), data}; - entry.extraInfo = function.path.path().toQString(); - return entry; - }); - - return classEntries + enumEntries + functionEntries; } -void LocatorFilter::accept(Core::LocatorFilterEntry, QString *, int *, int *) const +void LocatorFilter::accept(Core::LocatorFilterEntry locatorFilterEntry, QString *, int *, int *) const { + const Symbol symbol = locatorFilterEntry.internalData.value<Symbol>(); + + const auto sourceLocation = m_symbolQuery.locationForSymbolId(symbol.symbolId, + ClangBackEnd::SourceLocationKind::Definition); + if (sourceLocation) + m_editorManager.openEditorAt(sourceLocation->filePathId, sourceLocation->lineColumn); } void LocatorFilter::refresh(QFutureInterface<void> &) diff --git a/src/plugins/clangrefactoring/locatorfilter.h b/src/plugins/clangrefactoring/locatorfilter.h index d443d2c72a..15eaf93f0e 100644 --- a/src/plugins/clangrefactoring/locatorfilter.h +++ b/src/plugins/clangrefactoring/locatorfilter.h @@ -26,6 +26,7 @@ #pragma once #include "symbolqueryinterface.h" +#include "editormanagerinterface.h" #include <coreplugin/locator/ilocatorfilter.h> @@ -35,7 +36,22 @@ class LocatorFilter : public Core::ILocatorFilter { Q_OBJECT public: - LocatorFilter(SymbolQueryInterface &symbolQuery); + LocatorFilter(SymbolQueryInterface &symbolQuery, + EditorManagerInterface &editorManager, + ClangBackEnd::SymbolKinds &&symbolKinds, + Core::Id id, + const QString &displayName, + const QString &shortCut, + bool includedByDefault=false) + : m_symbolQuery(symbolQuery), + m_editorManager(editorManager), + m_symbolKinds(std::move(symbolKinds)) + { + setId(id); + setDisplayName(displayName); + setShortcutString(shortCut); + setIncludedByDefault(includedByDefault); + } QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future, const QString &entry) override; @@ -44,6 +60,8 @@ public: void refresh(QFutureInterface<void> &future) override; private: SymbolQueryInterface &m_symbolQuery; + EditorManagerInterface &m_editorManager; + ClangBackEnd::SymbolKinds m_symbolKinds; }; } // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorclassesfilter.h b/src/plugins/clangrefactoring/qtcreatorclassesfilter.h deleted file mode 100644 index 96cac20ff2..0000000000 --- a/src/plugins/clangrefactoring/qtcreatorclassesfilter.h +++ /dev/null @@ -1,41 +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. -** -****************************************************************************/ - -#pragma once - -#include "classesfilter.h" - -namespace ClangRefactoring { - -class QtcreatorClassesFilter : public ClassesFilter -{ - Q_OBJECT -public: - QtcreatorClassesFilter(SymbolQueryInterface &symbolQuery) : ClassesFilter(symbolQuery) {} - void accept(Core::LocatorFilterEntry selection, - QString *newText, int *selectionStart, int *selectionLength) const override; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorclassesfilter.cpp b/src/plugins/clangrefactoring/qtcreatoreditormanager.cpp index 3e1c9899e4..4aef8baa5d 100644 --- a/src/plugins/clangrefactoring/qtcreatorclassesfilter.cpp +++ b/src/plugins/clangrefactoring/qtcreatoreditormanager.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2018 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of Qt Creator. @@ -23,18 +23,22 @@ ** ****************************************************************************/ -#include "qtcreatorclassesfilter.h" +#include "qtcreatoreditormanager.h" #include <coreplugin/editormanager/editormanager.h> +#include <filepathcachinginterface.h> + +#include <utils/smallstring.h> + namespace ClangRefactoring { -void QtcreatorClassesFilter::accept(Core::LocatorFilterEntry selection, - QString *, int *, int *) const +Core::IEditor *ClangRefactoring::QtCreatorEditorManager::openEditorAt(ClangBackEnd::FilePathId filePathId, + Utils::LineColumn lineColumn) { - auto info = qvariant_cast<Symbol>(selection.internalData); - Core::EditorManager::openEditorAt(info.path.path().toQString(), info.lineColumn.line, - info.lineColumn.column); + const QString filePath = m_filePathCache.filePath(filePathId).toQString(); + + return Core::EditorManager::openEditorAt(filePath, lineColumn.line, lineColumn.column - 1); } } // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/function.h b/src/plugins/clangrefactoring/qtcreatoreditormanager.h index 863ac1b352..5c09cae082 100644 --- a/src/plugins/clangrefactoring/function.h +++ b/src/plugins/clangrefactoring/qtcreatoreditormanager.h @@ -25,14 +25,25 @@ #pragma once -#include "symbol.h" +#include "editormanagerinterface.h" + +namespace ClangBackEnd { +class FilePathCachingInterface; +}; namespace ClangRefactoring { -struct Function : public Symbol + +class QtCreatorEditorManager final : public EditorManagerInterface { - SymbolString parentName; - SymbolString returnValue; - SymbolString paramsList; +public: + QtCreatorEditorManager(ClangBackEnd::FilePathCachingInterface &filePathCache) + : m_filePathCache(filePathCache) + {} + + Core::IEditor *openEditorAt(ClangBackEnd::FilePathId filePathId, Utils::LineColumn lineColumn) override; + +private: + ClangBackEnd::FilePathCachingInterface &m_filePathCache; }; -using Functions = std::vector<Function>; -} // namespace ClangRefactoring + +} diff --git a/src/plugins/clangrefactoring/qtcreatorfunctionsfilter.cpp b/src/plugins/clangrefactoring/qtcreatorfunctionsfilter.cpp deleted file mode 100644 index 6a5a7938ce..0000000000 --- a/src/plugins/clangrefactoring/qtcreatorfunctionsfilter.cpp +++ /dev/null @@ -1,40 +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 "qtcreatorfunctionsfilter.h" - -#include <coreplugin/editormanager/editormanager.h> - -namespace ClangRefactoring { - -void QtcreatorFunctionsFilter::accept(Core::LocatorFilterEntry selection, - QString *, int *, int *) const -{ - auto info = qvariant_cast<Symbol>(selection.internalData); - Core::EditorManager::openEditorAt(info.path.path().toQString(), info.lineColumn.line, - info.lineColumn.column); -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorfunctionsfilter.h b/src/plugins/clangrefactoring/qtcreatorfunctionsfilter.h deleted file mode 100644 index 8c60db81d4..0000000000 --- a/src/plugins/clangrefactoring/qtcreatorfunctionsfilter.h +++ /dev/null @@ -1,41 +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. -** -****************************************************************************/ - -#pragma once - -#include "functionsfilter.h" - -namespace ClangRefactoring { - -class QtcreatorFunctionsFilter : public FunctionsFilter -{ - Q_OBJECT -public: - QtcreatorFunctionsFilter(SymbolQueryInterface &symbolQuery) : FunctionsFilter(symbolQuery) {} - void accept(Core::LocatorFilterEntry selection, - QString *newText, int *selectionStart, int *selectionLength) const override; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorincludesfilter.cpp b/src/plugins/clangrefactoring/qtcreatorincludesfilter.cpp deleted file mode 100644 index 0acf39d02e..0000000000 --- a/src/plugins/clangrefactoring/qtcreatorincludesfilter.cpp +++ /dev/null @@ -1,38 +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 "qtcreatorincludesfilter.h" - -#include <coreplugin/editormanager/editormanager.h> - -namespace ClangRefactoring { - -void QtcreatorIncludesFilter::accept(Core::LocatorFilterEntry selection, - QString *, int *, int *) const -{ - Core::EditorManager::openEditorAt(selection.displayName, 1, 1); -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorincludesfilter.h b/src/plugins/clangrefactoring/qtcreatorincludesfilter.h deleted file mode 100644 index 3c28f0eed8..0000000000 --- a/src/plugins/clangrefactoring/qtcreatorincludesfilter.h +++ /dev/null @@ -1,41 +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. -** -****************************************************************************/ - -#pragma once - -#include "includesfilter.h" - -namespace ClangRefactoring { - -class QtcreatorIncludesFilter : public IncludesFilter -{ - Q_OBJECT -public: - QtcreatorIncludesFilter(SymbolQueryInterface &symbolQuery) : IncludesFilter(symbolQuery) {} - void accept(Core::LocatorFilterEntry selection, - QString *newText, int *selectionStart, int *selectionLength) const override; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorlocatorfilter.cpp b/src/plugins/clangrefactoring/qtcreatorlocatorfilter.cpp deleted file mode 100644 index b2cae53e8c..0000000000 --- a/src/plugins/clangrefactoring/qtcreatorlocatorfilter.cpp +++ /dev/null @@ -1,40 +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 "qtcreatorlocatorfilter.h" - -#include <coreplugin/editormanager/editormanager.h> - -namespace ClangRefactoring { - -void QtcreatorLocatorFilter::accept(Core::LocatorFilterEntry selection, - QString *, int *, int *) const -{ - auto info = qvariant_cast<Symbol>(selection.internalData); - Core::EditorManager::openEditorAt(info.path.path().toQString(), info.lineColumn.line, - info.lineColumn.column); -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorlocatorfilter.h b/src/plugins/clangrefactoring/qtcreatorlocatorfilter.h deleted file mode 100644 index 5543d997f5..0000000000 --- a/src/plugins/clangrefactoring/qtcreatorlocatorfilter.h +++ /dev/null @@ -1,41 +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. -** -****************************************************************************/ - -#pragma once - -#include "locatorfilter.h" - -namespace ClangRefactoring { - -class QtcreatorLocatorFilter : public LocatorFilter -{ - Q_OBJECT -public: - QtcreatorLocatorFilter(SymbolQueryInterface &symbolQuery) : LocatorFilter(symbolQuery) {} - void accept(Core::LocatorFilterEntry selection, - QString *newText, int *selectionStart, int *selectionLength) const override; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.cpp b/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.cpp index 9e5bd7a750..eb049d8516 100644 --- a/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.cpp +++ b/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.cpp @@ -29,11 +29,7 @@ namespace ClangRefactoring { -QtcreatorSymbolsFindFilter::QtcreatorSymbolsFindFilter() -{ -} - -QWidget *QtcreatorSymbolsFindFilter::createConfigWidget() +QWidget *QtCreatorSymbolsFindFilter::createConfigWidget() { return new SymbolsFindFilterConfigWidget(this); } diff --git a/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.h b/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.h index db9a856ffd..cd09463088 100644 --- a/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.h +++ b/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.h @@ -29,11 +29,11 @@ namespace ClangRefactoring { -class QtcreatorSymbolsFindFilter : public SymbolsFindFilter +class QtCreatorSymbolsFindFilter : public SymbolsFindFilter { Q_OBJECT public: - QtcreatorSymbolsFindFilter(); + QtCreatorSymbolsFindFilter() = default; QWidget *createConfigWidget() override; }; diff --git a/src/plugins/clangrefactoring/querysqlitestatementfactory.h b/src/plugins/clangrefactoring/querysqlitestatementfactory.h index 231287e84c..21a1f022ec 100644 --- a/src/plugins/clangrefactoring/querysqlitestatementfactory.h +++ b/src/plugins/clangrefactoring/querysqlitestatementfactory.h @@ -49,6 +49,18 @@ public: "FROM locations NATURAL JOIN sources NATURAL JOIN directories " "WHERE symbolId = (SELECT symbolId FROM locations WHERE sourceId=? AND line=? AND column=?)", database}; + ReadStatement selectSymbolsForKindAndStartsWith{ + "SELECT symbolId, symbolName, signature FROM symbols WHERE symbolKind = ? AND symbolName LIKE ?", + database}; + ReadStatement selectSymbolsForKindAndStartsWith2{ + "SELECT symbolId, symbolName, signature FROM symbols WHERE symbolKind IN (?,?) AND symbolName LIKE ?", + database}; + ReadStatement selectSymbolsForKindAndStartsWith3{ + "SELECT symbolId, symbolName, signature FROM symbols WHERE symbolKind IN (?,?,?) AND symbolName LIKE ?", + database}; + ReadStatement selectLocationOfSymbol{ + "SELECT (SELECT directoryId FROM sources WHERE sourceId = l.sourceId), sourceId, line, column FROM locations AS l WHERE symbolId = ? AND locationKind = ?", + database}; }; } // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/sourcelocations.h b/src/plugins/clangrefactoring/sourcelocations.h index fd0dcf7d7f..9766a779b5 100644 --- a/src/plugins/clangrefactoring/sourcelocations.h +++ b/src/plugins/clangrefactoring/sourcelocations.h @@ -29,6 +29,8 @@ #include <filepathid.h> +#include <utils/linecolumn.h> + #include <vector> namespace ClangRefactoring { @@ -36,24 +38,26 @@ namespace ClangRefactoring { class SourceLocation { public: + SourceLocation() = default; + SourceLocation(ClangBackEnd::FilePathId filePathId, Utils::LineColumn lineColumn) + : filePathId{filePathId}, lineColumn{lineColumn} + {} SourceLocation(ClangBackEnd::FilePathId filePathId, int line, int column) - : filePathId(filePathId), line(line), column(column) + : filePathId{filePathId}, lineColumn{line, column} {} SourceLocation(int directoryId, int sourceId, int line, int column) - : filePathId{directoryId, sourceId}, line(line), column(column) + : filePathId{directoryId, sourceId}, lineColumn{line, column} {} friend bool operator==(SourceLocation first, SourceLocation second) { return first.filePathId == second.filePathId - && first.line == second.line - && first.column == second.column; + && first.lineColumn == second.lineColumn; } public: ClangBackEnd::FilePathId filePathId; - int line; - int column; + Utils::LineColumn lineColumn; }; using SourceLocations = std::vector<SourceLocation>; diff --git a/src/plugins/clangrefactoring/symbol.h b/src/plugins/clangrefactoring/symbol.h index 4f502248fe..5c2df29272 100644 --- a/src/plugins/clangrefactoring/symbol.h +++ b/src/plugins/clangrefactoring/symbol.h @@ -31,15 +31,32 @@ namespace ClangRefactoring { -// Use proper name -using SymbolString = Utils::PathString; +using SymbolString = Utils::BasicSmallString<63>; +using SignatureString = Utils::BasicSmallString<126>; +using SymbolId = long long; struct Symbol { + Symbol() = default; + Symbol(SymbolId symbolId, Utils::SmallStringView name) + : name(name), symbolId(symbolId) + {} + Symbol(SymbolId symbolId, Utils::SmallStringView name, Utils::SmallStringView signature) + : signature(signature), name(name), symbolId(symbolId) + {} + SignatureString signature; SymbolString name; - ClangBackEnd::FilePath path; - Utils::LineColumn lineColumn; + SymbolId symbolId; + + friend + bool operator==(const Symbol &first, const Symbol &second) + { + return first.symbolId == second.symbolId + && first.name == second.name + && first.signature == second.signature; + } }; + using Symbols = std::vector<Symbol>; } // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/symbolquery.h b/src/plugins/clangrefactoring/symbolquery.h index 96e9af891f..507d032f06 100644 --- a/src/plugins/clangrefactoring/symbolquery.h +++ b/src/plugins/clangrefactoring/symbolquery.h @@ -75,19 +75,53 @@ public: utf8Column); } - Symbols symbolsContaining(SymbolType /*symbolType*/, - Utils::SmallStringView/*regularExpression*/) const override + Symbols symbolsWithOneSymbolKinds(ClangBackEnd::SymbolKind symbolKind, + Utils::SmallStringView searchTerm) const { - // TODO: implement - return Classes(); + ReadStatement &statement = m_statementFactory.selectSymbolsForKindAndStartsWith; + + return statement.template values<Symbol, 3>(100, int(symbolKind), searchTerm); + } + + Symbols symbolsWithTwoSymbolKinds(ClangBackEnd::SymbolKind symbolKind1, + ClangBackEnd::SymbolKind symbolKind2, + Utils::SmallStringView searchTerm) const + { + ReadStatement &statement = m_statementFactory.selectSymbolsForKindAndStartsWith2; + + return statement.template values<Symbol, 3>(100, int(symbolKind1), int(symbolKind2), searchTerm); + } + + Symbols symbolsWithThreeSymbolKinds(ClangBackEnd::SymbolKind symbolKind1, + ClangBackEnd::SymbolKind symbolKind2, + ClangBackEnd::SymbolKind symbolKind3, + Utils::SmallStringView searchTerm) const + { + ReadStatement &statement = m_statementFactory.selectSymbolsForKindAndStartsWith3; + + return statement.template values<Symbol, 3>(100, int(symbolKind1), int(symbolKind2), int(symbolKind3), searchTerm); } - Functions functionsContaining(Utils::SmallStringView/*regularExpression*/) const override + Symbols symbols(const ClangBackEnd::SymbolKinds &symbolKinds, + Utils::SmallStringView searchTerm) const override { - // TODO: implement - return Functions(); + switch (symbolKinds.size()) + { + case 1: return symbolsWithOneSymbolKinds(symbolKinds[0], searchTerm); + case 2: return symbolsWithTwoSymbolKinds(symbolKinds[0], symbolKinds[1], searchTerm); + case 3: return symbolsWithThreeSymbolKinds(symbolKinds[0], symbolKinds[1], symbolKinds[2], searchTerm); + } + + return Symbols(); } + Utils::optional<SourceLocation> locationForSymbolId(SymbolId symbolId, + ClangBackEnd::SourceLocationKind kind) const override + { + ReadStatement &statement = m_statementFactory.selectLocationOfSymbol; + + return statement.template value<SourceLocation, 4>(symbolId, int(kind)); + } private: StatementFactory &m_statementFactory; }; diff --git a/src/plugins/clangrefactoring/symbolqueryinterface.h b/src/plugins/clangrefactoring/symbolqueryinterface.h index 362ba5cc05..568d26568f 100644 --- a/src/plugins/clangrefactoring/symbolqueryinterface.h +++ b/src/plugins/clangrefactoring/symbolqueryinterface.h @@ -27,23 +27,12 @@ #include "sourcelocations.h" -#include "class.h" -#include "enum.h" -#include "function.h" -#include "include.h" #include "symbol.h" #include <cpptools/usages.h> namespace ClangRefactoring { -enum class SymbolType -{ - Class = 0, - Enum = 1, - Include = 2 -}; - class SymbolQueryInterface { public: @@ -57,9 +46,10 @@ public: virtual CppTools::Usages sourceUsagesAt(ClangBackEnd::FilePathId filePathId, int line, int utf8Column) const = 0; - virtual Symbols symbolsContaining(SymbolType symbolType, - Utils::SmallStringView regularExpression) const = 0; - virtual Functions functionsContaining(Utils::SmallStringView regularExpression) const = 0; + virtual Symbols symbols(const ClangBackEnd::SymbolKinds &symbolKinds, + Utils::SmallStringView searchTerm) const = 0; + virtual Utils::optional<SourceLocation> locationForSymbolId(SymbolId symbolId, + ClangBackEnd::SourceLocationKind kind) const = 0; protected: ~SymbolQueryInterface() = default; diff --git a/src/tools/clangrefactoringbackend/source/collectmacrospreprocessorcallbacks.h b/src/tools/clangrefactoringbackend/source/collectmacrospreprocessorcallbacks.h index b3f86ae539..36592ca5aa 100644 --- a/src/tools/clangrefactoringbackend/source/collectmacrospreprocessorcallbacks.h +++ b/src/tools/clangrefactoringbackend/source/collectmacrospreprocessorcallbacks.h @@ -112,7 +112,7 @@ public: addUsedMacro(macroNameToken, macroDefinition); addMacroAsSymbol(macroNameToken, firstMacroInfo(macroDefinition.getLocalDirective()), - SymbolType::MacroUsage); + SourceLocationKind::MacroUsage); } void Ifdef(clang::SourceLocation, @@ -122,7 +122,7 @@ public: addUsedMacro( macroNameToken, macroDefinition); addMacroAsSymbol(macroNameToken, firstMacroInfo(macroDefinition.getLocalDirective()), - SymbolType::MacroUsage); + SourceLocationKind::MacroUsage); } void Defined(const clang::Token ¯oNameToken, @@ -132,13 +132,13 @@ public: addUsedMacro(macroNameToken, macroDefinition); addMacroAsSymbol(macroNameToken, firstMacroInfo(macroDefinition.getLocalDirective()), - SymbolType::MacroUsage); + SourceLocationKind::MacroUsage); } void MacroDefined(const clang::Token ¯oNameToken, const clang::MacroDirective *macroDirective) override { - addMacroAsSymbol(macroNameToken, firstMacroInfo(macroDirective), SymbolType::MacroDefinition); + addMacroAsSymbol(macroNameToken, firstMacroInfo(macroDirective), SourceLocationKind::MacroDefinition); } void MacroUndefined(const clang::Token ¯oNameToken, @@ -147,7 +147,7 @@ public: { addMacroAsSymbol(macroNameToken, firstMacroInfo(macroDefinition.getLocalDirective()), - SymbolType::MacroUndefinition); + SourceLocationKind::MacroUndefinition); } void MacroExpands(const clang::Token ¯oNameToken, @@ -158,7 +158,7 @@ public: addUsedMacro(macroNameToken, macroDefinition); addMacroAsSymbol(macroNameToken, firstMacroInfo(macroDefinition.getLocalDirective()), - SymbolType::MacroUsage); + SourceLocationKind::MacroUsage); } void EndOfMainFile() override @@ -228,7 +228,7 @@ public: void addMacroAsSymbol(const clang::Token ¯oNameToken, const clang::MacroInfo *macroInfo, - SymbolType symbolType) + SourceLocationKind symbolType) { clang::SourceLocation sourceLocation = macroNameToken.getLocation(); if (macroInfo && sourceLocation.isFileID()) { diff --git a/src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp b/src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp index a1aba16555..008dd749a4 100644 --- a/src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp +++ b/src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp @@ -47,16 +47,16 @@ Utils::SmallString symbolName(const clang::NamedDecl *declaration) return declarationName.getAsString(); } -SymbolType symbolType(clang::index::SymbolRoleSet roles) +SourceLocationKind sourceLocationKind(clang::index::SymbolRoleSet roles) { if (hasSymbolRole(clang::index::SymbolRole::Reference, roles)) - return SymbolType::DeclarationReference; + return SourceLocationKind::DeclarationReference; else if (hasSymbolRole(clang::index::SymbolRole::Declaration, roles)) - return SymbolType::Declaration; + return SourceLocationKind::Declaration; else if (hasSymbolRole(clang::index::SymbolRole::Definition, roles)) - return SymbolType::Definition; + return SourceLocationKind::Definition; - return SymbolType::None; + return SourceLocationKind::None; } using SymbolKindAndTags = std::pair<SymbolKind, SymbolTags>; @@ -133,7 +133,7 @@ bool IndexDataConsumer::handleDeclOccurence(const clang::Decl *declaration, m_sourceLocationEntries.emplace_back(globalId, filePathId(sourceLocation), lineColum(sourceLocation), - symbolType(symbolRoles)); + sourceLocationKind(symbolRoles)); } return true; diff --git a/src/tools/clangrefactoringbackend/source/sourcelocationentry.h b/src/tools/clangrefactoringbackend/source/sourcelocationentry.h index 21e107be71..5d4a4bbf77 100644 --- a/src/tools/clangrefactoringbackend/source/sourcelocationentry.h +++ b/src/tools/clangrefactoringbackend/source/sourcelocationentry.h @@ -36,17 +36,6 @@ using uint = unsigned int; namespace ClangBackEnd { -enum class SymbolType -{ - None = 0, - Declaration, - DeclarationReference, - Definition, - MacroDefinition = 1024, - MacroUsage, - MacroUndefinition -}; - using SymbolIndex = long long; class SourceLocationEntry @@ -55,24 +44,24 @@ public: SourceLocationEntry(SymbolIndex symbolId, FilePathId filePathId, Utils::LineColumn lineColumn, - SymbolType symbolType) + SourceLocationKind kind) : symbolId(symbolId), filePathId(filePathId), lineColumn(lineColumn), - symbolType(symbolType) + kind(kind) {} SymbolIndex symbolId = 0; FilePathId filePathId; Utils::LineColumn lineColumn; - SymbolType symbolType; + SourceLocationKind kind; friend bool operator==(const SourceLocationEntry &first, const SourceLocationEntry &second) { return first.symbolId == second.symbolId && first.filePathId == second.filePathId && first.lineColumn == second.lineColumn - && first.symbolType == second.symbolType; + && first.kind == second.kind; } }; diff --git a/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h b/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h index 7cd05ee27b..7652795acb 100644 --- a/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h +++ b/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h @@ -73,6 +73,7 @@ public: const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer); const Sqlite::Column &lineColumn = table.addColumn("line", Sqlite::ColumnType::Integer); const Sqlite::Column &columnColumn = table.addColumn("column", Sqlite::ColumnType::Integer); + table.addColumn("locationKind", Sqlite::ColumnType::Integer); table.addUniqueIndex({sourceIdColumn, lineColumn, columnColumn}); table.initialize(database); @@ -119,7 +120,7 @@ public: "INSERT INTO newSymbols(temporarySymbolId, usr, symbolName, symbolKind) VALUES(?,?,?,?)", database}; WriteStatement insertLocationsToNewLocationsStatement{ - "INSERT OR IGNORE INTO newLocations(temporarySymbolId, line, column, sourceId) VALUES(?,?,?,?)", + "INSERT OR IGNORE INTO newLocations(temporarySymbolId, line, column, sourceId, locationKind) VALUES(?,?,?,?,?)", database }; ReadStatement selectNewSourceIdsStatement{ @@ -145,7 +146,7 @@ public: database }; WriteStatement insertNewLocationsInLocationsStatement{ - "INSERT INTO locations(symbolId, line, column, sourceId) SELECT symbolId, line, column, sourceId FROM newLocations", + "INSERT INTO locations(symbolId, line, column, sourceId, locationKind) SELECT symbolId, line, column, sourceId, locationKind FROM newLocations", database }; WriteStatement deleteNewSymbolsTableStatement{ diff --git a/src/tools/clangrefactoringbackend/source/symbolstorage.h b/src/tools/clangrefactoringbackend/source/symbolstorage.h index 9c307a8664..dccc8f06fb 100644 --- a/src/tools/clangrefactoringbackend/source/symbolstorage.h +++ b/src/tools/clangrefactoringbackend/source/symbolstorage.h @@ -210,11 +210,12 @@ public: { WriteStatement &statement = m_statementFactory.insertLocationsToNewLocationsStatement; - for (const auto &locationsEntry : sourceLocations) { - statement.write(locationsEntry.symbolId, - locationsEntry.lineColumn.line, - locationsEntry.lineColumn.column, - locationsEntry.filePathId.filePathId); + for (const auto &locationEntry : sourceLocations) { + statement.write(locationEntry.symbolId, + locationEntry.lineColumn.line, + locationEntry.lineColumn.column, + locationEntry.filePathId.filePathId, + int(locationEntry.kind)); } } |