2015-09-04 12:15:17 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-09-04 12:15:17 +02:00
|
|
|
**
|
|
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2015-09-04 12:15:17 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2015-09-04 12:15:17 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2018-04-12 14:49:07 +02:00
|
|
|
#include "clangconstants.h"
|
2015-09-04 12:15:17 +02:00
|
|
|
#include "clangdiagnosticfilter.h"
|
|
|
|
|
#include "clangdiagnosticmanager.h"
|
2016-01-27 13:37:19 +01:00
|
|
|
#include "clangisdiagnosticrelatedtolocation.h"
|
2017-05-19 08:55:08 +02:00
|
|
|
#include "clangutils.h"
|
2015-09-04 12:15:17 +02:00
|
|
|
|
2016-02-05 15:16:02 +01:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
|
|
|
|
|
|
|
|
|
#include <cpptools/cpptoolsconstants.h>
|
|
|
|
|
|
2018-04-12 14:49:07 +02:00
|
|
|
#include <projectexplorer/taskhub.h>
|
|
|
|
|
|
2015-12-02 12:25:20 +01:00
|
|
|
#include <texteditor/fontsettings.h>
|
2015-09-04 12:15:17 +02:00
|
|
|
#include <texteditor/textdocument.h>
|
2015-12-02 12:25:20 +01:00
|
|
|
#include <texteditor/texteditorsettings.h>
|
2015-09-04 12:15:17 +02:00
|
|
|
|
2017-09-21 12:35:24 +02:00
|
|
|
#include <utils/textutils.h>
|
2015-09-04 12:15:17 +02:00
|
|
|
#include <utils/fileutils.h>
|
2016-02-05 15:16:02 +01:00
|
|
|
#include <utils/proxyaction.h>
|
2015-09-04 12:15:17 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2017-07-03 13:29:30 +02:00
|
|
|
#include <utils/theme/theme.h>
|
2018-04-12 14:49:07 +02:00
|
|
|
#include <utils/utilsicons.h>
|
2015-09-04 12:15:17 +02:00
|
|
|
|
2016-10-04 16:23:42 +02:00
|
|
|
#include <QFileInfo>
|
2015-12-02 20:07:29 +01:00
|
|
|
#include <QTextBlock>
|
|
|
|
|
|
2015-09-04 12:15:17 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
QTextEdit::ExtraSelection createExtraSelections(const QTextCharFormat &mainformat,
|
2016-01-27 13:37:19 +01:00
|
|
|
const QTextCursor &cursor)
|
2015-09-04 12:15:17 +02:00
|
|
|
{
|
|
|
|
|
QTextEdit::ExtraSelection extraSelection;
|
|
|
|
|
|
|
|
|
|
extraSelection.format = mainformat;
|
|
|
|
|
extraSelection.cursor = cursor;
|
|
|
|
|
|
|
|
|
|
return extraSelection;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-02 20:07:29 +01:00
|
|
|
int positionInText(QTextDocument *textDocument,
|
|
|
|
|
const ClangBackEnd::SourceLocationContainer &sourceLocationContainer)
|
|
|
|
|
{
|
2017-05-19 08:55:08 +02:00
|
|
|
auto textBlock = textDocument->findBlockByNumber(
|
2018-04-04 18:25:23 +02:00
|
|
|
static_cast<int>(sourceLocationContainer.line) - 1);
|
2018-01-26 17:04:38 +01:00
|
|
|
// 'sourceLocationContainer' already has the CppEditor column converted from
|
|
|
|
|
// the utf8 byte offset from the beginning of the line provided by clang.
|
|
|
|
|
// - 1 is required for 0-based columns.
|
2018-04-04 18:25:23 +02:00
|
|
|
const int column = static_cast<int>(sourceLocationContainer.column) - 1;
|
2017-05-19 08:55:08 +02:00
|
|
|
return textBlock.position() + column;
|
2015-12-02 20:07:29 +01:00
|
|
|
}
|
|
|
|
|
|
2015-09-04 12:15:17 +02:00
|
|
|
void addRangeSelections(const ClangBackEnd::DiagnosticContainer &diagnostic,
|
|
|
|
|
QTextDocument *textDocument,
|
2015-12-02 12:25:20 +01:00
|
|
|
const QTextCharFormat &contextFormat,
|
2015-09-04 12:15:17 +02:00
|
|
|
QList<QTextEdit::ExtraSelection> &extraSelections)
|
|
|
|
|
{
|
2018-04-04 18:25:23 +02:00
|
|
|
for (auto &&range : diagnostic.ranges) {
|
2015-09-04 12:15:17 +02:00
|
|
|
QTextCursor cursor(textDocument);
|
2018-04-04 18:25:23 +02:00
|
|
|
cursor.setPosition(positionInText(textDocument, range.start));
|
|
|
|
|
cursor.setPosition(positionInText(textDocument, range.end), QTextCursor::KeepAnchor);
|
2015-09-04 12:15:17 +02:00
|
|
|
|
2016-01-27 13:37:19 +01:00
|
|
|
auto extraSelection = createExtraSelections(contextFormat, cursor);
|
2015-09-04 12:15:17 +02:00
|
|
|
|
|
|
|
|
extraSelections.push_back(std::move(extraSelection));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-17 11:47:38 +02:00
|
|
|
QChar selectionEndChar(const QChar startSymbol)
|
|
|
|
|
{
|
|
|
|
|
if (startSymbol == '"')
|
|
|
|
|
return QLatin1Char('"');
|
|
|
|
|
if (startSymbol == '<')
|
|
|
|
|
return QLatin1Char('>');
|
|
|
|
|
return QChar();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void selectToLocationEnd(QTextCursor &cursor)
|
|
|
|
|
{
|
|
|
|
|
const QTextBlock textBlock = cursor.document()->findBlock(cursor.position());
|
|
|
|
|
const QString simplifiedStr = textBlock.text().simplified();
|
|
|
|
|
if (!simplifiedStr.startsWith("#include") && !simplifiedStr.startsWith("# include")) {
|
|
|
|
|
// General case, not the line with #include
|
|
|
|
|
cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QChar endChar = selectionEndChar(cursor.document()->characterAt(cursor.position()));
|
|
|
|
|
if (endChar.isNull()) {
|
|
|
|
|
cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
|
|
|
|
|
} else {
|
|
|
|
|
const int endPosition = textBlock.text().indexOf(endChar, cursor.position()
|
|
|
|
|
- textBlock.position() + 1);
|
|
|
|
|
if (endPosition >= 0)
|
|
|
|
|
cursor.setPosition(textBlock.position() + endPosition + 1, QTextCursor::KeepAnchor);
|
|
|
|
|
else
|
|
|
|
|
cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-02 20:07:29 +01:00
|
|
|
QTextCursor createSelectionCursor(QTextDocument *textDocument,
|
|
|
|
|
const ClangBackEnd::SourceLocationContainer &sourceLocationContainer)
|
2015-09-04 12:15:17 +02:00
|
|
|
{
|
|
|
|
|
QTextCursor cursor(textDocument);
|
2015-12-02 20:07:29 +01:00
|
|
|
cursor.setPosition(positionInText(textDocument, sourceLocationContainer));
|
2017-05-17 11:47:38 +02:00
|
|
|
selectToLocationEnd(cursor);
|
2015-09-04 12:15:17 +02:00
|
|
|
|
|
|
|
|
if (!cursor.hasSelection()) {
|
2015-12-02 20:07:29 +01:00
|
|
|
cursor.setPosition(positionInText(textDocument, sourceLocationContainer) - 1);
|
2015-09-04 12:15:17 +02:00
|
|
|
cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cursor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addSelections(const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics,
|
|
|
|
|
QTextDocument *textDocument,
|
|
|
|
|
const QTextCharFormat &mainFormat,
|
2015-12-02 12:25:20 +01:00
|
|
|
const QTextCharFormat &contextFormat,
|
2015-09-04 12:15:17 +02:00
|
|
|
QList<QTextEdit::ExtraSelection> &extraSelections)
|
|
|
|
|
{
|
|
|
|
|
for (auto &&diagnostic : diagnostics) {
|
2018-04-04 18:25:23 +02:00
|
|
|
auto cursor = createSelectionCursor(textDocument, diagnostic.location);
|
2016-01-27 13:37:19 +01:00
|
|
|
auto extraSelection = createExtraSelections(mainFormat, cursor);
|
2015-09-04 12:15:17 +02:00
|
|
|
|
2016-01-27 13:37:19 +01:00
|
|
|
addRangeSelections(diagnostic, textDocument, contextFormat, extraSelections);
|
2015-09-04 12:15:17 +02:00
|
|
|
|
|
|
|
|
extraSelections.push_back(std::move(extraSelection));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addWarningSelections(const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics,
|
|
|
|
|
QTextDocument *textDocument,
|
|
|
|
|
QList<QTextEdit::ExtraSelection> &extraSelections)
|
|
|
|
|
{
|
2015-12-02 12:25:20 +01:00
|
|
|
const auto fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
|
2015-09-04 12:15:17 +02:00
|
|
|
|
2015-12-02 12:25:20 +01:00
|
|
|
QTextCharFormat warningFormat = fontSettings.toTextCharFormat(TextEditor::C_WARNING);
|
2015-09-04 12:15:17 +02:00
|
|
|
|
2015-12-02 12:25:20 +01:00
|
|
|
QTextCharFormat warningContextFormat = fontSettings.toTextCharFormat(TextEditor::C_WARNING_CONTEXT);
|
|
|
|
|
|
|
|
|
|
addSelections(diagnostics, textDocument, warningFormat, warningContextFormat, extraSelections);
|
2015-09-04 12:15:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addErrorSelections(const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics,
|
|
|
|
|
QTextDocument *textDocument,
|
|
|
|
|
QList<QTextEdit::ExtraSelection> &extraSelections)
|
|
|
|
|
{
|
2015-12-02 12:25:20 +01:00
|
|
|
const auto fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
|
2015-09-04 12:15:17 +02:00
|
|
|
|
2015-12-02 12:25:20 +01:00
|
|
|
QTextCharFormat errorFormat = fontSettings.toTextCharFormat(TextEditor::C_ERROR);
|
|
|
|
|
QTextCharFormat errorContextFormat = fontSettings.toTextCharFormat(TextEditor::C_ERROR_CONTEXT);
|
2015-09-04 12:15:17 +02:00
|
|
|
|
2015-12-02 12:25:20 +01:00
|
|
|
addSelections(diagnostics, textDocument, errorFormat, errorContextFormat, extraSelections);
|
2015-09-04 12:15:17 +02:00
|
|
|
}
|
|
|
|
|
|
2016-01-27 13:37:19 +01:00
|
|
|
ClangBackEnd::SourceLocationContainer toSourceLocation(QTextDocument *textDocument, int position)
|
|
|
|
|
{
|
|
|
|
|
int line, column;
|
2017-09-21 12:35:24 +02:00
|
|
|
if (Utils::Text::convertPosition(textDocument, position, &line, &column))
|
2016-01-27 13:37:19 +01:00
|
|
|
return ClangBackEnd::SourceLocationContainer(Utf8String(), line, column);
|
|
|
|
|
|
|
|
|
|
return ClangBackEnd::SourceLocationContainer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClangBackEnd::SourceRangeContainer toSourceRange(const QTextCursor &cursor)
|
|
|
|
|
{
|
|
|
|
|
using namespace ClangBackEnd;
|
|
|
|
|
|
|
|
|
|
QTextDocument *textDocument = cursor.document();
|
|
|
|
|
|
|
|
|
|
return SourceRangeContainer(toSourceLocation(textDocument, cursor.anchor()),
|
|
|
|
|
toSourceLocation(textDocument, cursor.position()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isDiagnosticAtLocation(const ClangBackEnd::DiagnosticContainer &diagnostic,
|
|
|
|
|
uint line,
|
|
|
|
|
uint column,
|
|
|
|
|
QTextDocument *textDocument)
|
|
|
|
|
{
|
|
|
|
|
using namespace ClangCodeModel::Internal;
|
|
|
|
|
|
2018-04-04 18:25:23 +02:00
|
|
|
const ClangBackEnd::SourceLocationContainer &location = diagnostic.location;
|
2016-01-27 13:37:19 +01:00
|
|
|
const QTextCursor cursor = createSelectionCursor(textDocument, location);
|
|
|
|
|
const ClangBackEnd::SourceRangeContainer cursorRange = toSourceRange(cursor);
|
|
|
|
|
|
|
|
|
|
return isDiagnosticRelatedToLocation(diagnostic, {cursorRange}, line, column);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVector<ClangBackEnd::DiagnosticContainer>
|
|
|
|
|
filteredDiagnosticsAtLocation(const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics,
|
|
|
|
|
uint line,
|
|
|
|
|
uint column,
|
|
|
|
|
QTextDocument *textDocument)
|
|
|
|
|
{
|
|
|
|
|
QVector<ClangBackEnd::DiagnosticContainer> filteredDiagnostics;
|
|
|
|
|
|
|
|
|
|
foreach (const auto &diagnostic, diagnostics) {
|
|
|
|
|
if (isDiagnosticAtLocation(diagnostic, line, column, textDocument))
|
|
|
|
|
filteredDiagnostics.append(diagnostic);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return filteredDiagnostics;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool editorDocumentProcessorHasDiagnosticAt(
|
|
|
|
|
const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics,
|
|
|
|
|
uint line,
|
|
|
|
|
uint column,
|
|
|
|
|
QTextDocument *textDocument)
|
|
|
|
|
{
|
|
|
|
|
foreach (const auto &diagnostic, diagnostics) {
|
|
|
|
|
if (isDiagnosticAtLocation(diagnostic, line, column, textDocument))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-05 15:16:02 +01:00
|
|
|
QTextCursor cursorAtLastPositionOfLine(QTextDocument *textDocument, int lineNumber)
|
|
|
|
|
{
|
|
|
|
|
const QTextBlock textBlock = textDocument->findBlockByNumber(lineNumber - 1);
|
|
|
|
|
QTC_ASSERT(textBlock.isValid(), return QTextCursor());
|
|
|
|
|
|
|
|
|
|
const int lastPositionOfLine = textBlock.position() + textBlock.length() - 1;
|
|
|
|
|
|
|
|
|
|
QTextCursor textCursor(textDocument);
|
|
|
|
|
textCursor.setPosition(lastPositionOfLine);
|
|
|
|
|
|
|
|
|
|
return textCursor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString tooltipForFixItAvailableMarker()
|
|
|
|
|
{
|
2016-04-26 15:51:04 +09:00
|
|
|
QString text = QCoreApplication::translate("ClangCodeModel::Internal::ClangDiagnosticManager", "Inspect available fixits");
|
2016-02-05 15:16:02 +01:00
|
|
|
|
|
|
|
|
Core::Command *command = Core::ActionManager::command(TextEditor::Constants::QUICKFIX_THIS);
|
|
|
|
|
if (command)
|
|
|
|
|
text = Utils::ProxyAction::stringWithAppendedShortcut(text, command->keySequence());
|
|
|
|
|
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TextEditor::RefactorMarker createFixItAvailableMarker(QTextDocument *textDocument, int lineNumber)
|
|
|
|
|
{
|
|
|
|
|
TextEditor::RefactorMarker marker;
|
|
|
|
|
marker.tooltip = tooltipForFixItAvailableMarker();
|
|
|
|
|
marker.cursor = cursorAtLastPositionOfLine(textDocument, lineNumber);
|
|
|
|
|
marker.data = QLatin1String(CppTools::Constants::CPP_CLANG_FIXIT_AVAILABLE_MARKER_ID);
|
|
|
|
|
|
|
|
|
|
return marker;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-04 12:15:17 +02:00
|
|
|
} // anonymous
|
|
|
|
|
|
|
|
|
|
namespace ClangCodeModel {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
ClangDiagnosticManager::ClangDiagnosticManager(TextEditor::TextDocument *textDocument)
|
|
|
|
|
: m_textDocument(textDocument)
|
|
|
|
|
{
|
2017-07-12 09:34:30 +02:00
|
|
|
m_textMarkDelay.setInterval(1500);
|
|
|
|
|
m_textMarkDelay.setSingleShot(true);
|
2015-09-04 12:15:17 +02:00
|
|
|
}
|
|
|
|
|
|
2016-07-19 11:58:15 +02:00
|
|
|
ClangDiagnosticManager::~ClangDiagnosticManager()
|
|
|
|
|
{
|
|
|
|
|
cleanMarks();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangDiagnosticManager::cleanMarks()
|
2015-09-04 12:15:17 +02:00
|
|
|
{
|
2016-07-19 11:58:15 +02:00
|
|
|
for (ClangTextMark *textMark : m_clangTextMarks) {
|
|
|
|
|
m_textDocument->removeMark(textMark);
|
|
|
|
|
delete textMark;
|
|
|
|
|
}
|
2015-09-04 12:15:17 +02:00
|
|
|
m_clangTextMarks.clear();
|
2016-07-19 11:58:15 +02:00
|
|
|
}
|
|
|
|
|
void ClangDiagnosticManager::generateTextMarks()
|
|
|
|
|
{
|
2017-07-12 09:34:30 +02:00
|
|
|
QObject::disconnect(&m_textMarkDelay, &QTimer::timeout, 0, 0);
|
2016-07-19 11:58:15 +02:00
|
|
|
cleanMarks();
|
2015-09-04 12:15:17 +02:00
|
|
|
m_clangTextMarks.reserve(m_warningDiagnostics.size() + m_errorDiagnostics.size());
|
|
|
|
|
addClangTextMarks(m_warningDiagnostics);
|
|
|
|
|
addClangTextMarks(m_errorDiagnostics);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-05 15:16:02 +01:00
|
|
|
void ClangDiagnosticManager::generateFixItAvailableMarkers()
|
|
|
|
|
{
|
|
|
|
|
m_fixItAvailableMarkers.clear();
|
|
|
|
|
|
|
|
|
|
QSet<int> lineNumbersWithFixItMarker;
|
|
|
|
|
addFixItAvailableMarker(m_warningDiagnostics, lineNumbersWithFixItMarker);
|
|
|
|
|
addFixItAvailableMarker(m_errorDiagnostics, lineNumbersWithFixItMarker);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-12 14:49:07 +02:00
|
|
|
static void addTask(const ClangBackEnd::DiagnosticContainer &diagnostic, bool isChild = false)
|
|
|
|
|
{
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using ::Utils::FileName;
|
|
|
|
|
|
|
|
|
|
Task::TaskType taskType = ProjectExplorer::Task::TaskType::Unknown;
|
|
|
|
|
FileName iconPath;
|
|
|
|
|
QIcon icon;
|
|
|
|
|
|
|
|
|
|
if (!isChild) {
|
|
|
|
|
switch (diagnostic.severity) {
|
|
|
|
|
case ClangBackEnd::DiagnosticSeverity::Fatal:
|
|
|
|
|
case ClangBackEnd::DiagnosticSeverity::Error:
|
|
|
|
|
taskType = Task::TaskType::Error;
|
|
|
|
|
icon = ::Utils::Icons::CODEMODEL_ERROR.icon();
|
|
|
|
|
break;
|
|
|
|
|
case ClangBackEnd::DiagnosticSeverity::Warning:
|
|
|
|
|
taskType = Task::TaskType::Warning;
|
|
|
|
|
icon = ::Utils::Icons::CODEMODEL_WARNING.icon();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TaskHub::addTask(Task(taskType,
|
|
|
|
|
diagnostic.text.toString(),
|
|
|
|
|
FileName::fromString(diagnostic.location.filePath.toString()),
|
|
|
|
|
diagnostic.location.line,
|
|
|
|
|
Constants::TASK_CATEGORY_DIAGNOSTICS,
|
|
|
|
|
icon,
|
|
|
|
|
/*addTextMark =*/ false));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangDiagnosticManager::clearTaskHubIssues()
|
|
|
|
|
{
|
|
|
|
|
ProjectExplorer::TaskHub::clearTasks(Constants::TASK_CATEGORY_DIAGNOSTICS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangDiagnosticManager::generateTaskHubIssues()
|
|
|
|
|
{
|
|
|
|
|
const QVector<ClangBackEnd::DiagnosticContainer> diagnostics = m_errorDiagnostics
|
|
|
|
|
+ m_warningDiagnostics;
|
|
|
|
|
for (const ClangBackEnd::DiagnosticContainer &diagnostic : diagnostics) {
|
|
|
|
|
addTask(diagnostic);
|
|
|
|
|
for (const ClangBackEnd::DiagnosticContainer &child : diagnostic.children)
|
|
|
|
|
addTask(child, /*isChild = */ true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-04 12:15:17 +02:00
|
|
|
QList<QTextEdit::ExtraSelection> ClangDiagnosticManager::takeExtraSelections()
|
|
|
|
|
{
|
|
|
|
|
auto extraSelections = m_extraSelections;
|
|
|
|
|
|
|
|
|
|
m_extraSelections.clear();
|
|
|
|
|
|
|
|
|
|
return extraSelections;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-05 15:16:02 +01:00
|
|
|
TextEditor::RefactorMarkers ClangDiagnosticManager::takeFixItAvailableMarkers()
|
|
|
|
|
{
|
|
|
|
|
TextEditor::RefactorMarkers fixItAvailableMarkers = m_fixItAvailableMarkers;
|
|
|
|
|
|
|
|
|
|
m_fixItAvailableMarkers.clear();
|
|
|
|
|
|
|
|
|
|
return fixItAvailableMarkers;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-27 13:37:19 +01:00
|
|
|
bool ClangDiagnosticManager::hasDiagnosticsAt(uint line, uint column) const
|
|
|
|
|
{
|
|
|
|
|
QTextDocument *textDocument = m_textDocument->document();
|
|
|
|
|
|
|
|
|
|
return editorDocumentProcessorHasDiagnosticAt(m_errorDiagnostics, line, column, textDocument)
|
2018-04-12 00:13:48 +03:00
|
|
|
|| editorDocumentProcessorHasDiagnosticAt(m_warningDiagnostics, line, column, textDocument);
|
2016-01-27 13:37:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVector<ClangBackEnd::DiagnosticContainer>
|
|
|
|
|
ClangDiagnosticManager::diagnosticsAt(uint line, uint column) const
|
|
|
|
|
{
|
|
|
|
|
QTextDocument *textDocument = m_textDocument->document();
|
|
|
|
|
|
|
|
|
|
QVector<ClangBackEnd::DiagnosticContainer> diagnostics;
|
|
|
|
|
diagnostics += filteredDiagnosticsAtLocation(m_errorDiagnostics, line, column, textDocument);
|
|
|
|
|
diagnostics += filteredDiagnosticsAtLocation(m_warningDiagnostics, line, column, textDocument);
|
|
|
|
|
|
|
|
|
|
return diagnostics;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-03 13:29:30 +02:00
|
|
|
void ClangDiagnosticManager::invalidateDiagnostics()
|
|
|
|
|
{
|
2017-07-12 09:34:30 +02:00
|
|
|
m_textMarkDelay.start();
|
2017-07-03 13:29:30 +02:00
|
|
|
if (m_diagnosticsInvalidated)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_diagnosticsInvalidated = true;
|
|
|
|
|
for (ClangTextMark *textMark : m_clangTextMarks) {
|
|
|
|
|
textMark->setColor(::Utils::Theme::Color::IconsDisabledColor);
|
|
|
|
|
textMark->updateIcon(/*valid=*/ false);
|
|
|
|
|
textMark->updateMarker();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-25 15:11:23 +01:00
|
|
|
void ClangDiagnosticManager::clearDiagnosticsWithFixIts()
|
|
|
|
|
{
|
|
|
|
|
m_fixItdiagnostics.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-04 12:15:17 +02:00
|
|
|
void ClangDiagnosticManager::generateEditorSelections()
|
|
|
|
|
{
|
|
|
|
|
m_extraSelections.clear();
|
|
|
|
|
m_extraSelections.reserve(int(m_warningDiagnostics.size() + m_errorDiagnostics.size()));
|
|
|
|
|
|
|
|
|
|
addWarningSelections(m_warningDiagnostics, m_textDocument->document(), m_extraSelections);
|
|
|
|
|
addErrorSelections(m_errorDiagnostics, m_textDocument->document(), m_extraSelections);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangDiagnosticManager::processNewDiagnostics(
|
2017-07-10 09:53:34 +02:00
|
|
|
const QVector<ClangBackEnd::DiagnosticContainer> &allDiagnostics,
|
|
|
|
|
bool showTextMarkAnnotations)
|
2015-09-04 12:15:17 +02:00
|
|
|
{
|
2017-07-03 13:29:30 +02:00
|
|
|
m_diagnosticsInvalidated = false;
|
2017-07-10 09:53:34 +02:00
|
|
|
m_showTextMarkAnnotations = showTextMarkAnnotations;
|
2015-09-04 12:15:17 +02:00
|
|
|
filterDiagnostics(allDiagnostics);
|
|
|
|
|
|
|
|
|
|
generateEditorSelections();
|
2016-02-05 15:16:02 +01:00
|
|
|
generateFixItAvailableMarkers();
|
2017-07-12 09:34:30 +02:00
|
|
|
if (m_firstDiagnostics) {
|
|
|
|
|
m_firstDiagnostics = false;
|
|
|
|
|
generateTextMarks();
|
|
|
|
|
} else if (!m_textMarkDelay.isActive()) {
|
|
|
|
|
generateTextMarks();
|
|
|
|
|
} else {
|
|
|
|
|
QObject::connect(&m_textMarkDelay, &QTimer::timeout, [this]() {
|
|
|
|
|
generateTextMarks();
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-04-12 14:49:07 +02:00
|
|
|
|
|
|
|
|
clearTaskHubIssues();
|
|
|
|
|
generateTaskHubIssues();
|
2015-09-04 12:15:17 +02:00
|
|
|
}
|
|
|
|
|
|
2015-08-24 18:26:09 +02:00
|
|
|
const QVector<ClangBackEnd::DiagnosticContainer> &
|
|
|
|
|
ClangDiagnosticManager::diagnosticsWithFixIts() const
|
|
|
|
|
{
|
|
|
|
|
return m_fixItdiagnostics;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-04 12:15:17 +02:00
|
|
|
void ClangDiagnosticManager::addClangTextMarks(
|
|
|
|
|
const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics)
|
|
|
|
|
{
|
2016-07-19 11:58:15 +02:00
|
|
|
for (const ClangBackEnd::DiagnosticContainer &diagnostic : diagnostics) {
|
2016-11-17 15:55:06 +01:00
|
|
|
const auto onMarkRemoved = [this](const ClangTextMark *mark) {
|
|
|
|
|
const auto it = std::remove(m_clangTextMarks.begin(), m_clangTextMarks.end(), mark);
|
|
|
|
|
m_clangTextMarks.erase(it, m_clangTextMarks.end());
|
|
|
|
|
delete mark;
|
2018-04-12 00:13:48 +03:00
|
|
|
};
|
2018-05-02 15:02:00 +02:00
|
|
|
auto textMark = new ClangTextMark(::Utils::FileName::fromString(filePath()),
|
|
|
|
|
diagnostic,
|
|
|
|
|
onMarkRemoved,
|
2017-07-10 09:53:34 +02:00
|
|
|
m_showTextMarkAnnotations);
|
2016-07-19 11:58:15 +02:00
|
|
|
m_clangTextMarks.push_back(textMark);
|
|
|
|
|
m_textDocument->addMark(textMark);
|
2015-09-04 12:15:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-05 15:16:02 +01:00
|
|
|
void ClangDiagnosticManager::addFixItAvailableMarker(
|
|
|
|
|
const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics,
|
|
|
|
|
QSet<int> &lineNumbersWithFixItMarker)
|
|
|
|
|
{
|
|
|
|
|
for (auto &&diagnostic : diagnostics) {
|
2018-04-04 18:25:23 +02:00
|
|
|
for (auto &&fixit : diagnostic.fixIts) {
|
|
|
|
|
const ClangBackEnd::SourceLocationContainer &location = fixit.range.start;
|
|
|
|
|
const int line = int(location.line);
|
2016-02-05 15:16:02 +01:00
|
|
|
|
2018-04-04 18:25:23 +02:00
|
|
|
if (location.filePath == filePath() && !lineNumbersWithFixItMarker.contains(line)) {
|
2016-06-24 15:01:16 +02:00
|
|
|
const TextEditor::RefactorMarker marker
|
|
|
|
|
= createFixItAvailableMarker(m_textDocument->document(), line);
|
|
|
|
|
|
|
|
|
|
lineNumbersWithFixItMarker.insert(line);
|
|
|
|
|
m_fixItAvailableMarkers.append(marker);
|
|
|
|
|
}
|
2016-02-05 15:16:02 +01:00
|
|
|
}
|
|
|
|
|
|
2018-04-04 18:25:23 +02:00
|
|
|
addFixItAvailableMarker(diagnostic.children, lineNumbersWithFixItMarker);
|
2016-02-05 15:16:02 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-04 12:15:17 +02:00
|
|
|
QString ClangDiagnosticManager::filePath() const
|
|
|
|
|
{
|
|
|
|
|
return m_textDocument->filePath().toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangDiagnosticManager::filterDiagnostics(
|
|
|
|
|
const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics)
|
|
|
|
|
{
|
|
|
|
|
ClangDiagnosticFilter filter(filePath());
|
|
|
|
|
filter.filter(diagnostics);
|
|
|
|
|
|
|
|
|
|
m_warningDiagnostics = filter.takeWarnings();
|
|
|
|
|
m_errorDiagnostics = filter.takeErrors();
|
2015-08-24 18:26:09 +02:00
|
|
|
m_fixItdiagnostics = filter.takeFixIts();
|
2015-09-04 12:15:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ClangCodeModel
|