Clang: Do not show diagnostic category in inline annotations and issues pane

For build system diagnostics they are not displayed either.

Also, the error/warning is already encoded in the icon and the color.

However, the category is still shown in the tooltip.

Change-Id: I190ab17691c32786cefc20d058010c65cda5ace9
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Nikolai Kosjar
2018-05-09 15:12:01 +02:00
parent 851d56cda2
commit 6b70c27e3b
5 changed files with 35 additions and 27 deletions

View File

@@ -345,7 +345,7 @@ static void addTask(const ClangBackEnd::DiagnosticContainer &diagnostic, bool is
} }
TaskHub::addTask(Task(taskType, TaskHub::addTask(Task(taskType,
diagnostic.text.toString(), Utils::diagnosticCategoryPrefixRemoved(diagnostic.text.toString()),
FileName::fromString(diagnostic.location.filePath.toString()), FileName::fromString(diagnostic.location.filePath.toString()),
diagnostic.location.line, diagnostic.location.line,
Constants::TASK_CATEGORY_DIAGNOSTICS, Constants::TASK_CATEGORY_DIAGNOSTICS,

View File

@@ -26,6 +26,7 @@
#include "clangfixitoperationsextractor.h" #include "clangfixitoperationsextractor.h"
#include "clangfixitoperation.h" #include "clangfixitoperation.h"
#include "clangutils.h"
#include <utils/algorithm.h> #include <utils/algorithm.h>
@@ -40,27 +41,6 @@ void capitalizeText(QString &text)
text[0] = text[0].toUpper(); text[0] = text[0].toUpper();
} }
void removeDiagnosticCategoryPrefix(QString &text)
{
// Prefixes are taken from $LLVM_SOURCE_DIR/tools/clang/lib/Frontend/TextDiagnostic.cpp,
// function TextDiagnostic::printDiagnosticLevel (llvm-3.6.2).
static const QStringList categoryPrefixes = {
QStringLiteral("note"),
QStringLiteral("remark"),
QStringLiteral("warning"),
QStringLiteral("error"),
QStringLiteral("fatal error")
};
foreach (const QString &prefix, categoryPrefixes) {
const QString fullPrefix = prefix + QStringLiteral(": ");
if (text.startsWith(fullPrefix)) {
text.remove(0, fullPrefix.length());
break;
}
}
}
QString tweakedDiagnosticText(const QString &diagnosticText) QString tweakedDiagnosticText(const QString &diagnosticText)
{ {
// Examples: // Examples:
@@ -70,7 +50,7 @@ QString tweakedDiagnosticText(const QString &diagnosticText)
QString tweakedText = diagnosticText; QString tweakedText = diagnosticText;
if (!tweakedText.isEmpty()) { if (!tweakedText.isEmpty()) {
removeDiagnosticCategoryPrefix(tweakedText); tweakedText = ClangCodeModel::Utils::diagnosticCategoryPrefixRemoved(tweakedText);
capitalizeText(tweakedText); capitalizeText(tweakedText);
} }

View File

@@ -27,6 +27,7 @@
#include "clangconstants.h" #include "clangconstants.h"
#include "clangdiagnostictooltipwidget.h" #include "clangdiagnostictooltipwidget.h"
#include "clangutils.h"
#include <utils/utilsicons.h> #include <utils/utilsicons.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
@@ -75,20 +76,20 @@ ClangTextMark::ClangTextMark(const FileName &fileName,
, m_removedFromEditorHandler(removedHandler) , m_removedFromEditorHandler(removedHandler)
{ {
const bool warning = isWarningOrNote(diagnostic.severity); const bool warning = isWarningOrNote(diagnostic.severity);
setColor(warning ? Utils::Theme::ClangCodeModel_Warning_TextMarkColor setColor(warning ? ::Utils::Theme::ClangCodeModel_Warning_TextMarkColor
: Utils::Theme::ClangCodeModel_Error_TextMarkColor); : ::Utils::Theme::ClangCodeModel_Error_TextMarkColor);
setDefaultToolTip(warning ? QApplication::translate("Clang Code Model Marks", "Code Model Warning") setDefaultToolTip(warning ? QApplication::translate("Clang Code Model Marks", "Code Model Warning")
: QApplication::translate("Clang Code Model Marks", "Code Model Error")); : QApplication::translate("Clang Code Model Marks", "Code Model Error"));
setPriority(warning ? TextEditor::TextMark::NormalPriority setPriority(warning ? TextEditor::TextMark::NormalPriority
: TextEditor::TextMark::HighPriority); : TextEditor::TextMark::HighPriority);
updateIcon(); updateIcon();
if (showLineAnnotations) if (showLineAnnotations)
setLineAnnotation(diagnostic.text.toString()); setLineAnnotation(Utils::diagnosticCategoryPrefixRemoved(diagnostic.text.toString()));
} }
void ClangTextMark::updateIcon(bool valid) void ClangTextMark::updateIcon(bool valid)
{ {
using namespace Utils::Icons; using namespace ::Utils::Icons;
if (isWarningOrNote(m_diagnostic.severity)) if (isWarningOrNote(m_diagnostic.severity))
setIcon(valid ? CODEMODEL_WARNING.icon() : CODEMODEL_DISABLED_WARNING.icon()); setIcon(valid ? CODEMODEL_WARNING.icon() : CODEMODEL_DISABLED_WARNING.icon());
else else

View File

@@ -307,5 +307,30 @@ CPlusPlus::Icons::IconType iconTypeForToken(const ClangBackEnd::TokenInfoContain
return CPlusPlus::Icons::UnknownIconType; return CPlusPlus::Icons::UnknownIconType;
} }
QString diagnosticCategoryPrefixRemoved(const QString &text)
{
QString theText = text;
// Prefixes are taken from $LLVM_SOURCE_DIR/tools/clang/lib/Frontend/TextDiagnostic.cpp,
// function TextDiagnostic::printDiagnosticLevel (llvm-3.6.2).
static const QStringList categoryPrefixes = {
QStringLiteral("note"),
QStringLiteral("remark"),
QStringLiteral("warning"),
QStringLiteral("error"),
QStringLiteral("fatal error")
};
for (const QString &prefix : categoryPrefixes) {
const QString fullPrefix = prefix + QStringLiteral(": ");
if (theText.startsWith(fullPrefix)) {
theText.remove(0, fullPrefix.length());
return theText;
}
}
return text;
}
} // namespace Utils } // namespace Utils
} // namespace Clang } // namespace Clang

View File

@@ -56,6 +56,8 @@ bool isProjectPartLoaded(const CppTools::ProjectPart::Ptr projectPart);
QString projectPartIdForFile(const QString &filePath); QString projectPartIdForFile(const QString &filePath);
int clangColumn(const QTextBlock &lineText, int cppEditorColumn); int clangColumn(const QTextBlock &lineText, int cppEditorColumn);
QString diagnosticCategoryPrefixRemoved(const QString &text);
CPlusPlus::Icons::IconType iconTypeForToken(const ClangBackEnd::TokenInfoContainer &token); CPlusPlus::Icons::IconType iconTypeForToken(const ClangBackEnd::TokenInfoContainer &token);
} // namespace Utils } // namespace Utils