ClangCodeModel: Remove libclang-based locator filter

Change-Id: I1c588a7bfdee773662d1956e9a998040794b8c9d
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2022-04-27 17:59:26 +02:00
parent 2e725b4869
commit c21774f0a7
9 changed files with 24 additions and 256 deletions

View File

@@ -24,7 +24,6 @@ add_qtc_plugin(ClangCodeModel
clangcompletionchunkstotextconverter.cpp clangcompletionchunkstotextconverter.h
clangcompletioncontextanalyzer.cpp clangcompletioncontextanalyzer.h
clangconstants.h
clangcurrentdocumentfilter.cpp clangcurrentdocumentfilter.h
clangdclient.cpp clangdclient.h
clangdiagnosticfilter.cpp clangdiagnosticfilter.h
clangdiagnosticmanager.cpp clangdiagnosticmanager.h

View File

@@ -54,8 +54,6 @@ QtcPlugin {
"clangcompletioncontextanalyzer.cpp",
"clangcompletioncontextanalyzer.h",
"clangconstants.h",
"clangcurrentdocumentfilter.cpp",
"clangcurrentdocumentfilter.h",
"clangdclient.cpp",
"clangdclient.h",
"clangdiagnosticfilter.cpp",

View File

@@ -1,177 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "clangcurrentdocumentfilter.h"
#include "clangeditordocumentprocessor.h"
#include "clangutils.h"
#include <clangsupport/tokeninfocontainer.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <cplusplus/Icons.h>
#include <cppeditor/cppeditorconstants.h>
#include <texteditor/textdocument.h>
#include <utils/algorithm.h>
#include <utils/fuzzymatcher.h>
#include <utils/linecolumn.h>
#include <utils/textutils.h>
#include <utils/qtcassert.h>
#include <QRegularExpression>
using namespace Utils;
namespace ClangCodeModel {
namespace Internal {
ClangCurrentDocumentFilter::ClangCurrentDocumentFilter()
{
setId(CppEditor::Constants::CURRENT_DOCUMENT_FILTER_ID);
setDisplayName(CppEditor::Constants::CURRENT_DOCUMENT_FILTER_DISPLAY_NAME);
setDefaultShortcutString(".");
setPriority(High);
setDefaultIncludedByDefault(false);
Core::EditorManager *editorManager = Core::EditorManager::instance();
connect(editorManager, &Core::EditorManager::currentEditorChanged,
this, &ClangCurrentDocumentFilter::onCurrentEditorChanged);
connect(editorManager, &Core::EditorManager::editorAboutToClose,
this, &ClangCurrentDocumentFilter::onEditorAboutToClose);
}
static QString addType(const QString &signature, const ClangBackEnd::ExtraInfo &extraInfo)
{
return signature + QLatin1String(" -> ", 4) + extraInfo.typeSpelling.toString();
}
static Core::LocatorFilterEntry makeEntry(Core::ILocatorFilter *filter,
const ClangBackEnd::TokenInfoContainer &info)
{
const ClangBackEnd::ExtraInfo &extraInfo = info.extraInfo;
QString displayName = extraInfo.token;
LineColumn lineColumn(info.line, info.column);
Core::LocatorFilterEntry entry(filter, displayName, QVariant::fromValue(lineColumn));
QString extra;
ClangBackEnd::HighlightingType mainType = info.types.mainHighlightingType;
if (mainType == ClangBackEnd::HighlightingType::VirtualFunction
|| mainType == ClangBackEnd::HighlightingType::Function
|| mainType == ClangBackEnd::HighlightingType::GlobalVariable
|| mainType == ClangBackEnd::HighlightingType::Field
|| mainType == ClangBackEnd::HighlightingType::QtProperty) {
displayName = addType(displayName, extraInfo);
extra = extraInfo.semanticParentTypeSpelling.toString();
} else {
extra = extraInfo.typeSpelling.toString();
}
entry.displayName = displayName;
entry.extraInfo = extra;
entry.displayIcon = CodeModelIcon::iconForType(iconTypeForToken(info));
return entry;
}
void ClangCurrentDocumentFilter::prepareSearch(const QString &entry)
{
Q_UNUSED(entry)
m_preparedPath = m_currentPath;
}
QList<Core::LocatorFilterEntry> ClangCurrentDocumentFilter::matchesFor(
QFutureInterface<Core::LocatorFilterEntry> &, const QString &entry)
{
QList<Core::LocatorFilterEntry> goodEntries;
if (m_preparedPath.isEmpty())
return goodEntries;
FuzzyMatcher::CaseSensitivity caseSesitivity = caseSensitivity(entry) == Qt::CaseSensitive
? FuzzyMatcher::CaseSensitivity::CaseSensitive
: FuzzyMatcher::CaseSensitivity::CaseInsensitive;
const QRegularExpression regexp = FuzzyMatcher::createRegExp(entry, caseSesitivity);
if (!regexp.isValid())
return goodEntries;
ClangEditorDocumentProcessor *processor = ClangEditorDocumentProcessor::get(m_preparedPath);
if (!processor)
return goodEntries;
using TokInfoContainer = ClangBackEnd::TokenInfoContainer;
const QVector<TokInfoContainer> &infos = processor->tokenInfos();
for (const TokInfoContainer &info : infos) {
if (!info.isGlobalDeclaration())
continue;
QRegularExpressionMatch match = regexp.match(info.extraInfo.token);
if (match.hasMatch())
goodEntries.push_back(makeEntry(this, info));
}
return goodEntries;
}
void ClangCurrentDocumentFilter::accept(const Core::LocatorFilterEntry &selection,
QString *, int *, int *) const
{
if (!m_currentEditor)
return;
auto lineColumn = qvariant_cast<LineColumn>(selection.internalData);
Core::EditorManager::openEditorAt(
{FilePath::fromString(m_currentPath), lineColumn.line, lineColumn.column - 1});
}
void ClangCurrentDocumentFilter::reset(Core::IEditor *newCurrent, const QString &path)
{
m_currentEditor = newCurrent;
m_currentPath = path;
}
void ClangCurrentDocumentFilter::onEditorAboutToClose(Core::IEditor *editorAboutToClose)
{
if (!editorAboutToClose)
return;
if (m_currentEditor == editorAboutToClose)
reset();
}
void ClangCurrentDocumentFilter::onCurrentEditorChanged(Core::IEditor *newCurrent)
{
if (newCurrent) {
Core::IDocument *document = newCurrent->document();
QTC_ASSERT(document, reset(); return);
if (auto *textDocument = qobject_cast<TextEditor::TextDocument *>(document)) {
reset(newCurrent, textDocument->filePath().toString());
return;
}
}
reset();
}
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -1,60 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <coreplugin/locator/ilocatorfilter.h>
namespace Core { class IEditor; }
namespace ClangCodeModel {
namespace Internal {
class ClangCurrentDocumentFilter : public Core::ILocatorFilter
{
Q_OBJECT
public:
explicit ClangCurrentDocumentFilter();
void prepareSearch(const QString &entry) override;
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
const QString &entry) override;
void accept(const Core::LocatorFilterEntry &selection,
QString *newText, int *selectionStart, int *selectionLength) const override;
private:
void onEditorAboutToClose(Core::IEditor *editors);
void onCurrentEditorChanged(Core::IEditor *newCurrent);
void reset(Core::IEditor *newCurrent = nullptr, const QString &path = QString());
Core::IEditor *m_currentEditor = nullptr;
QString m_currentPath;
QString m_preparedPath;
};
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -27,7 +27,6 @@
#include "clangdclient.h"
#include "clangmodelmanagersupport.h"
#include "clangcurrentdocumentfilter.h"
#include <cppeditor/cppeditorconstants.h>
#include <cppeditor/cpplocatorfilter.h>
@@ -226,19 +225,6 @@ ClangFunctionsFilter::ClangFunctionsFilter()
setDefaultIncludedByDefault(false);
}
class CppCurrentDocumentFilter : public ClangCurrentDocumentFilter
{
public:
CppCurrentDocumentFilter()
{
setId({});
setDisplayName({});
setDefaultShortcutString({});
setEnabled(false);
setHidden(true);
}
};
class LspCurrentDocumentFilter : public LanguageClient::DocumentLocatorFilter
{
public:
@@ -278,7 +264,10 @@ private:
class ClangdCurrentDocumentFilter::Private
{
public:
CppCurrentDocumentFilter cppFilter;
~Private() { delete cppFilter; }
Core::ILocatorFilter * const cppFilter
= CppEditor::CppModelManager::createAuxiliaryCurrentDocumentFilter();
LspCurrentDocumentFilter lspFilter;
Core::ILocatorFilter *activeFilter = nullptr;
};
@@ -306,7 +295,7 @@ void ClangdCurrentDocumentFilter::prepareSearch(const QString &entry)
->clientForFile(doc->filePath()); client && client->reachable()) {
d->activeFilter = &d->lspFilter;
} else {
d->activeFilter = &d->cppFilter;
d->activeFilter = d->cppFilter;
}
d->activeFilter->prepareSearch(entry);
}

View File

@@ -60,6 +60,15 @@ CppCurrentDocumentFilter::CppCurrentDocumentFilter(CppModelManager *manager)
this, &CppCurrentDocumentFilter::onEditorAboutToClose);
}
void CppCurrentDocumentFilter::makeAuxiliary()
{
setId({});
setDisplayName({});
setDefaultShortcutString({});
setEnabled(false);
setHidden(true);
}
QList<Core::LocatorFilterEntry> CppCurrentDocumentFilter::matchesFor(
QFutureInterface<Core::LocatorFilterEntry> &future, const QString & entry)
{

View File

@@ -45,6 +45,8 @@ public:
explicit CppCurrentDocumentFilter(CppModelManager *manager);
~CppCurrentDocumentFilter() override = default;
void makeAuxiliary();
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
const QString &entry) override;
void accept(const Core::LocatorFilterEntry &selection,

View File

@@ -1680,6 +1680,13 @@ void CppModelManager::switchDeclDef(const CursorInEditor &data,
d->m_activeModelManagerSupport->switchDeclDef(data, std::move(processLinkCallback));
}
Core::ILocatorFilter *CppModelManager::createAuxiliaryCurrentDocumentFilter()
{
const auto filter = new Internal::CppCurrentDocumentFilter(instance());
filter->makeAuxiliary();
return filter;
}
BaseEditorDocumentProcessor *CppModelManager::createEditorDocumentProcessor(
TextEditor::TextDocument *baseTextDocument) const
{

View File

@@ -187,6 +187,7 @@ public:
bool resolveTarget, bool inNextSplit);
void switchDeclDef(const CursorInEditor &data,
Utils::ProcessLinkCallback &&processLinkCallback);
static Core::ILocatorFilter *createAuxiliaryCurrentDocumentFilter();
std::unique_ptr<AbstractOverviewModel> createOverviewModel() const;