ClangCodeModel: Remove libclang-based outline support

Change-Id: Ic7a7b0cfe1d3eb822dbad610fc84f29676404505
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2022-04-27 17:21:30 +02:00
parent 52d9def5e9
commit e045af7e69
6 changed files with 3 additions and 327 deletions

View File

@@ -40,7 +40,6 @@ add_qtc_plugin(ClangCodeModel
clanghighlightingresultreporter.cpp clanghighlightingresultreporter.h clanghighlightingresultreporter.cpp clanghighlightingresultreporter.h
clangisdiagnosticrelatedtolocation.h clangisdiagnosticrelatedtolocation.h
clangmodelmanagersupport.cpp clangmodelmanagersupport.h clangmodelmanagersupport.cpp clangmodelmanagersupport.h
clangoverviewmodel.cpp clangoverviewmodel.h
clangpreprocessorassistproposalitem.cpp clangpreprocessorassistproposalitem.h clangpreprocessorassistproposalitem.cpp clangpreprocessorassistproposalitem.h
clangprojectsettings.cpp clangprojectsettings.h clangprojectsettings.cpp clangprojectsettings.h
clangprojectsettingswidget.cpp clangprojectsettingswidget.h clangprojectsettingswidget.ui clangprojectsettingswidget.cpp clangprojectsettingswidget.h clangprojectsettingswidget.ui

View File

@@ -85,8 +85,6 @@ QtcPlugin {
"clangisdiagnosticrelatedtolocation.h", "clangisdiagnosticrelatedtolocation.h",
"clangmodelmanagersupport.cpp", "clangmodelmanagersupport.cpp",
"clangmodelmanagersupport.h", "clangmodelmanagersupport.h",
"clangoverviewmodel.cpp",
"clangoverviewmodel.h",
"clangpreprocessorassistproposalitem.cpp", "clangpreprocessorassistproposalitem.cpp",
"clangpreprocessorassistproposalitem.h", "clangpreprocessorassistproposalitem.h",
"clangprojectsettings.cpp", "clangprojectsettings.cpp",

View File

@@ -30,7 +30,6 @@
#include "clangdquickfixfactory.h" #include "clangdquickfixfactory.h"
#include "clangeditordocumentprocessor.h" #include "clangeditordocumentprocessor.h"
#include "clangdlocatorfilters.h" #include "clangdlocatorfilters.h"
#include "clangoverviewmodel.h"
#include "clangprojectsettings.h" #include "clangprojectsettings.h"
#include "clangrefactoringengine.h" #include "clangrefactoringengine.h"
#include "clangutils.h" #include "clangutils.h"
@@ -41,6 +40,7 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h> #include <coreplugin/messagemanager.h>
#include <cppeditor/abstractoverviewmodel.h>
#include <cppeditor/cppcodemodelsettings.h> #include <cppeditor/cppcodemodelsettings.h>
#include <cppeditor/cppeditorconstants.h> #include <cppeditor/cppeditorconstants.h>
#include <cppeditor/cppeditorwidget.h> #include <cppeditor/cppeditorwidget.h>
@@ -222,7 +222,7 @@ CppEditor::RefactoringEngineInterface &ClangModelManagerSupport::refactoringEngi
std::unique_ptr<CppEditor::AbstractOverviewModel> ClangModelManagerSupport::createOverviewModel() std::unique_ptr<CppEditor::AbstractOverviewModel> ClangModelManagerSupport::createOverviewModel()
{ {
return std::make_unique<OverviewModel>(); return {};
} }
bool ClangModelManagerSupport::supportsOutline(const TextEditor::TextDocument *document) const bool ClangModelManagerSupport::supportsOutline(const TextEditor::TextDocument *document) const

View File

@@ -1,251 +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.
**
****************************************************************************/
#include "clangoverviewmodel.h"
#include "clangeditordocumentprocessor.h"
#include "clangutils.h"
#include <cplusplus/Icons.h>
#include <utils/dropsupport.h>
#include <utils/linecolumn.h>
#include <utils/qtcassert.h>
using TokenContainer = ClangBackEnd::TokenInfoContainer;
using TokenContainers = QVector<TokenContainer>;
using namespace Utils;
namespace ClangCodeModel {
namespace Internal {
void addFirstItem(TokenTreeItem *root)
{
ClangBackEnd::ExtraInfo extraInfo;
if (!root->childCount()) {
extraInfo.token = Utf8String::fromString(
QString(QT_TRANSLATE_NOOP("ClangCodeModel", "<No Symbols>")));
} else {
extraInfo.token = Utf8String::fromString(
QString(QT_TRANSLATE_NOOP("ClangCodeModel", "<Select Symbol>")));
}
ClangBackEnd::HighlightingTypes types;
types.mainHighlightingType = ClangBackEnd::HighlightingType::Invalid;
TokenContainer firstItem(0, 0, 0, types, extraInfo);
root->prependChild(new TokenTreeItem(firstItem));
}
void buildTree(const TokenContainers &containers,
TokenTreeItem *root)
{
// Most of the nodes are not used in this tree at all (all local variables and more)
// therefore use unordered_map instead of vector.
std::unordered_map<int, TokenTreeItem *> treeItemCache;
for (int index = 0; index < containers.size(); ++index) {
const TokenContainer &container = containers[index];
if (!container.isGlobalDeclaration())
continue;
const int lexicalParentIndex = container.extraInfo.lexicalParentIndex;
QTC_ASSERT(lexicalParentIndex < index, return;);
auto item = std::make_unique<TokenTreeItem>(container);
treeItemCache[index] = item.get();
TokenTreeItem *parent = root;
if (lexicalParentIndex >= 0 && treeItemCache[lexicalParentIndex])
parent = treeItemCache[lexicalParentIndex];
ClangBackEnd::HighlightingType parentType = parent->token.types.mainHighlightingType;
if (parentType == ClangBackEnd::HighlightingType::VirtualFunction
|| parentType == ClangBackEnd::HighlightingType::Function) {
// Treat everything inside a function scope as local variables.
treeItemCache.erase(index);
continue;
}
parent->appendChild(item.release());
}
addFirstItem(root);
}
static QString addType(const QString &name, const ClangBackEnd::ExtraInfo &extraInfo)
{
return name + QLatin1String(" -> ", 4) + extraInfo.typeSpelling.toString();
}
static QString fullName(const ClangBackEnd::ExtraInfo &extraInfo, TokenTreeItem *parent)
{
const QString parentType = parent->token.extraInfo.typeSpelling.toString();
if (extraInfo.semanticParentTypeSpelling.startsWith(parentType)) {
const QString parentQualification = parentType.isEmpty()
? extraInfo.semanticParentTypeSpelling
: extraInfo.semanticParentTypeSpelling.mid(parentType.length() + 2);
if (!parentQualification.isEmpty())
return parentQualification + "::" + extraInfo.token.toString();
}
return extraInfo.token.toString();
}
QVariant TokenTreeItem::data(int column, int role) const
{
Q_UNUSED(column)
if (token.types.mainHighlightingType == ClangBackEnd::HighlightingType::Invalid
&& token.line == 0 && token.column == 0 && token.length == 0) {
if (role == Qt::DisplayRole)
return token.extraInfo.token.toString();
return QVariant();
}
switch (role) {
case Qt::DisplayRole: {
QString name = fullName(token.extraInfo, static_cast<TokenTreeItem *>(parent()));
ClangBackEnd::HighlightingType mainType = token.types.mainHighlightingType;
if (mainType == ClangBackEnd::HighlightingType::VirtualFunction
|| mainType == ClangBackEnd::HighlightingType::Function) {
name = addType(name, token.extraInfo);
} else if (mainType == ClangBackEnd::HighlightingType::GlobalVariable
|| mainType == ClangBackEnd::HighlightingType::Field
|| mainType == ClangBackEnd::HighlightingType::QtProperty) {
name = addType(name, token.extraInfo);
if (token.types.mixinHighlightingTypes.contains(
ClangBackEnd::HighlightingType::ObjectiveCProperty)) {
name = QLatin1String("@property ") + name;
} else if (token.types.mixinHighlightingTypes.contains(
ClangBackEnd::HighlightingType::ObjectiveCMethod)) {
if (token.extraInfo.storageClass == ClangBackEnd::StorageClass::Static)
name = QLatin1Char('+') + name;
else
name = QLatin1Char('-') + name;
}
} else if (mainType == ClangBackEnd::HighlightingType::Type) {
if (token.types.mixinHighlightingTypes.contains(
ClangBackEnd::HighlightingType::ObjectiveCClass)) {
name = QLatin1String("@class ") + name;
} else if (token.types.mixinHighlightingTypes.contains(
ClangBackEnd::HighlightingType::ObjectiveCProtocol)) {
name = QLatin1String("@protocol ") + name;
} else if (token.types.mixinHighlightingTypes.contains(
ClangBackEnd::HighlightingType::ObjectiveCInterface)) {
name = QLatin1String("@interface ") + name;
} else if (token.types.mixinHighlightingTypes.contains(
ClangBackEnd::HighlightingType::ObjectiveCImplementation)) {
name = QLatin1String("@implementation ") + name;
} else if (token.types.mixinHighlightingTypes.contains(
ClangBackEnd::HighlightingType::ObjectiveCCategory)) {
name = name + " [category]";
}
}
return name;
}
case Qt::EditRole: {
return token.extraInfo.token.toString();
}
case Qt::DecorationRole: {
return CodeModelIcon::iconForType(iconTypeForToken(token));
}
case CppEditor::AbstractOverviewModel::FileNameRole: {
return token.extraInfo.cursorRange.start.filePath.toString();
}
case CppEditor::AbstractOverviewModel::LineNumberRole: {
return token.line;
}
default:
return QVariant();
} // switch
}
bool OverviewModel::rebuild(const QString &filePath)
{
ClangEditorDocumentProcessor *processor = ClangEditorDocumentProcessor::get(filePath);
if (!processor)
return false;
if (m_filePath != filePath) {
if (!m_filePath.isEmpty()) {
ClangEditorDocumentProcessor *previousProcessor
= ClangEditorDocumentProcessor::get(m_filePath);
if (previousProcessor) {
disconnect(previousProcessor, &ClangEditorDocumentProcessor::tokenInfosUpdated,
this, &OverviewModel::needsUpdate);
}
}
m_filePath = filePath;
connect(processor, &ClangEditorDocumentProcessor::tokenInfosUpdated, this,
&OverviewModel::needsUpdate);
}
const TokenContainers &tokenContainers = processor->tokenInfos();
auto *root = new TokenTreeItem;
buildTree(tokenContainers, root);
setRootItem(root);
return true;
}
bool OverviewModel::isGenerated(const QModelIndex &) const
{
return false;
}
Link OverviewModel::linkFromIndex(const QModelIndex &sourceIndex) const
{
auto item = static_cast<TokenTreeItem *>(itemForIndex(sourceIndex));
if (!item)
return {};
return Link(FilePath::fromString(m_filePath), item->token.line, item->token.column - 1);
}
LineColumn OverviewModel::lineColumnFromIndex(const QModelIndex &sourceIndex) const
{
auto item = static_cast<TokenTreeItem *>(itemForIndex(sourceIndex));
if (!item)
return {};
return {item->token.line, item->token.column};
}
OverviewModel::Range OverviewModel::rangeFromIndex(const QModelIndex &sourceIndex) const
{
auto item = static_cast<TokenTreeItem *>(itemForIndex(sourceIndex));
if (!item)
return {};
const ClangBackEnd::SourceRangeContainer &range = item->token.extraInfo.cursorRange;
return std::make_pair(LineColumn(range.start.line, range.start.column),
LineColumn(range.end.line, range.end.column));
}
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -1,70 +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 "tokeninfocontainer.h"
#include <cppeditor/abstractoverviewmodel.h>
namespace ClangBackEnd { class TokenInfoContainer; }
namespace ClangCodeModel {
namespace Internal {
class ClangEditorDocumentProcessor;
class TokenTreeItem : public ::Utils::TypedTreeItem<TokenTreeItem>
{
public:
TokenTreeItem() noexcept
: token()
{}
TokenTreeItem(const ClangBackEnd::TokenInfoContainer &token) noexcept
: token(token)
{}
QVariant data(int column, int role) const override;
const ClangBackEnd::TokenInfoContainer token;
};
class OverviewModel : public CppEditor::AbstractOverviewModel
{
Q_OBJECT
public:
bool rebuild(const QString &filePath) override;
bool isGenerated(const QModelIndex &sourceIndex) const override;
::Utils::Link linkFromIndex(const QModelIndex &sourceIndex) const override;
::Utils::LineColumn lineColumnFromIndex(const QModelIndex &sourceIndex) const override;
Range rangeFromIndex(const QModelIndex &sourceIndex) const override;
private:
QString m_filePath;
};
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -548,7 +548,7 @@ Core::ILocatorFilter *CppModelManager::currentDocumentFilter() const
std::unique_ptr<AbstractOverviewModel> CppModelManager::createOverviewModel() const std::unique_ptr<AbstractOverviewModel> CppModelManager::createOverviewModel() const
{ {
return d->m_activeModelManagerSupport->createOverviewModel(); return d->m_builtinModelManagerSupport->createOverviewModel();
} }
QString CppModelManager::configurationFileName() QString CppModelManager::configurationFileName()