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>
This commit is contained in:
Marco Bubke
2018-04-09 13:30:30 +02:00
parent 18de1e3fcf
commit 4b0bcbdcb6
57 changed files with 649 additions and 1118 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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> &)

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -29,11 +29,7 @@
namespace ClangRefactoring {
QtcreatorSymbolsFindFilter::QtcreatorSymbolsFindFilter()
{
}
QWidget *QtcreatorSymbolsFindFilter::createConfigWidget()
QWidget *QtCreatorSymbolsFindFilter::createConfigWidget()
{
return new SymbolsFindFilterConfigWidget(this);
}

View File

@@ -29,11 +29,11 @@
namespace ClangRefactoring {
class QtcreatorSymbolsFindFilter : public SymbolsFindFilter
class QtCreatorSymbolsFindFilter : public SymbolsFindFilter
{
Q_OBJECT
public:
QtcreatorSymbolsFindFilter();
QtCreatorSymbolsFindFilter() = default;
QWidget *createConfigWidget() override;
};

View File

@@ -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

View File

@@ -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>;

View File

@@ -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

View File

@@ -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);
}
Functions functionsContaining(Utils::SmallStringView/*regularExpression*/) const override
Symbols symbolsWithTwoSymbolKinds(ClangBackEnd::SymbolKind symbolKind1,
ClangBackEnd::SymbolKind symbolKind2,
Utils::SmallStringView searchTerm) const
{
// TODO: implement
return Functions();
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);
}
Symbols symbols(const ClangBackEnd::SymbolKinds &symbolKinds,
Utils::SmallStringView searchTerm) const override
{
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;
};

View File

@@ -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;