Commit e1de989e authored by Nikolai Kosjar's avatar Nikolai Kosjar

Clang: Show inline diagnostics only for project files

When navigating to headers that are not part of the project, avoid
showing the inline diagnostics. In most cases, these files can't be
changed.

This helps also for the session-load case where files are opened/parsed
when no project information is available yet.

Change-Id: I7fce24af78b3b1efbf64dd27d8ca2a053e02d4ec
Reviewed-by: David Schulz's avatarDavid Schulz <david.schulz@qt.io>
parent dc1bdc9b
......@@ -376,9 +376,11 @@ void ClangDiagnosticManager::generateEditorSelections()
}
void ClangDiagnosticManager::processNewDiagnostics(
const QVector<ClangBackEnd::DiagnosticContainer> &allDiagnostics)
const QVector<ClangBackEnd::DiagnosticContainer> &allDiagnostics,
bool showTextMarkAnnotations)
{
m_diagnosticsInvalidated = false;
m_showTextMarkAnnotations = showTextMarkAnnotations;
filterDiagnostics(allDiagnostics);
generateTextMarks();
......@@ -401,7 +403,8 @@ void ClangDiagnosticManager::addClangTextMarks(
m_clangTextMarks.erase(it, m_clangTextMarks.end());
delete mark;
};
auto textMark = new ClangTextMark(filePath(), diagnostic, onMarkRemoved);
auto textMark = new ClangTextMark(filePath(), diagnostic, onMarkRemoved,
m_showTextMarkAnnotations);
m_clangTextMarks.push_back(textMark);
m_textDocument->addMark(textMark);
}
......
......@@ -49,7 +49,8 @@ public:
ClangDiagnosticManager(TextEditor::TextDocument *textDocument);
~ClangDiagnosticManager();
void processNewDiagnostics(const QVector<ClangBackEnd::DiagnosticContainer> &allDiagnostics);
void processNewDiagnostics(const QVector<ClangBackEnd::DiagnosticContainer> &allDiagnostics,
bool showTextMarkAnnotations);
const QVector<ClangBackEnd::DiagnosticContainer> &diagnosticsWithFixIts() const;
QList<QTextEdit::ExtraSelection> takeExtraSelections();
......@@ -82,6 +83,7 @@ private:
TextEditor::RefactorMarkers m_fixItAvailableMarkers;
std::vector<ClangTextMark *> m_clangTextMarks;
bool m_diagnosticsInvalidated = false;
bool m_showTextMarkAnnotations = false;
};
} // namespace Internal
......
......@@ -180,7 +180,7 @@ void ClangEditorDocumentProcessor::updateCodeWarnings(
uint documentRevision)
{
if (documentRevision == revision()) {
m_diagnosticManager.processNewDiagnostics(diagnostics);
m_diagnosticManager.processNewDiagnostics(diagnostics, m_isProjectFile);
const auto codeWarnings = m_diagnosticManager.takeExtraSelections();
const auto fixitAvailableMarkers = m_diagnosticManager.takeFixItAvailableMarkers();
const auto creator = creatorForHeaderErrorDiagnosticWidget(firstHeaderErrorDiagnostic);
......@@ -368,6 +368,8 @@ void ClangEditorDocumentProcessor::updateProjectPartAndTranslationUnitForEditor(
registerTranslationUnitForEditor(projectPart.data());
m_projectPart = projectPart;
m_isProjectFile = m_parser->projectPartInfo().hints
& CppTools::ProjectPartInfo::IsFromProjectMatch;
}
}
......
......@@ -114,6 +114,7 @@ private:
IpcCommunicator &m_ipcCommunicator;
QSharedPointer<ClangEditorDocumentParser> m_parser;
CppTools::ProjectPart::Ptr m_projectPart;
bool m_isProjectFile = false;
QFutureWatcher<void> m_parserWatcher;
QTimer m_updateTranslationUnitTimer;
unsigned m_parserRevision;
......
......@@ -64,7 +64,8 @@ Core::Id cartegoryForSeverity(ClangBackEnd::DiagnosticSeverity severity)
ClangTextMark::ClangTextMark(const QString &fileName,
const ClangBackEnd::DiagnosticContainer &diagnostic,
const RemovedFromEditorHandler &removedHandler)
const RemovedFromEditorHandler &removedHandler,
bool showLineAnnotations)
: TextEditor::TextMark(fileName,
int(diagnostic.location().line()),
cartegoryForSeverity(diagnostic.severity()))
......@@ -79,6 +80,7 @@ ClangTextMark::ClangTextMark(const QString &fileName,
setPriority(warning ? TextEditor::TextMark::NormalPriority
: TextEditor::TextMark::HighPriority);
updateIcon();
if (showLineAnnotations)
setLineAnnotation(diagnostic.text().toString());
}
......
......@@ -41,7 +41,8 @@ public:
ClangTextMark(const QString &fileName,
const ClangBackEnd::DiagnosticContainer &diagnostic,
const RemovedFromEditorHandler &removedHandler);
const RemovedFromEditorHandler &removedHandler,
bool showLineAnnotations);
void updateIcon(bool valid = true);
private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment