forked from qt-creator/qt-creator
Remove clangsupport dependency from plugins
Change-Id: Ifd4215a590d32cd04fab720d0d8d5e746e81c6e8 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -79,6 +79,7 @@ public:
|
||||
QTCREATOR_UTILS_EXPORT QHashValueType qHash(const Link &l);
|
||||
|
||||
using ProcessLinkCallback = std::function<void(const Link &)>;
|
||||
using Links = QList<Link>;
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
|
@@ -1,3 +1,5 @@
|
||||
set(CLANG_VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH})
|
||||
|
||||
set(TEST_LINK_DEPENDS)
|
||||
if(WITH_TESTS)
|
||||
set(TEST_LINK_DEPENDS QtSupport)
|
||||
@@ -5,9 +7,13 @@ endif()
|
||||
|
||||
add_qtc_plugin(ClangCodeModel
|
||||
CONDITION TARGET libclang
|
||||
DEPENDS ClangSupport CPlusPlus
|
||||
DEPENDS CPlusPlus
|
||||
PLUGIN_DEPENDS Core CppEditor LanguageClient ${TEST_LINK_DEPENDS} TextEditor
|
||||
PLUGIN_TEST_DEPENDS QmakeProjectManager
|
||||
DEFINES
|
||||
CLANG_VERSION="${CLANG_VERSION}"
|
||||
CLANG_INCLUDE_DIR="${LLVM_LIBRARY_DIR}/clang/${CLANG_VERSION}/include"
|
||||
CLANG_BINDIR="${LLVM_TOOLS_BINARY_DIR}"
|
||||
SOURCES
|
||||
clangactivationsequencecontextprocessor.cpp clangactivationsequencecontextprocessor.h
|
||||
clangactivationsequenceprocessor.cpp clangactivationsequenceprocessor.h
|
||||
|
@@ -6,7 +6,6 @@ QtcPlugin {
|
||||
|
||||
Depends { name: "Qt"; submodules: ["concurrent", "widgets"] }
|
||||
|
||||
Depends { name: "ClangSupport" }
|
||||
Depends { name: "Core" }
|
||||
Depends { name: "CppEditor" }
|
||||
Depends { name: "LanguageClient" }
|
||||
|
@@ -34,7 +34,6 @@
|
||||
#include "clangtextmark.h"
|
||||
#include "clangutils.h"
|
||||
|
||||
#include <clangsupport/sourcelocationscontainer.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/find/searchresultitem.h>
|
||||
#include <coreplugin/find/searchresultwindow.h>
|
||||
@@ -2240,11 +2239,7 @@ void ClangdClient::findLocalUsages(TextDocument *document, const QTextCursor &cu
|
||||
qCDebug(clangdLog) << "found" << locations.size() << "local references";
|
||||
if (!d->localRefsData || id != d->localRefsData->id)
|
||||
return;
|
||||
ClangBackEnd::SourceLocationsContainer container;
|
||||
for (const Location &loc : locations) {
|
||||
container.insertSourceLocation({}, loc.range().start().line() + 1,
|
||||
loc.range().start().character() + 1);
|
||||
}
|
||||
const Utils::Links links = Utils::transform(locations, &Location::toLink);
|
||||
|
||||
// The callback only uses the symbol length, so we just create a dummy.
|
||||
// Note that the calculation will be wrong for identifiers with
|
||||
@@ -2254,7 +2249,7 @@ void ClangdClient::findLocalUsages(TextDocument *document, const QTextCursor &cu
|
||||
const Range r = locations.first().range();
|
||||
symbol = QString(r.end().character() - r.start().character(), 'x');
|
||||
}
|
||||
d->localRefsData->callback(symbol, container, d->localRefsData->revision);
|
||||
d->localRefsData->callback(symbol, links, d->localRefsData->revision);
|
||||
d->localRefsData->callback = {};
|
||||
d->localRefsData.reset();
|
||||
});
|
||||
|
@@ -52,36 +52,25 @@ namespace {
|
||||
const char LINK_ACTION_GOTO_LOCATION[] = "#gotoLocation";
|
||||
const char LINK_ACTION_APPLY_FIX[] = "#applyFix";
|
||||
|
||||
QString fileNamePrefix(const QString &mainFilePath,
|
||||
const ClangBackEnd::SourceLocationContainer &location)
|
||||
QString fileNamePrefix(const QString &mainFilePath, const Utils::Link &location)
|
||||
{
|
||||
const QString filePath = location.filePath.toString();
|
||||
const QString filePath = location.targetFilePath.toString();
|
||||
if (filePath != mainFilePath)
|
||||
return QFileInfo(filePath).fileName() + QLatin1Char(':');
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString locationToString(const ClangBackEnd::SourceLocationContainer &location)
|
||||
QString locationToString(const Utils::Link &location)
|
||||
{
|
||||
return QString::number(location.line)
|
||||
return QString::number(location.targetLine)
|
||||
+ QStringLiteral(":")
|
||||
+ QString::number(location.column);
|
||||
+ QString::number(location.targetColumn + 1);
|
||||
}
|
||||
|
||||
void openEditorAt(const ClangBackEnd::DiagnosticContainer &diagnostic)
|
||||
void applyFixit(const ClangDiagnostic &diagnostic)
|
||||
{
|
||||
const ClangBackEnd::SourceLocationContainer &location = diagnostic.location;
|
||||
|
||||
Core::EditorManager::openEditorAt({Utils::FilePath::fromString(location.filePath.toString()),
|
||||
int(location.line),
|
||||
int(location.column - 1)});
|
||||
}
|
||||
|
||||
void applyFixit(const ClangBackEnd::DiagnosticContainer &diagnostic)
|
||||
{
|
||||
ClangFixItOperation operation(Utf8String(), diagnostic.fixIts);
|
||||
|
||||
ClangFixItOperation operation({}, diagnostic.fixIts);
|
||||
operation.perform();
|
||||
}
|
||||
|
||||
@@ -102,7 +91,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
QWidget *createWidget(const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics,
|
||||
QWidget *createWidget(const QList<ClangDiagnostic> &diagnostics,
|
||||
const std::function<bool()> &canApplyFixIt, const QString &source)
|
||||
{
|
||||
const QString text = htmlText(diagnostics, source);
|
||||
@@ -133,12 +122,12 @@ public:
|
||||
const bool hideToolTipAfterLinkActivation = m_displayHints.hideTooltipAfterLinkActivation;
|
||||
QObject::connect(label, &QLabel::linkActivated, [table, hideToolTipAfterLinkActivation,
|
||||
canApplyFixIt](const QString &action) {
|
||||
const ClangBackEnd::DiagnosticContainer diagnostic = table.value(action);
|
||||
const ClangDiagnostic diagnostic = table.value(action);
|
||||
|
||||
if (diagnostic == ClangBackEnd::DiagnosticContainer())
|
||||
if (diagnostic == ClangDiagnostic())
|
||||
QDesktopServices::openUrl(QUrl(action));
|
||||
else if (action.startsWith(LINK_ACTION_GOTO_LOCATION)) {
|
||||
openEditorAt(diagnostic);
|
||||
Core::EditorManager::openEditorAt(diagnostic.location);
|
||||
} else if (action.startsWith(LINK_ACTION_APPLY_FIX)) {
|
||||
if (canApplyFixIt && canApplyFixIt())
|
||||
applyFixit(diagnostic);
|
||||
@@ -153,13 +142,12 @@ public:
|
||||
return label;
|
||||
}
|
||||
|
||||
QString htmlText(const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics,
|
||||
const QString &source)
|
||||
QString htmlText(const QList<ClangDiagnostic> &diagnostics, const QString &source)
|
||||
{
|
||||
// For debugging, add: style='border-width:1px;border-color:black'
|
||||
QString text = "<table cellspacing='0' cellpadding='0' width='100%'>";
|
||||
|
||||
foreach (const ClangBackEnd::DiagnosticContainer &diagnostic, diagnostics)
|
||||
foreach (const ClangDiagnostic &diagnostic, diagnostics)
|
||||
text.append(tableRows(diagnostic));
|
||||
if (!source.isEmpty()) {
|
||||
text.append(QString::fromUtf8("<tr><td colspan='2' align='left'>"
|
||||
@@ -186,13 +174,12 @@ private:
|
||||
// For clazy/tidy diagnostics, we expect something like "some text [some option]", e.g.:
|
||||
// * clazy: "Use the static QFileInfo::exists() instead. It's documented to be faster. [-Wclazy-qfileinfo-exists]"
|
||||
// * tidy: "use emplace_back instead of push_back [modernize-use-emplace]"
|
||||
static ClangBackEnd::DiagnosticContainer supplementedDiagnostic(
|
||||
const ClangBackEnd::DiagnosticContainer &diagnostic)
|
||||
static ClangDiagnostic supplementedDiagnostic(const ClangDiagnostic &diagnostic)
|
||||
{
|
||||
if (!diagnostic.category.isEmpty())
|
||||
return diagnostic; // OK, diagnostics from clang itself have this set.
|
||||
|
||||
ClangBackEnd::DiagnosticContainer supplementedDiagnostic = diagnostic;
|
||||
ClangDiagnostic supplementedDiagnostic = diagnostic;
|
||||
|
||||
DiagnosticTextInfo info(diagnostic.text);
|
||||
supplementedDiagnostic.enableOption = info.option();
|
||||
@@ -200,18 +187,18 @@ private:
|
||||
supplementedDiagnostic.text = info.textWithoutOption();
|
||||
|
||||
for (auto &child : supplementedDiagnostic.children)
|
||||
child.text = DiagnosticTextInfo(diagnostic.text.toString()).textWithoutOption();
|
||||
child.text = DiagnosticTextInfo(diagnostic.text).textWithoutOption();
|
||||
|
||||
return supplementedDiagnostic;
|
||||
}
|
||||
|
||||
QString tableRows(const ClangBackEnd::DiagnosticContainer &diagnostic)
|
||||
QString tableRows(const ClangDiagnostic &diagnostic)
|
||||
{
|
||||
m_mainFilePath = m_displayHints.showFileNameInMainDiagnostic
|
||||
? Utf8String()
|
||||
: diagnostic.location.filePath;
|
||||
? QString()
|
||||
: diagnostic.location.targetFilePath.toString();
|
||||
|
||||
const ClangBackEnd::DiagnosticContainer diag = supplementedDiagnostic(diagnostic);
|
||||
const ClangDiagnostic diag = supplementedDiagnostic(diagnostic);
|
||||
|
||||
QString text;
|
||||
if (m_displayHints.showCategoryAndEnableOption)
|
||||
@@ -222,8 +209,7 @@ private:
|
||||
return text;
|
||||
}
|
||||
|
||||
static QString diagnosticCategoryAndEnableOptionRow(
|
||||
const ClangBackEnd::DiagnosticContainer &diagnostic)
|
||||
static QString diagnosticCategoryAndEnableOptionRow(const ClangDiagnostic &diagnostic)
|
||||
{
|
||||
const QString text = QString::fromLatin1(
|
||||
" <tr>"
|
||||
@@ -235,11 +221,11 @@ private:
|
||||
return text;
|
||||
}
|
||||
|
||||
QString diagnosticText(const ClangBackEnd::DiagnosticContainer &diagnostic)
|
||||
QString diagnosticText(const ClangDiagnostic &diagnostic)
|
||||
{
|
||||
const bool hasFixit = m_displayHints.enableClickableFixits
|
||||
&& !diagnostic.fixIts.isEmpty();
|
||||
const QString diagnosticText = diagnostic.text.toString().toHtmlEscaped();
|
||||
const QString diagnosticText = diagnostic.text.toHtmlEscaped();
|
||||
const QString text = QString::fromLatin1("%1: %2")
|
||||
.arg(clickableLocation(diagnostic, m_mainFilePath),
|
||||
clickableFixIt(diagnostic, diagnosticText, hasFixit));
|
||||
@@ -247,8 +233,7 @@ private:
|
||||
return text;
|
||||
}
|
||||
|
||||
QString diagnosticRow(const ClangBackEnd::DiagnosticContainer &diagnostic,
|
||||
IndentMode indentMode)
|
||||
QString diagnosticRow(const ClangDiagnostic &diagnostic, IndentMode indentMode)
|
||||
{
|
||||
const QString text = QString::fromLatin1(
|
||||
" <tr>"
|
||||
@@ -260,9 +245,9 @@ private:
|
||||
return text;
|
||||
}
|
||||
|
||||
QString diagnosticRowsForChildren(const ClangBackEnd::DiagnosticContainer &diagnostic)
|
||||
QString diagnosticRowsForChildren(const ClangDiagnostic &diagnostic)
|
||||
{
|
||||
const QVector<ClangBackEnd::DiagnosticContainer> &children = diagnostic.children;
|
||||
const QList<ClangDiagnostic> &children = diagnostic.children;
|
||||
QString text;
|
||||
|
||||
if (children.size() <= 10) {
|
||||
@@ -277,8 +262,8 @@ private:
|
||||
}
|
||||
|
||||
QString diagnosticRowsForChildren(
|
||||
const QVector<ClangBackEnd::DiagnosticContainer>::const_iterator first,
|
||||
const QVector<ClangBackEnd::DiagnosticContainer>::const_iterator last)
|
||||
const QList<ClangDiagnostic>::const_iterator first,
|
||||
const QList<ClangDiagnostic>::const_iterator last)
|
||||
{
|
||||
QString text;
|
||||
|
||||
@@ -288,10 +273,9 @@ private:
|
||||
return text;
|
||||
}
|
||||
|
||||
QString clickableLocation(const ClangBackEnd::DiagnosticContainer &diagnostic,
|
||||
const QString &mainFilePath)
|
||||
QString clickableLocation(const ClangDiagnostic &diagnostic, const QString &mainFilePath)
|
||||
{
|
||||
const ClangBackEnd::SourceLocationContainer &location = diagnostic.location;
|
||||
const Utils::Link &location = diagnostic.location;
|
||||
|
||||
const QString filePrefix = fileNamePrefix(mainFilePath, location);
|
||||
const QString lineColumn = locationToString(location);
|
||||
@@ -301,9 +285,7 @@ private:
|
||||
return wrapInLink(linkText, targetId);
|
||||
}
|
||||
|
||||
QString clickableFixIt(const ClangBackEnd::DiagnosticContainer &diagnostic,
|
||||
const QString &text,
|
||||
bool hasFixIt)
|
||||
QString clickableFixIt(const ClangDiagnostic &diagnostic, const QString &text, bool hasFixIt)
|
||||
{
|
||||
if (!hasFixIt)
|
||||
return text;
|
||||
@@ -322,8 +304,7 @@ private:
|
||||
return nonClickableCategory + wrapInLink(clickableText, targetId);
|
||||
}
|
||||
|
||||
QString generateTargetId(const QString &targetPrefix,
|
||||
const ClangBackEnd::DiagnosticContainer &diagnostic)
|
||||
QString generateTargetId(const QString &targetPrefix, const ClangDiagnostic &diagnostic)
|
||||
{
|
||||
const QString idAsString = QString::number(++m_targetIdCounter);
|
||||
const QString targetId = targetPrefix + idAsString;
|
||||
@@ -364,7 +345,7 @@ private:
|
||||
private:
|
||||
const DisplayHints m_displayHints;
|
||||
|
||||
using TargetIdToDiagnosticTable = QHash<QString, ClangBackEnd::DiagnosticContainer>;
|
||||
using TargetIdToDiagnosticTable = QHash<QString, ClangDiagnostic>;
|
||||
TargetIdToDiagnosticTable m_targetIdsToDiagnostics;
|
||||
unsigned m_targetIdCounter = 0;
|
||||
|
||||
@@ -399,7 +380,7 @@ WidgetFromDiagnostics::DisplayHints toHints(const ClangDiagnosticWidget::Destina
|
||||
} // anonymous namespace
|
||||
|
||||
QString ClangDiagnosticWidget::createText(
|
||||
const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics,
|
||||
const QList<ClangDiagnostic> &diagnostics,
|
||||
const ClangDiagnosticWidget::Destination &destination)
|
||||
{
|
||||
const QString htmlText = WidgetFromDiagnostics(toHints(destination, {}))
|
||||
@@ -418,7 +399,7 @@ QString ClangDiagnosticWidget::createText(
|
||||
}
|
||||
|
||||
QWidget *ClangDiagnosticWidget::createWidget(
|
||||
const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics,
|
||||
const QList<ClangDiagnostic> &diagnostics,
|
||||
const Destination &destination, const std::function<bool()> &canApplyFixIt,
|
||||
const QString &source)
|
||||
{
|
||||
|
@@ -25,7 +25,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <clangsupport/diagnosticcontainer.h>
|
||||
#include <QtGlobal>
|
||||
|
||||
#include <functional>
|
||||
|
||||
@@ -36,16 +36,17 @@ QT_END_NAMESPACE
|
||||
|
||||
namespace ClangCodeModel {
|
||||
namespace Internal {
|
||||
class ClangDiagnostic;
|
||||
|
||||
class ClangDiagnosticWidget {
|
||||
public:
|
||||
enum Destination { ToolTip, InfoBar };
|
||||
|
||||
static QString createText(const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics,
|
||||
static QString createText(const QList<ClangDiagnostic> &diagnostics,
|
||||
const Destination &destination);
|
||||
|
||||
|
||||
static QWidget *createWidget(const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics,
|
||||
static QWidget *createWidget(const QList<ClangDiagnostic> &diagnostics,
|
||||
const Destination &destination,
|
||||
const std::function<bool()> &canApplyFixIt,
|
||||
const QString &source);
|
||||
|
@@ -34,14 +34,11 @@
|
||||
namespace ClangCodeModel {
|
||||
namespace Internal {
|
||||
|
||||
using FileToFixits = QMap<QString, QVector<ClangBackEnd::FixItContainer>>;
|
||||
using FileToFixits = QMap<QString, QList<ClangFixIt>>;
|
||||
using RefactoringFilePtr = QSharedPointer<TextEditor::RefactoringFile>;
|
||||
|
||||
ClangFixItOperation::ClangFixItOperation(
|
||||
const Utf8String &fixItText,
|
||||
const QVector<ClangBackEnd::FixItContainer> &fixItContainers)
|
||||
: fixItText(fixItText)
|
||||
, fixItContainers(fixItContainers)
|
||||
ClangFixItOperation::ClangFixItOperation(const QString &fixItText, const QList<ClangFixIt> &fixIts)
|
||||
: fixItText(fixItText), fixIts(fixIts)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -52,16 +49,16 @@ int ClangFixItOperation::priority() const
|
||||
|
||||
QString ClangFixItOperation::description() const
|
||||
{
|
||||
return QStringLiteral("Apply Fix: ") + fixItText.toString();
|
||||
return QStringLiteral("Apply Fix: ") + fixItText;
|
||||
}
|
||||
|
||||
static FileToFixits fixitsPerFile(const QVector<ClangBackEnd::FixItContainer> &fixItContainers)
|
||||
static FileToFixits fixitsPerFile(const QList<ClangFixIt> &fixIts)
|
||||
{
|
||||
FileToFixits mapping;
|
||||
|
||||
for (const auto &fixItContainer : fixItContainers) {
|
||||
const QString rangeStartFilePath = fixItContainer.range.start.filePath.toString();
|
||||
const QString rangeEndFilePath = fixItContainer.range.end.filePath.toString();
|
||||
for (const auto &fixItContainer : fixIts) {
|
||||
const QString rangeStartFilePath = fixItContainer.range.start.targetFilePath.toString();
|
||||
const QString rangeEndFilePath = fixItContainer.range.end.targetFilePath.toString();
|
||||
QTC_CHECK(rangeStartFilePath == rangeEndFilePath);
|
||||
mapping[rangeStartFilePath].append(fixItContainer);
|
||||
}
|
||||
@@ -72,11 +69,11 @@ static FileToFixits fixitsPerFile(const QVector<ClangBackEnd::FixItContainer> &f
|
||||
void ClangFixItOperation::perform()
|
||||
{
|
||||
const TextEditor::RefactoringChanges refactoringChanges;
|
||||
const FileToFixits fileToFixIts = fixitsPerFile(fixItContainers);
|
||||
const FileToFixits fileToFixIts = fixitsPerFile(fixIts);
|
||||
|
||||
for (auto i = fileToFixIts.cbegin(), end = fileToFixIts.cend(); i != end; ++i) {
|
||||
const QString filePath = i.key();
|
||||
const QVector<ClangBackEnd::FixItContainer> fixits = i.value();
|
||||
const QList<ClangFixIt> fixits = i.value();
|
||||
|
||||
RefactoringFilePtr refactoringFile = refactoringChanges.file(
|
||||
Utils::FilePath::fromString(filePath));
|
||||
@@ -91,11 +88,10 @@ QString ClangFixItOperation::firstRefactoringFileContent_forTestOnly() const
|
||||
return refactoringFiles.first()->document()->toPlainText();
|
||||
}
|
||||
|
||||
void ClangFixItOperation::applyFixitsToFile(
|
||||
TextEditor::RefactoringFile &refactoringFile,
|
||||
const QVector<ClangBackEnd::FixItContainer> fixItContainers)
|
||||
void ClangFixItOperation::applyFixitsToFile(TextEditor::RefactoringFile &refactoringFile,
|
||||
const QList<ClangFixIt> fixIts)
|
||||
{
|
||||
const Utils::ChangeSet changeSet = toChangeSet(refactoringFile, fixItContainers);
|
||||
const Utils::ChangeSet changeSet = toChangeSet(refactoringFile, fixIts);
|
||||
|
||||
refactoringFile.setChangeSet(changeSet);
|
||||
refactoringFile.apply();
|
||||
@@ -103,16 +99,16 @@ void ClangFixItOperation::applyFixitsToFile(
|
||||
|
||||
Utils::ChangeSet ClangFixItOperation::toChangeSet(
|
||||
TextEditor::RefactoringFile &refactoringFile,
|
||||
const QVector<ClangBackEnd::FixItContainer> fixItContainers) const
|
||||
const QList<ClangFixIt> fixIts) const
|
||||
{
|
||||
Utils::ChangeSet changeSet;
|
||||
|
||||
for (const auto &fixItContainer : fixItContainers) {
|
||||
for (const auto &fixItContainer : fixIts) {
|
||||
const auto &range = fixItContainer.range;
|
||||
const auto &start = range.start;
|
||||
const auto &end = range.end;
|
||||
changeSet.replace(refactoringFile.position(start.line, start.column),
|
||||
refactoringFile.position(end.line, end.column),
|
||||
changeSet.replace(refactoringFile.position(start.targetLine, start.targetColumn + 1),
|
||||
refactoringFile.position(end.targetLine, end.targetColumn + 1),
|
||||
fixItContainer.text);
|
||||
}
|
||||
|
||||
|
@@ -25,9 +25,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <texteditor/quickfix.h>
|
||||
#include "clangutils.h"
|
||||
|
||||
#include <clangsupport/fixitcontainer.h>
|
||||
#include <texteditor/quickfix.h>
|
||||
|
||||
#include <utils/changeset.h>
|
||||
|
||||
@@ -45,8 +45,7 @@ namespace Internal {
|
||||
class ClangFixItOperation : public TextEditor::QuickFixOperation
|
||||
{
|
||||
public:
|
||||
ClangFixItOperation(const Utf8String &fixItText,
|
||||
const QVector<ClangBackEnd::FixItContainer> &fixItContainers);
|
||||
ClangFixItOperation(const QString &fixItText, const QList<ClangFixIt> &fixIts);
|
||||
|
||||
int priority() const override;
|
||||
QString description() const override;
|
||||
@@ -56,15 +55,14 @@ public:
|
||||
|
||||
private:
|
||||
void applyFixitsToFile(TextEditor::RefactoringFile &refactoringFile,
|
||||
const QVector<ClangBackEnd::FixItContainer> fixItContainers);
|
||||
::Utils::ChangeSet toChangeSet(
|
||||
TextEditor::RefactoringFile &refactoringFile,
|
||||
const QVector<ClangBackEnd::FixItContainer> fixItContainers) const;
|
||||
const QList<ClangFixIt> fixIts);
|
||||
Utils::ChangeSet toChangeSet(TextEditor::RefactoringFile &refactoringFile,
|
||||
const QList<ClangFixIt> fixIts) const;
|
||||
|
||||
private:
|
||||
Utf8String fixItText;
|
||||
QString fixItText;
|
||||
QVector<QSharedPointer<TextEditor::RefactoringFile>> refactoringFiles;
|
||||
QVector<ClangBackEnd::FixItContainer> fixItContainers;
|
||||
QList<ClangFixIt> fixIts;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -29,11 +29,10 @@
|
||||
#include "clangutils.h"
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/link.h>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
using ClangBackEnd::DiagnosticContainer;
|
||||
|
||||
namespace ClangCodeModel {
|
||||
namespace Internal {
|
||||
|
||||
@@ -60,38 +59,35 @@ QString tweakedDiagnosticText(const QString &diagnosticText)
|
||||
return tweakedText;
|
||||
}
|
||||
|
||||
bool hasFixItAt(const QVector<ClangBackEnd::FixItContainer> &fixits,
|
||||
const Utf8String &filePath,
|
||||
int line)
|
||||
bool hasFixItAt(const QList<ClangFixIt> &fixits, const QString &filePath, int line)
|
||||
{
|
||||
const auto isFixitForLocation = [filePath, line] (const ClangBackEnd::FixItContainer &fixit) {
|
||||
const ClangBackEnd::SourceLocationContainer &location = fixit.range.start;
|
||||
return location.filePath == filePath && location.line == line;
|
||||
const auto isFixitForLocation = [filePath, line] (const ClangFixIt &fixit) {
|
||||
const Utils::Link &location = fixit.range.start;
|
||||
return location.targetFilePath.toString() == filePath && location.targetLine == line;
|
||||
};
|
||||
|
||||
return Utils::anyOf(fixits, isFixitForLocation);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
ClangFixItOperationsExtractor::ClangFixItOperationsExtractor(
|
||||
const QVector<DiagnosticContainer> &diagnosticContainers)
|
||||
: diagnosticContainers(diagnosticContainers)
|
||||
const QList<ClangDiagnostic> &diagnosticContainers)
|
||||
: diagnostics(diagnosticContainers)
|
||||
{
|
||||
}
|
||||
|
||||
TextEditor::QuickFixOperations
|
||||
ClangFixItOperationsExtractor::extract(const QString &filePath, int line)
|
||||
{
|
||||
foreach (const DiagnosticContainer &diagnosticContainer, diagnosticContainers)
|
||||
extractFromDiagnostic(diagnosticContainer, filePath, line);
|
||||
foreach (const ClangDiagnostic &diagnostic, diagnostics)
|
||||
extractFromDiagnostic(diagnostic, filePath, line);
|
||||
|
||||
return operations;
|
||||
}
|
||||
|
||||
void ClangFixItOperationsExtractor::appendFixitOperation(
|
||||
const QString &diagnosticText,
|
||||
const QVector<ClangBackEnd::FixItContainer> &fixits)
|
||||
const QList<ClangFixIt> &fixits)
|
||||
{
|
||||
if (!fixits.isEmpty()) {
|
||||
const QString diagnosticTextTweaked = tweakedDiagnosticText(diagnosticText);
|
||||
@@ -102,15 +98,14 @@ void ClangFixItOperationsExtractor::appendFixitOperation(
|
||||
}
|
||||
|
||||
void ClangFixItOperationsExtractor::extractFromDiagnostic(
|
||||
const DiagnosticContainer &diagnosticContainer,
|
||||
const ClangDiagnostic &diagnostic,
|
||||
const QString &filePath,
|
||||
int line)
|
||||
{
|
||||
const QVector<ClangBackEnd::FixItContainer> &fixIts = diagnosticContainer.fixIts;
|
||||
const QList<ClangFixIt> &fixIts = diagnostic.fixIts;
|
||||
if (hasFixItAt(fixIts, filePath, line)) {
|
||||
appendFixitOperation(diagnosticContainer.text.toString(), fixIts);
|
||||
|
||||
for (const auto &child : diagnosticContainer.children)
|
||||
appendFixitOperation(diagnostic.text, fixIts);
|
||||
for (const auto &child : diagnostic.children)
|
||||
extractFromDiagnostic(child, filePath, line);
|
||||
}
|
||||
}
|
||||
|
@@ -25,9 +25,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <texteditor/quickfix.h>
|
||||
#include "clangutils.h"
|
||||
|
||||
#include <clangsupport/diagnosticcontainer.h>
|
||||
#include <texteditor/quickfix.h>
|
||||
|
||||
namespace ClangCodeModel {
|
||||
namespace Internal {
|
||||
@@ -35,19 +35,19 @@ namespace Internal {
|
||||
class ClangFixItOperationsExtractor
|
||||
{
|
||||
public:
|
||||
ClangFixItOperationsExtractor(const QVector<ClangBackEnd::DiagnosticContainer> &diagnosticContainers);
|
||||
ClangFixItOperationsExtractor(const QList<ClangDiagnostic> &diagnosticContainers);
|
||||
|
||||
TextEditor::QuickFixOperations extract(const QString &filePath, int line);
|
||||
|
||||
private:
|
||||
void extractFromDiagnostic(const ClangBackEnd::DiagnosticContainer &diagnosticContainer,
|
||||
void extractFromDiagnostic(const ClangDiagnostic &diagnostic,
|
||||
const QString &filePath,
|
||||
int line);
|
||||
void appendFixitOperation(const QString &diagnosticText,
|
||||
const QVector<ClangBackEnd::FixItContainer> &fixits);
|
||||
const QList<ClangFixIt> &fixits);
|
||||
|
||||
private:
|
||||
const QVector<ClangBackEnd::DiagnosticContainer> &diagnosticContainers;
|
||||
const QList<ClangDiagnostic> &diagnostics;
|
||||
TextEditor::QuickFixOperations operations;
|
||||
};
|
||||
|
||||
|
@@ -62,7 +62,6 @@
|
||||
#include <projectexplorer/target.h>
|
||||
#include <projectexplorer/taskhub.h>
|
||||
|
||||
#include <clangsupport/filecontainer.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/runextensions.h>
|
||||
|
@@ -80,7 +80,7 @@ Project *projectForCurrentEditor()
|
||||
}
|
||||
|
||||
enum class DiagnosticType { Clang, Tidy, Clazy };
|
||||
DiagnosticType diagnosticType(const ClangBackEnd::DiagnosticContainer &diagnostic)
|
||||
DiagnosticType diagnosticType(const ClangDiagnostic &diagnostic)
|
||||
|
||||
{
|
||||
if (!diagnostic.disableOption.isEmpty())
|
||||
@@ -92,8 +92,7 @@ DiagnosticType diagnosticType(const ClangBackEnd::DiagnosticContainer &diagnosti
|
||||
return DiagnosticType::Tidy;
|
||||
}
|
||||
|
||||
void disableDiagnosticInConfig(ClangDiagnosticConfig &config,
|
||||
const ClangBackEnd::DiagnosticContainer &diagnostic)
|
||||
void disableDiagnosticInConfig(ClangDiagnosticConfig &config, const ClangDiagnostic &diagnostic)
|
||||
{
|
||||
switch (diagnosticType(diagnostic)) {
|
||||
case DiagnosticType::Clang:
|
||||
@@ -131,8 +130,7 @@ ClangDiagnosticConfig diagnosticConfig(const ClangProjectSettings &projectSettin
|
||||
return configsModel.configWithId(currentConfigId);
|
||||
}
|
||||
|
||||
bool isDiagnosticConfigChangable(Project *project,
|
||||
const ClangBackEnd::DiagnosticContainer &diagnostic)
|
||||
bool isDiagnosticConfigChangable(Project *project, const ClangDiagnostic &diagnostic)
|
||||
{
|
||||
if (!project)
|
||||
return false;
|
||||
@@ -149,7 +147,7 @@ bool isDiagnosticConfigChangable(Project *project,
|
||||
return true;
|
||||
}
|
||||
|
||||
void disableDiagnosticInCurrentProjectConfig(const ClangBackEnd::DiagnosticContainer &diagnostic)
|
||||
void disableDiagnosticInCurrentProjectConfig(const ClangDiagnostic &diagnostic)
|
||||
{
|
||||
Project *project = projectForCurrentEditor();
|
||||
QTC_ASSERT(project, return );
|
||||
@@ -194,30 +192,26 @@ void disableDiagnosticInCurrentProjectConfig(const ClangBackEnd::DiagnosticConta
|
||||
FadingIndicator::SmallText);
|
||||
}
|
||||
|
||||
ClangBackEnd::DiagnosticSeverity convertSeverity(DiagnosticSeverity src)
|
||||
ClangDiagnostic::Severity convertSeverity(DiagnosticSeverity src)
|
||||
{
|
||||
if (src == DiagnosticSeverity::Error)
|
||||
return ClangBackEnd::DiagnosticSeverity::Error;
|
||||
return ClangDiagnostic::Severity::Error;
|
||||
if (src == DiagnosticSeverity::Warning)
|
||||
return ClangBackEnd::DiagnosticSeverity::Warning;
|
||||
return ClangBackEnd::DiagnosticSeverity::Note;
|
||||
return ClangDiagnostic::Severity::Warning;
|
||||
return ClangDiagnostic::Severity::Note;
|
||||
}
|
||||
|
||||
ClangBackEnd::SourceRangeContainer convertRange(const FilePath &filePath, const Range &src)
|
||||
ClangSourceRange convertRange(const FilePath &filePath, const Range &src)
|
||||
{
|
||||
const ClangBackEnd::SourceLocationContainer start(filePath.toString(), src.start().line() + 1,
|
||||
src.start().character() + 1);
|
||||
const ClangBackEnd::SourceLocationContainer end(filePath.toString(), src.end().line() + 1,
|
||||
src.end().character() + 1);
|
||||
return ClangBackEnd::SourceRangeContainer(start, end);
|
||||
const Utils::Link start(filePath, src.start().line() + 1, src.start().character());
|
||||
const Utils::Link end(filePath, src.end().line() + 1, src.end().character());
|
||||
return ClangSourceRange(start, end);
|
||||
}
|
||||
|
||||
ClangBackEnd::DiagnosticContainer convertDiagnostic(const ClangdDiagnostic &src,
|
||||
const FilePath &filePath)
|
||||
ClangDiagnostic convertDiagnostic(const ClangdDiagnostic &src, const FilePath &filePath)
|
||||
{
|
||||
ClangBackEnd::DiagnosticContainer target;
|
||||
target.ranges.append(convertRange(filePath, src.range()));
|
||||
target.location = target.ranges.first().start;
|
||||
ClangDiagnostic target;
|
||||
target.location = convertRange(filePath, src.range()).start;
|
||||
const QStringList messages = src.message().split("\n\n", Qt::SkipEmptyParts);
|
||||
if (!messages.isEmpty())
|
||||
target.text = messages.first();
|
||||
@@ -230,7 +224,7 @@ ClangBackEnd::DiagnosticContainer convertDiagnostic(const ClangdDiagnostic &src,
|
||||
"^(<command line>|([A-Za-z]:)?[^:]+\\.[^:]+)"
|
||||
"(:(\\d+):(\\d+)|\\((\\d+)\\) *): +(fatal +)?(error|warning|note): (.*)$");
|
||||
|
||||
ClangBackEnd::DiagnosticContainer aux;
|
||||
ClangDiagnostic aux;
|
||||
if (const QRegularExpressionMatch match = msgRegex.match(auxMessage); match.hasMatch()) {
|
||||
bool ok = false;
|
||||
int line = match.captured(4).toInt(&ok);
|
||||
@@ -242,17 +236,17 @@ ClangBackEnd::DiagnosticContainer convertDiagnostic(const ClangdDiagnostic &src,
|
||||
FilePath auxFilePath = FilePath::fromUserInput(match.captured(1));
|
||||
if (auxFilePath.isRelativePath() && auxFilePath.fileName() == filePath.fileName())
|
||||
auxFilePath = filePath;
|
||||
aux.location = {auxFilePath.toString(), line, column};
|
||||
aux.location = {auxFilePath, line, column - 1};
|
||||
aux.text = match.captured(9);
|
||||
const QString type = match.captured(8);
|
||||
if (type == "fatal")
|
||||
aux.severity = ClangBackEnd::DiagnosticSeverity::Fatal;
|
||||
aux.severity = ClangDiagnostic::Severity::Fatal;
|
||||
else if (type == "error")
|
||||
aux.severity = ClangBackEnd::DiagnosticSeverity::Error;
|
||||
aux.severity = ClangDiagnostic::Severity::Error;
|
||||
else if (type == "warning")
|
||||
aux.severity = ClangBackEnd::DiagnosticSeverity::Warning;
|
||||
aux.severity = ClangDiagnostic::Severity::Warning;
|
||||
else if (type == "note")
|
||||
aux.severity = ClangBackEnd::DiagnosticSeverity::Note;
|
||||
aux.severity = ClangDiagnostic::Severity::Note;
|
||||
} else {
|
||||
aux.text = auxMessage;
|
||||
}
|
||||
@@ -274,7 +268,7 @@ ClangBackEnd::DiagnosticContainer convertDiagnostic(const ClangdDiagnostic &src,
|
||||
continue;
|
||||
for (auto it = changes->cbegin(); it != changes->cend(); ++it) {
|
||||
for (const TextEdit &textEdit : it.value()) {
|
||||
target.fixIts << ClangBackEnd::FixItContainer(textEdit.newText(),
|
||||
target.fixIts << ClangFixIt(textEdit.newText(),
|
||||
convertRange(it.key().toFilePath(), textEdit.range()));
|
||||
}
|
||||
}
|
||||
@@ -282,18 +276,18 @@ ClangBackEnd::DiagnosticContainer convertDiagnostic(const ClangdDiagnostic &src,
|
||||
return target;
|
||||
}
|
||||
|
||||
void addTask(const ClangBackEnd::DiagnosticContainer &diagnostic)
|
||||
void addTask(const ClangDiagnostic &diagnostic)
|
||||
{
|
||||
Task::TaskType taskType = Task::TaskType::Unknown;
|
||||
QIcon icon;
|
||||
|
||||
switch (diagnostic.severity) {
|
||||
case ClangBackEnd::DiagnosticSeverity::Fatal:
|
||||
case ClangBackEnd::DiagnosticSeverity::Error:
|
||||
case ClangDiagnostic::Severity::Fatal:
|
||||
case ClangDiagnostic::Severity::Error:
|
||||
taskType = Task::TaskType::Error;
|
||||
icon = ::Utils::Icons::CODEMODEL_ERROR.icon();
|
||||
break;
|
||||
case ClangBackEnd::DiagnosticSeverity::Warning:
|
||||
case ClangDiagnostic::Severity::Warning:
|
||||
taskType = Task::TaskType::Warning;
|
||||
icon = ::Utils::Icons::CODEMODEL_WARNING.icon();
|
||||
break;
|
||||
@@ -302,9 +296,9 @@ void addTask(const ClangBackEnd::DiagnosticContainer &diagnostic)
|
||||
}
|
||||
|
||||
TaskHub::addTask(Task(taskType,
|
||||
diagnosticCategoryPrefixRemoved(diagnostic.text.toString()),
|
||||
FilePath::fromString(diagnostic.location.filePath.toString()),
|
||||
diagnostic.location.line,
|
||||
diagnosticCategoryPrefixRemoved(diagnostic.text),
|
||||
FilePath::fromString(diagnostic.location.targetFilePath.toString()),
|
||||
diagnostic.location.targetLine,
|
||||
Constants::TASK_CATEGORY_DIAGNOSTICS,
|
||||
icon,
|
||||
Task::NoOptions));
|
||||
|
@@ -25,8 +25,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <clangsupport_global.h>
|
||||
#include <clangsupport/diagnosticcontainer.h>
|
||||
#include "clangutils.h"
|
||||
|
||||
#include <languageserverprotocol/lsptypes.h>
|
||||
|
||||
@@ -54,7 +53,7 @@ private:
|
||||
bool addToolTipContent(QLayout *target) const override;
|
||||
|
||||
const LanguageServerProtocol::Diagnostic m_lspDiagnostic;
|
||||
const ClangBackEnd::DiagnosticContainer m_diagnostic;
|
||||
const ClangDiagnostic m_diagnostic;
|
||||
const QPointer<const LanguageClient::Client> m_client;
|
||||
};
|
||||
|
||||
|
@@ -29,8 +29,6 @@
|
||||
#include "clangmodelmanagersupport.h"
|
||||
#include "clangprojectsettings.h"
|
||||
|
||||
#include <clangsupport/tokeninfocontainer.h>
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/idocument.h>
|
||||
#include <cppeditor/baseeditordocumentparser.h>
|
||||
@@ -170,109 +168,6 @@ int cppEditorColumn(const QTextBlock &line, int clangColumn)
|
||||
return QString::fromUtf8(line.text().toUtf8().left(clangColumn - 1)).size() + 1;
|
||||
}
|
||||
|
||||
CodeModelIcon::Type iconTypeForToken(const ClangBackEnd::TokenInfoContainer &token)
|
||||
{
|
||||
const ClangBackEnd::ExtraInfo &extraInfo = token.extraInfo;
|
||||
if (extraInfo.signal)
|
||||
return CodeModelIcon::Signal;
|
||||
|
||||
ClangBackEnd::AccessSpecifier access = extraInfo.accessSpecifier;
|
||||
if (extraInfo.slot) {
|
||||
switch (access) {
|
||||
case ClangBackEnd::AccessSpecifier::Public:
|
||||
case ClangBackEnd::AccessSpecifier::Invalid:
|
||||
return CodeModelIcon::SlotPublic;
|
||||
case ClangBackEnd::AccessSpecifier::Protected:
|
||||
return CodeModelIcon::SlotProtected;
|
||||
case ClangBackEnd::AccessSpecifier::Private:
|
||||
return CodeModelIcon::SlotPrivate;
|
||||
}
|
||||
}
|
||||
|
||||
ClangBackEnd::HighlightingType mainType = token.types.mainHighlightingType;
|
||||
|
||||
if (mainType == ClangBackEnd::HighlightingType::QtProperty)
|
||||
return CodeModelIcon::Property;
|
||||
|
||||
if (mainType == ClangBackEnd::HighlightingType::PreprocessorExpansion
|
||||
|| mainType == ClangBackEnd::HighlightingType::PreprocessorDefinition) {
|
||||
return CodeModelIcon::Macro;
|
||||
}
|
||||
|
||||
if (mainType == ClangBackEnd::HighlightingType::Enumeration)
|
||||
return CodeModelIcon::Enumerator;
|
||||
|
||||
if (mainType == ClangBackEnd::HighlightingType::Type
|
||||
|| mainType == ClangBackEnd::HighlightingType::Keyword) {
|
||||
const ClangBackEnd::MixinHighlightingTypes &types = token.types.mixinHighlightingTypes;
|
||||
if (types.contains(ClangBackEnd::HighlightingType::Enum))
|
||||
return CodeModelIcon::Enum;
|
||||
if (types.contains(ClangBackEnd::HighlightingType::Struct))
|
||||
return CodeModelIcon::Struct;
|
||||
if (types.contains(ClangBackEnd::HighlightingType::Namespace))
|
||||
return CodeModelIcon::Namespace;
|
||||
if (types.contains(ClangBackEnd::HighlightingType::Class))
|
||||
return CodeModelIcon::Class;
|
||||
if (mainType == ClangBackEnd::HighlightingType::Keyword)
|
||||
return CodeModelIcon::Keyword;
|
||||
return CodeModelIcon::Class;
|
||||
}
|
||||
|
||||
ClangBackEnd::StorageClass storageClass = extraInfo.storageClass;
|
||||
if (mainType == ClangBackEnd::HighlightingType::VirtualFunction
|
||||
|| mainType == ClangBackEnd::HighlightingType::Function
|
||||
|| token.types.mixinHighlightingTypes.contains(
|
||||
ClangBackEnd::HighlightingType::Operator)) {
|
||||
if (storageClass != ClangBackEnd::StorageClass::Static) {
|
||||
switch (access) {
|
||||
case ClangBackEnd::AccessSpecifier::Public:
|
||||
case ClangBackEnd::AccessSpecifier::Invalid:
|
||||
return CodeModelIcon::FuncPublic;
|
||||
case ClangBackEnd::AccessSpecifier::Protected:
|
||||
return CodeModelIcon::FuncProtected;
|
||||
case ClangBackEnd::AccessSpecifier::Private:
|
||||
return CodeModelIcon::FuncPrivate;
|
||||
}
|
||||
} else {
|
||||
switch (access) {
|
||||
case ClangBackEnd::AccessSpecifier::Public:
|
||||
case ClangBackEnd::AccessSpecifier::Invalid:
|
||||
return CodeModelIcon::FuncPublicStatic;
|
||||
case ClangBackEnd::AccessSpecifier::Protected:
|
||||
return CodeModelIcon::FuncProtectedStatic;
|
||||
case ClangBackEnd::AccessSpecifier::Private:
|
||||
return CodeModelIcon::FuncPrivateStatic;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mainType == ClangBackEnd::HighlightingType::GlobalVariable
|
||||
|| mainType == ClangBackEnd::HighlightingType::Field) {
|
||||
if (storageClass != ClangBackEnd::StorageClass::Static) {
|
||||
switch (access) {
|
||||
case ClangBackEnd::AccessSpecifier::Public:
|
||||
case ClangBackEnd::AccessSpecifier::Invalid:
|
||||
return CodeModelIcon::VarPublic;
|
||||
case ClangBackEnd::AccessSpecifier::Protected:
|
||||
return CodeModelIcon::VarProtected;
|
||||
case ClangBackEnd::AccessSpecifier::Private:
|
||||
return CodeModelIcon::VarPrivate;
|
||||
}
|
||||
} else {
|
||||
switch (access) {
|
||||
case ClangBackEnd::AccessSpecifier::Public:
|
||||
case ClangBackEnd::AccessSpecifier::Invalid:
|
||||
return CodeModelIcon::VarPublicStatic;
|
||||
case ClangBackEnd::AccessSpecifier::Protected:
|
||||
return CodeModelIcon::VarProtectedStatic;
|
||||
case ClangBackEnd::AccessSpecifier::Private:
|
||||
return CodeModelIcon::VarPrivateStatic;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return CodeModelIcon::Unknown;
|
||||
}
|
||||
|
||||
QString diagnosticCategoryPrefixRemoved(const QString &text)
|
||||
{
|
||||
QString theText = text;
|
||||
|
@@ -30,6 +30,8 @@
|
||||
#include <cppeditor/projectinfo.h>
|
||||
#include <cppeditor/compileroptionsbuilder.h>
|
||||
|
||||
#include <utils/link.h>
|
||||
|
||||
#include <QPair>
|
||||
#include <QTextCursor>
|
||||
|
||||
@@ -72,8 +74,6 @@ QString currentCppEditorDocumentFilePath();
|
||||
|
||||
QString diagnosticCategoryPrefixRemoved(const QString &text);
|
||||
|
||||
Utils::CodeModelIcon::Type iconTypeForToken(const ClangBackEnd::TokenInfoContainer &token);
|
||||
|
||||
class GenerateCompilationDbResult
|
||||
{
|
||||
public:
|
||||
@@ -159,5 +159,74 @@ QString textUntilPreviousStatement(TextEditor::TextDocumentManipulatorInterface
|
||||
bool isAtUsingDeclaration(TextEditor::TextDocumentManipulatorInterface &manipulator,
|
||||
int basePosition);
|
||||
|
||||
class ClangSourceRange
|
||||
{
|
||||
public:
|
||||
ClangSourceRange(const Utils::Link &start, const Utils::Link &end) : start(start), end(end) {}
|
||||
|
||||
bool contains(int line, int column) const
|
||||
{
|
||||
if (line < start.targetLine || line > end.targetLine)
|
||||
return false;
|
||||
if (line == start.targetLine && column < start.targetLine)
|
||||
return false;
|
||||
if (line == end.targetLine && column > end.targetColumn)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool contains(const Utils::Link &sourceLocation) const
|
||||
{
|
||||
return contains(sourceLocation.targetLine, sourceLocation.targetColumn);
|
||||
}
|
||||
|
||||
Utils::Link start;
|
||||
Utils::Link end;
|
||||
};
|
||||
|
||||
inline bool operator==(const ClangSourceRange &first, const ClangSourceRange &second)
|
||||
{
|
||||
return first.start == second.start && first.end == second.end;
|
||||
}
|
||||
|
||||
class ClangFixIt
|
||||
{
|
||||
public:
|
||||
ClangFixIt(const QString &text, const ClangSourceRange &range) : range(range), text(text) {}
|
||||
|
||||
ClangSourceRange range;
|
||||
QString text;
|
||||
};
|
||||
|
||||
inline bool operator==(const ClangFixIt &first, const ClangFixIt &second)
|
||||
{
|
||||
return first.text == second.text && first.range == second.range;
|
||||
}
|
||||
|
||||
class ClangDiagnostic
|
||||
{
|
||||
public:
|
||||
enum class Severity { Ignored, Note, Warning, Error, Fatal };
|
||||
|
||||
Utils::Link location;
|
||||
QString text;
|
||||
QString category;
|
||||
QString enableOption;
|
||||
QString disableOption;
|
||||
QList<ClangDiagnostic> children;
|
||||
QList<ClangFixIt> fixIts;
|
||||
Severity severity = Severity::Ignored;
|
||||
};
|
||||
|
||||
inline bool operator==(const ClangDiagnostic &first, const ClangDiagnostic &second)
|
||||
{
|
||||
return first.text == second.text && first.location == second.location;
|
||||
}
|
||||
inline bool operator!=(const ClangDiagnostic &first, const ClangDiagnostic &second)
|
||||
{
|
||||
return !(first == second);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Clang
|
||||
|
@@ -55,7 +55,6 @@
|
||||
#include <QString>
|
||||
#include <QThread>
|
||||
|
||||
using namespace ClangBackEnd;
|
||||
using namespace ProjectExplorer;
|
||||
|
||||
namespace ClangCodeModel {
|
||||
|
@@ -29,7 +29,6 @@
|
||||
#include "../clangdclient.h"
|
||||
#include "../clangmodelmanagersupport.h"
|
||||
|
||||
#include <clangsupport/sourcelocationscontainer.h>
|
||||
#include <cplusplus/FindUsages.h>
|
||||
#include <cppeditor/cppcodemodelsettings.h>
|
||||
#include <cppeditor/cpptoolsreuse.h>
|
||||
@@ -419,9 +418,9 @@ void ClangdTestLocalReferences::test_data()
|
||||
QTest::addColumn<QList<Range>>("expectedRanges");
|
||||
|
||||
QTest::newRow("cursor not on identifier") << 3 << 5 << QList<Range>();
|
||||
QTest::newRow("local variable, one use") << 3 << 9 << QList<Range>{{3, 9, 3}};
|
||||
QTest::newRow("local variable, one use") << 3 << 9 << QList<Range>{{3, 8, 3}};
|
||||
QTest::newRow("local variable, two uses") << 10 << 9
|
||||
<< QList<Range>{{10, 9, 3}, {11, 12, 3}};
|
||||
<< QList<Range>{{10, 8, 3}, {11, 11, 3}};
|
||||
QTest::newRow("class name") << 16 << 7 << QList<Range>()
|
||||
/* QList<Range>{{16, 7, 3}, {19, 5, 3}} */;
|
||||
QTest::newRow("namespace") << 24 << 11 << QList<Range>()
|
||||
@@ -433,9 +432,9 @@ void ClangdTestLocalReferences::test_data()
|
||||
QTest::newRow("class name and new expression") << 40 << 7 << QList<Range>()
|
||||
/* QList<Range>{{40, 7, 3}, {43, 9, 3}} */;
|
||||
QTest::newRow("instantiated template object") << 52 << 19
|
||||
<< QList<Range>{{52, 19, 3}, {53, 5, 3}};
|
||||
<< QList<Range>{{52, 18, 3}, {53, 4, 3}};
|
||||
QTest::newRow("variable in template") << 62 << 13
|
||||
<< QList<Range>{{62, 13, 3}, {63, 11, 3}};
|
||||
<< QList<Range>{{62, 12, 3}, {63, 10, 3}};
|
||||
QTest::newRow("member in template") << 67 << 7 << QList<Range>()
|
||||
/* QList<Range>{{64, 16, 3}, {67, 7, 3}} */;
|
||||
QTest::newRow("template type") << 58 << 19 << QList<Range>()
|
||||
@@ -454,9 +453,9 @@ void ClangdTestLocalReferences::test_data()
|
||||
QTest::newRow("enum type") << 112 << 6 << QList<Range>()
|
||||
/* QList<Range>{{112, 6, 2}, {113, 8, 2}} */;
|
||||
QTest::newRow("captured lambda var") << 122 << 15
|
||||
<< QList<Range>{{122, 15, 3}, {122, 33, 3}};
|
||||
<< QList<Range>{{122, 14, 3}, {122, 32, 3}};
|
||||
QTest::newRow("lambda initializer") << 122 << 19
|
||||
<< QList<Range>{{121, 19, 3}, {122, 19, 3}};
|
||||
<< QList<Range>{{121, 18, 3}, {122, 18, 3}};
|
||||
QTest::newRow("template specialization") << 127 << 25 << QList<Range>()
|
||||
/* QList<Range>{{127, 5, 3}, {128, 25, 3}, {129, 18, 3}} */;
|
||||
QTest::newRow("dependent name") << 133 << 34 << QList<Range>()
|
||||
@@ -468,16 +467,16 @@ void ClangdTestLocalReferences::test_data()
|
||||
QTest::newRow("function-like macro") << 155 << 9 << QList<Range>()
|
||||
/* QList<Range>{{155, 9, 3}, {158, 12, 3}} */;
|
||||
QTest::newRow("argument to function-like macro") << 156 << 27
|
||||
<< QList<Range>{{156, 27, 3}, {158, 16, 3}};
|
||||
<< QList<Range>{{156, 26, 3}, {158, 15, 3}};
|
||||
QTest::newRow("overloaded bracket operator argument") << 172 << 7
|
||||
<< QList<Range>{{171, 7, 1}, {172, 7, 1}, {172, 12, 1},
|
||||
{173, 7, 1}, {173, 10, 1}};
|
||||
<< QList<Range>{{171, 6, 1}, {172, 6, 1}, {172, 11, 1},
|
||||
{173, 6, 1}, {173, 9, 1}};
|
||||
QTest::newRow("overloaded call operator second argument") << 173 << 10
|
||||
<< QList<Range>{{171, 7, 1}, {172, 7, 1}, {172, 12, 1},
|
||||
{173, 7, 1}, {173, 10, 1}};
|
||||
<< QList<Range>{{171, 6, 1}, {172, 6, 1}, {172, 11, 1},
|
||||
{173, 6, 1}, {173, 9, 1}};
|
||||
QTest::newRow("overloaded operators arguments from outside") << 171 << 7
|
||||
<< QList<Range>{{171, 7, 1}, {172, 7, 1}, {172, 12, 1},
|
||||
{173, 7, 1}, {173, 10, 1}};
|
||||
<< QList<Range>{{171, 6, 1}, {172, 6, 1}, {172, 11, 1},
|
||||
{173, 6, 1}, {173, 9, 1}};
|
||||
}
|
||||
|
||||
void ClangdTestLocalReferences::test()
|
||||
@@ -495,11 +494,9 @@ void ClangdTestLocalReferences::test()
|
||||
QObject::connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
|
||||
QList<Range> actualRanges;
|
||||
const auto handler = [&actualRanges, &loop](const QString &symbol,
|
||||
const ClangBackEnd::SourceLocationsContainer &container, int) {
|
||||
for (const ClangBackEnd::SourceLocationContainer &c
|
||||
: container.m_sourceLocationContainers) {
|
||||
actualRanges << Range(c.line, c.column, symbol.length());
|
||||
}
|
||||
const Utils::Links &links, int) {
|
||||
for (const Utils::Link &link : links)
|
||||
actualRanges << Range(link.targetLine, link.targetColumn, symbol.length());
|
||||
loop.quit();
|
||||
};
|
||||
|
||||
|
@@ -27,15 +27,12 @@
|
||||
|
||||
#include "../clangfixitoperation.h"
|
||||
|
||||
#include <clangsupport/fixitcontainer.h>
|
||||
#include <utils/changeset.h>
|
||||
|
||||
#include <QFile>
|
||||
#include <QtTest>
|
||||
#include <QVector>
|
||||
|
||||
using ClangBackEnd::FixItContainer;
|
||||
|
||||
namespace ClangCodeModel::Internal::Tests {
|
||||
|
||||
static QString qrcPath(const QString &relativeFilePath)
|
||||
@@ -52,14 +49,14 @@ void ClangFixItTest::testDescription()
|
||||
QLatin1String("Apply Fix: expected ';' at end of declaration"));
|
||||
}
|
||||
|
||||
QString ClangFixItTest::semicolonFilePath() const
|
||||
Utils::FilePath ClangFixItTest::semicolonFilePath() const
|
||||
{
|
||||
return m_dataDir->absolutePath("diagnostic_semicolon_fixit.cpp");
|
||||
return Utils::FilePath::fromString(m_dataDir->absolutePath("diagnostic_semicolon_fixit.cpp"));
|
||||
}
|
||||
|
||||
QString ClangFixItTest::compareFilePath() const
|
||||
Utils::FilePath ClangFixItTest::compareFilePath() const
|
||||
{
|
||||
return m_dataDir->absolutePath("diagnostic_comparison_fixit.cpp");
|
||||
return Utils::FilePath::fromString(m_dataDir->absolutePath("diagnostic_comparison_fixit.cpp"));
|
||||
}
|
||||
|
||||
QString ClangFixItTest::fileContent(const QByteArray &relFilePath) const
|
||||
@@ -71,10 +68,9 @@ QString ClangFixItTest::fileContent(const QByteArray &relFilePath) const
|
||||
return QString::fromUtf8(file.readAll());
|
||||
}
|
||||
|
||||
FixItContainer ClangFixItTest::semicolonFixIt() const
|
||||
ClangFixIt ClangFixItTest::semicolonFixIt() const
|
||||
{
|
||||
return {Utf8StringLiteral(";"), {{semicolonFilePath(), 3u, 13u},
|
||||
{semicolonFilePath(), 3u, 13u}}};
|
||||
return {";", {{semicolonFilePath(), 3u, 12u}, {semicolonFilePath(), 3u, 12u}}};
|
||||
}
|
||||
|
||||
void ClangFixItTest::init()
|
||||
@@ -92,8 +88,8 @@ void ClangFixItTest::testAppendSemicolon()
|
||||
|
||||
void ClangFixItTest::testComparisonVersusAssignmentChooseComparison()
|
||||
{
|
||||
const FixItContainer compareFixIt{Utf8StringLiteral("=="), {{compareFilePath(), 4u, 11u},
|
||||
{compareFilePath(), 4u, 12u}}};
|
||||
const ClangFixIt compareFixIt{"==", {{compareFilePath(), 4u, 10u},
|
||||
{compareFilePath(), 4u, 11u}}};
|
||||
ClangFixItOperation operation(diagnosticText(), {compareFixIt});
|
||||
operation.perform();
|
||||
QCOMPARE(operation.firstRefactoringFileContent_forTestOnly(),
|
||||
@@ -102,10 +98,10 @@ void ClangFixItTest::testComparisonVersusAssignmentChooseComparison()
|
||||
|
||||
void ClangFixItTest::testComparisonVersusAssignmentChooseParentheses()
|
||||
{
|
||||
const FixItContainer assignmentFixItParenLeft{Utf8StringLiteral("("),
|
||||
{{compareFilePath(), 4u, 9u}, {compareFilePath(), 4u, 9u}}};
|
||||
const FixItContainer assignmentFixItParenRight{Utf8StringLiteral(")"),
|
||||
{{compareFilePath(), 4u, 14u}, {compareFilePath(), 4u, 14u}}};
|
||||
const ClangFixIt assignmentFixItParenLeft{"(", {{compareFilePath(), 4u, 8u},
|
||||
{compareFilePath(), 4u, 8u}}};
|
||||
const ClangFixIt assignmentFixItParenRight{")", {{compareFilePath(), 4u, 13u},
|
||||
{compareFilePath(), 4u, 13u}}};
|
||||
ClangFixItOperation operation(diagnosticText(), {assignmentFixItParenLeft,
|
||||
assignmentFixItParenRight});
|
||||
operation.perform();
|
||||
|
@@ -31,9 +31,12 @@
|
||||
#include <QScopedPointer>
|
||||
#include <QString>
|
||||
|
||||
namespace ClangBackEnd { class FixItContainer; }
|
||||
namespace Utils { class FilePath; }
|
||||
|
||||
namespace ClangCodeModel::Internal::Tests {
|
||||
namespace ClangCodeModel::Internal {
|
||||
class ClangFixIt;
|
||||
|
||||
namespace Tests {
|
||||
|
||||
class ClangFixItTest : public QObject
|
||||
{
|
||||
@@ -47,14 +50,15 @@ private slots:
|
||||
void testDescription();
|
||||
|
||||
private:
|
||||
QString semicolonFilePath() const;
|
||||
QString compareFilePath() const;
|
||||
Utils::FilePath semicolonFilePath() const;
|
||||
Utils::FilePath compareFilePath() const;
|
||||
QString fileContent(const QByteArray &relFilePath) const;
|
||||
|
||||
ClangBackEnd::FixItContainer semicolonFixIt() const;
|
||||
ClangFixIt semicolonFixIt() const;
|
||||
|
||||
private:
|
||||
QScopedPointer<CppEditor::Tests::TemporaryCopiedDir> m_dataDir;
|
||||
};
|
||||
|
||||
} // namespace ClangCodeModel::Internal::Tests
|
||||
} //namespace Tests
|
||||
} // namespace ClangCodeModel::Internal
|
||||
|
@@ -1,11 +1,17 @@
|
||||
find_package(yaml-cpp QUIET MODULE)
|
||||
|
||||
set(CLANG_VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH})
|
||||
|
||||
add_qtc_plugin(ClangTools
|
||||
CONDITION TARGET yaml-cpp
|
||||
DEPENDS ClangSupport yaml-cpp
|
||||
PLUGIN_DEPENDS Core Debugger CppEditor
|
||||
PLUGIN_RECOMMENDS CppEditor
|
||||
PLUGIN_TEST_DEPENDS QmakeProjectManager QbsProjectManager
|
||||
DEFINES
|
||||
CLANG_VERSION="${CLANG_VERSION}"
|
||||
CLANG_INCLUDE_DIR="${LLVM_LIBRARY_DIR}/clang/${CLANG_VERSION}/include"
|
||||
CLANG_BINDIR="${LLVM_TOOLS_BINARY_DIR}"
|
||||
INCLUDES ${CLANG_INCLUDE_DIRS}
|
||||
SOURCES
|
||||
clangfileinfo.h
|
||||
|
@@ -1,6 +1,6 @@
|
||||
add_qtc_plugin(CppEditor
|
||||
DEPENDS Qt5::Network Qt5::Xml
|
||||
PUBLIC_DEPENDS CPlusPlus ClangSupport Qt5::Widgets
|
||||
PUBLIC_DEPENDS CPlusPlus Qt5::Widgets
|
||||
PLUGIN_DEPENDS Core ProjectExplorer TextEditor
|
||||
PLUGIN_TEST_DEPENDS QbsProjectManager QmakeProjectManager
|
||||
SOURCES
|
||||
|
@@ -36,7 +36,6 @@
|
||||
#include "symbolfinder.h"
|
||||
|
||||
#include <app/app_version.h>
|
||||
#include <clangsupport/sourcelocationscontainer.h>
|
||||
#include <texteditor/basehoverhandler.h>
|
||||
#include <utils/executeondestruction.h>
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -164,14 +163,10 @@ void BuiltinModelManagerSupport::startLocalRenaming(const CursorInEditor &data,
|
||||
RenameCallback &&renameSymbolsCallback)
|
||||
{
|
||||
CppEditorWidget *editorWidget = data.editorWidget();
|
||||
QTC_ASSERT(editorWidget, renameSymbolsCallback(QString(),
|
||||
ClangBackEnd::SourceLocationsContainer(),
|
||||
0); return;);
|
||||
QTC_ASSERT(editorWidget, renameSymbolsCallback(QString(), {}, 0); return;);
|
||||
editorWidget->updateSemanticInfo();
|
||||
// Call empty callback
|
||||
renameSymbolsCallback(QString(),
|
||||
ClangBackEnd::SourceLocationsContainer(),
|
||||
data.cursor().document()->revision());
|
||||
renameSymbolsCallback(QString(), {}, data.cursor().document()->revision());
|
||||
}
|
||||
|
||||
void BuiltinModelManagerSupport::globalRename(const CursorInEditor &data,
|
||||
|
@@ -6,7 +6,6 @@ QtcPlugin {
|
||||
Depends { name: "Qt.widgets" }
|
||||
Depends { condition: project.withAutotests; name: "Qt.testlib" }
|
||||
|
||||
Depends { name: "ClangSupport" }
|
||||
Depends { name: "CPlusPlus" }
|
||||
Depends { name: "Utils" }
|
||||
|
||||
|
@@ -52,8 +52,6 @@
|
||||
#include "cppworkingcopy.h"
|
||||
#include "symbolfinder.h"
|
||||
|
||||
#include <clangsupport/sourcelocationscontainer.h>
|
||||
|
||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/editormanager/documentmodel.h>
|
||||
@@ -934,7 +932,6 @@ const ProjectPart *CppEditorWidget::projectPart() const
|
||||
|
||||
namespace {
|
||||
|
||||
using ClangBackEnd::SourceLocationContainer;
|
||||
using Utils::Text::selectAt;
|
||||
|
||||
QTextCharFormat occurrencesTextCharFormat()
|
||||
@@ -945,7 +942,7 @@ QTextCharFormat occurrencesTextCharFormat()
|
||||
}
|
||||
|
||||
QList<QTextEdit::ExtraSelection> sourceLocationsToExtraSelections(
|
||||
const std::vector<SourceLocationContainer> &sourceLocations,
|
||||
const Links &sourceLocations,
|
||||
uint selectionLength,
|
||||
CppEditorWidget *cppEditorWidget)
|
||||
{
|
||||
@@ -954,12 +951,12 @@ QList<QTextEdit::ExtraSelection> sourceLocationsToExtraSelections(
|
||||
QList<QTextEdit::ExtraSelection> selections;
|
||||
selections.reserve(int(sourceLocations.size()));
|
||||
|
||||
auto sourceLocationToExtraSelection = [&](const SourceLocationContainer &sourceLocation) {
|
||||
auto sourceLocationToExtraSelection = [&](const Link &sourceLocation) {
|
||||
QTextEdit::ExtraSelection selection;
|
||||
|
||||
selection.cursor = selectAt(cppEditorWidget->textCursor(),
|
||||
sourceLocation.line,
|
||||
sourceLocation.column,
|
||||
sourceLocation.targetLine,
|
||||
sourceLocation.targetColumn,
|
||||
selectionLength);
|
||||
selection.format = textCharFormat;
|
||||
|
||||
@@ -978,8 +975,6 @@ QList<QTextEdit::ExtraSelection> sourceLocationsToExtraSelections(
|
||||
|
||||
void CppEditorWidget::renameSymbolUnderCursor()
|
||||
{
|
||||
using ClangBackEnd::SourceLocationsContainer;
|
||||
|
||||
const ProjectPart *projPart = projectPart();
|
||||
if (!projPart)
|
||||
return;
|
||||
@@ -992,17 +987,15 @@ void CppEditorWidget::renameSymbolUnderCursor()
|
||||
|
||||
QPointer<CppEditorWidget> cppEditorWidget = this;
|
||||
|
||||
auto renameSymbols = [=](const QString &symbolName,
|
||||
const SourceLocationsContainer &sourceLocations,
|
||||
int revision) {
|
||||
auto renameSymbols = [=](const QString &symbolName, const Links &links, int revision) {
|
||||
if (cppEditorWidget) {
|
||||
viewport()->setCursor(Qt::IBeamCursor);
|
||||
|
||||
if (revision != document()->revision())
|
||||
return;
|
||||
if (sourceLocations.hasContent()) {
|
||||
if (!links.isEmpty()) {
|
||||
QList<QTextEdit::ExtraSelection> selections
|
||||
= sourceLocationsToExtraSelections(sourceLocations.sourceLocationContainers(),
|
||||
= sourceLocationsToExtraSelections(links,
|
||||
static_cast<uint>(symbolName.size()),
|
||||
cppEditorWidget);
|
||||
setExtraSelections(TextEditor::TextEditorWidget::CodeSemanticsSelection, selections);
|
||||
|
@@ -26,21 +26,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/link.h>
|
||||
|
||||
#include <QTextCursor>
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace ClangBackEnd { class SourceLocationsContainer; }
|
||||
namespace TextEditor { class TextDocument; }
|
||||
|
||||
namespace CppEditor {
|
||||
class CppEditorWidget;
|
||||
|
||||
// TODO: Move to a better place.
|
||||
using RenameCallback = std::function<void(const QString &,
|
||||
const ClangBackEnd::SourceLocationsContainer &,
|
||||
int)>;
|
||||
using RenameCallback = std::function<void(const QString &, const Utils::Links &, int)>;
|
||||
|
||||
class CursorInEditor
|
||||
{
|
||||
|
Reference in New Issue
Block a user