forked from qt-creator/qt-creator
Clang: Show current editor diagnostics in issues pane
This helps to deal with many diagnostics. Error diagnostics precede warning diagnostis to have them on top. If no CppEditor is active, no diagnostics are displayed. Previously one had to scroll the document up and down to locate the diagnostics. Now they are in a list and can be easily navigated with F6/Shift-F6. Also, at least for some diagnostics "Get Help Online" from the context menu seems to provide useful results. For example, triggering the action on clang tidy issues will open the web browser with some good hits explaining the issues. Change-Id: Idabe30b0961d893bee39ccee431e92aeeda1cc26 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -38,6 +38,7 @@
|
|||||||
#include <projectexplorer/projectpanelfactory.h>
|
#include <projectexplorer/projectpanelfactory.h>
|
||||||
#include <projectexplorer/projectexplorer.h>
|
#include <projectexplorer/projectexplorer.h>
|
||||||
#include <projectexplorer/session.h>
|
#include <projectexplorer/session.h>
|
||||||
|
#include <projectexplorer/taskhub.h>
|
||||||
|
|
||||||
#include <texteditor/textmark.h>
|
#include <texteditor/textmark.h>
|
||||||
|
|
||||||
@@ -64,6 +65,9 @@ bool ClangCodeModelPlugin::initialize(const QStringList &arguments, QString *err
|
|||||||
Q_UNUSED(arguments);
|
Q_UNUSED(arguments);
|
||||||
Q_UNUSED(errorMessage);
|
Q_UNUSED(errorMessage);
|
||||||
|
|
||||||
|
ProjectExplorer::TaskHub::addCategory(Constants::TASK_CATEGORY_DIAGNOSTICS,
|
||||||
|
tr("Clang Code Model"));
|
||||||
|
|
||||||
connect(ProjectExplorer::ProjectExplorerPlugin::instance(),
|
connect(ProjectExplorer::ProjectExplorerPlugin::instance(),
|
||||||
&ProjectExplorer::ProjectExplorerPlugin::finishedInitialization,
|
&ProjectExplorer::ProjectExplorerPlugin::finishedInitialization,
|
||||||
this,
|
this,
|
||||||
|
@@ -32,5 +32,7 @@ const char CLANG_MODELMANAGERSUPPORT_ID[] = "ClangCodeModel.ClangCodeModel";
|
|||||||
const char CLANG_ERROR[] = "Clang.Error";
|
const char CLANG_ERROR[] = "Clang.Error";
|
||||||
const char CLANG_WARNING[] = "Clang.Warning";
|
const char CLANG_WARNING[] = "Clang.Warning";
|
||||||
|
|
||||||
|
const char TASK_CATEGORY_DIAGNOSTICS[] = "ClangCodeModel";
|
||||||
|
|
||||||
} // namespace Constants
|
} // namespace Constants
|
||||||
} // namespace ClangCodeModel
|
} // namespace ClangCodeModel
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "clangconstants.h"
|
||||||
#include "clangdiagnosticfilter.h"
|
#include "clangdiagnosticfilter.h"
|
||||||
#include "clangdiagnosticmanager.h"
|
#include "clangdiagnosticmanager.h"
|
||||||
#include "clangisdiagnosticrelatedtolocation.h"
|
#include "clangisdiagnosticrelatedtolocation.h"
|
||||||
@@ -33,6 +34,8 @@
|
|||||||
|
|
||||||
#include <cpptools/cpptoolsconstants.h>
|
#include <cpptools/cpptoolsconstants.h>
|
||||||
|
|
||||||
|
#include <projectexplorer/taskhub.h>
|
||||||
|
|
||||||
#include <texteditor/fontsettings.h>
|
#include <texteditor/fontsettings.h>
|
||||||
#include <texteditor/textdocument.h>
|
#include <texteditor/textdocument.h>
|
||||||
#include <texteditor/texteditorsettings.h>
|
#include <texteditor/texteditorsettings.h>
|
||||||
@@ -42,6 +45,7 @@
|
|||||||
#include <utils/proxyaction.h>
|
#include <utils/proxyaction.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/theme/theme.h>
|
#include <utils/theme/theme.h>
|
||||||
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QTextBlock>
|
#include <QTextBlock>
|
||||||
@@ -315,6 +319,56 @@ void ClangDiagnosticManager::generateFixItAvailableMarkers()
|
|||||||
addFixItAvailableMarker(m_errorDiagnostics, lineNumbersWithFixItMarker);
|
addFixItAvailableMarker(m_errorDiagnostics, lineNumbersWithFixItMarker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QList<QTextEdit::ExtraSelection> ClangDiagnosticManager::takeExtraSelections()
|
QList<QTextEdit::ExtraSelection> ClangDiagnosticManager::takeExtraSelections()
|
||||||
{
|
{
|
||||||
auto extraSelections = m_extraSelections;
|
auto extraSelections = m_extraSelections;
|
||||||
@@ -401,6 +455,9 @@ void ClangDiagnosticManager::processNewDiagnostics(
|
|||||||
generateTextMarks();
|
generateTextMarks();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clearTaskHubIssues();
|
||||||
|
generateTaskHubIssues();
|
||||||
}
|
}
|
||||||
|
|
||||||
const QVector<ClangBackEnd::DiagnosticContainer> &
|
const QVector<ClangBackEnd::DiagnosticContainer> &
|
||||||
|
@@ -63,6 +63,9 @@ public:
|
|||||||
void invalidateDiagnostics();
|
void invalidateDiagnostics();
|
||||||
void clearDiagnosticsWithFixIts();
|
void clearDiagnosticsWithFixIts();
|
||||||
|
|
||||||
|
static void clearTaskHubIssues();
|
||||||
|
void generateTaskHubIssues();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void cleanMarks();
|
void cleanMarks();
|
||||||
QString filePath() const;
|
QString filePath() const;
|
||||||
|
@@ -241,6 +241,16 @@ const QVector<ClangBackEnd::TokenInfoContainer>
|
|||||||
return m_tokenInfos;
|
return m_tokenInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClangEditorDocumentProcessor::clearTaskHubIssues()
|
||||||
|
{
|
||||||
|
m_diagnosticManager.clearTaskHubIssues();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClangEditorDocumentProcessor::generateTaskHubIssues()
|
||||||
|
{
|
||||||
|
m_diagnosticManager.generateTaskHubIssues();
|
||||||
|
}
|
||||||
|
|
||||||
void ClangEditorDocumentProcessor::updateHighlighting(
|
void ClangEditorDocumentProcessor::updateHighlighting(
|
||||||
const QVector<ClangBackEnd::TokenInfoContainer> &tokenInfos,
|
const QVector<ClangBackEnd::TokenInfoContainer> &tokenInfos,
|
||||||
const QVector<ClangBackEnd::SourceRangeContainer> &skippedPreprocessorRanges,
|
const QVector<ClangBackEnd::SourceRangeContainer> &skippedPreprocessorRanges,
|
||||||
|
@@ -103,6 +103,9 @@ public:
|
|||||||
|
|
||||||
const QVector<ClangBackEnd::TokenInfoContainer> &tokenInfos() const;
|
const QVector<ClangBackEnd::TokenInfoContainer> &tokenInfos() const;
|
||||||
|
|
||||||
|
void clearTaskHubIssues();
|
||||||
|
void generateTaskHubIssues();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static ClangEditorDocumentProcessor *get(const QString &filePath);
|
static ClangEditorDocumentProcessor *get(const QString &filePath);
|
||||||
|
|
||||||
|
@@ -160,9 +160,20 @@ CppTools::BaseEditorDocumentProcessor *ModelManagerSupportClang::createEditorDoc
|
|||||||
return new ClangEditorDocumentProcessor(m_communicator, baseTextDocument);
|
return new ClangEditorDocumentProcessor(m_communicator, baseTextDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelManagerSupportClang::onCurrentEditorChanged(Core::IEditor *)
|
void ModelManagerSupportClang::onCurrentEditorChanged(Core::IEditor *editor)
|
||||||
{
|
{
|
||||||
m_communicator.updateTranslationUnitVisiblity();
|
m_communicator.updateTranslationUnitVisiblity();
|
||||||
|
|
||||||
|
// Update task hub issues for current CppEditorDocument
|
||||||
|
QTC_ASSERT(editor, return);
|
||||||
|
Core::IDocument *document = editor->document();
|
||||||
|
QTC_ASSERT(document, return);
|
||||||
|
TextEditor::TextDocument *textDocument = qobject_cast<TextEditor::TextDocument *>(document);
|
||||||
|
|
||||||
|
auto processor = ClangEditorDocumentProcessor::get(document->filePath().toString());
|
||||||
|
processor->clearTaskHubIssues();
|
||||||
|
if (textDocument && cppModelManager()->isCppEditor(editor))
|
||||||
|
processor->generateTaskHubIssues();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelManagerSupportClang::connectTextDocumentToTranslationUnit(TextEditor::TextDocument *textDocument)
|
void ModelManagerSupportClang::connectTextDocumentToTranslationUnit(TextEditor::TextDocument *textDocument)
|
||||||
|
Reference in New Issue
Block a user