forked from qt-creator/qt-creator
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 <david.schulz@qt.io>
This commit is contained in:
@@ -376,9 +376,11 @@ void ClangDiagnosticManager::generateEditorSelections()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ClangDiagnosticManager::processNewDiagnostics(
|
void ClangDiagnosticManager::processNewDiagnostics(
|
||||||
const QVector<ClangBackEnd::DiagnosticContainer> &allDiagnostics)
|
const QVector<ClangBackEnd::DiagnosticContainer> &allDiagnostics,
|
||||||
|
bool showTextMarkAnnotations)
|
||||||
{
|
{
|
||||||
m_diagnosticsInvalidated = false;
|
m_diagnosticsInvalidated = false;
|
||||||
|
m_showTextMarkAnnotations = showTextMarkAnnotations;
|
||||||
filterDiagnostics(allDiagnostics);
|
filterDiagnostics(allDiagnostics);
|
||||||
|
|
||||||
generateTextMarks();
|
generateTextMarks();
|
||||||
@@ -401,7 +403,8 @@ void ClangDiagnosticManager::addClangTextMarks(
|
|||||||
m_clangTextMarks.erase(it, m_clangTextMarks.end());
|
m_clangTextMarks.erase(it, m_clangTextMarks.end());
|
||||||
delete mark;
|
delete mark;
|
||||||
};
|
};
|
||||||
auto textMark = new ClangTextMark(filePath(), diagnostic, onMarkRemoved);
|
auto textMark = new ClangTextMark(filePath(), diagnostic, onMarkRemoved,
|
||||||
|
m_showTextMarkAnnotations);
|
||||||
m_clangTextMarks.push_back(textMark);
|
m_clangTextMarks.push_back(textMark);
|
||||||
m_textDocument->addMark(textMark);
|
m_textDocument->addMark(textMark);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,8 @@ public:
|
|||||||
ClangDiagnosticManager(TextEditor::TextDocument *textDocument);
|
ClangDiagnosticManager(TextEditor::TextDocument *textDocument);
|
||||||
~ClangDiagnosticManager();
|
~ClangDiagnosticManager();
|
||||||
|
|
||||||
void processNewDiagnostics(const QVector<ClangBackEnd::DiagnosticContainer> &allDiagnostics);
|
void processNewDiagnostics(const QVector<ClangBackEnd::DiagnosticContainer> &allDiagnostics,
|
||||||
|
bool showTextMarkAnnotations);
|
||||||
|
|
||||||
const QVector<ClangBackEnd::DiagnosticContainer> &diagnosticsWithFixIts() const;
|
const QVector<ClangBackEnd::DiagnosticContainer> &diagnosticsWithFixIts() const;
|
||||||
QList<QTextEdit::ExtraSelection> takeExtraSelections();
|
QList<QTextEdit::ExtraSelection> takeExtraSelections();
|
||||||
@@ -82,6 +83,7 @@ private:
|
|||||||
TextEditor::RefactorMarkers m_fixItAvailableMarkers;
|
TextEditor::RefactorMarkers m_fixItAvailableMarkers;
|
||||||
std::vector<ClangTextMark *> m_clangTextMarks;
|
std::vector<ClangTextMark *> m_clangTextMarks;
|
||||||
bool m_diagnosticsInvalidated = false;
|
bool m_diagnosticsInvalidated = false;
|
||||||
|
bool m_showTextMarkAnnotations = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ void ClangEditorDocumentProcessor::updateCodeWarnings(
|
|||||||
uint documentRevision)
|
uint documentRevision)
|
||||||
{
|
{
|
||||||
if (documentRevision == revision()) {
|
if (documentRevision == revision()) {
|
||||||
m_diagnosticManager.processNewDiagnostics(diagnostics);
|
m_diagnosticManager.processNewDiagnostics(diagnostics, m_isProjectFile);
|
||||||
const auto codeWarnings = m_diagnosticManager.takeExtraSelections();
|
const auto codeWarnings = m_diagnosticManager.takeExtraSelections();
|
||||||
const auto fixitAvailableMarkers = m_diagnosticManager.takeFixItAvailableMarkers();
|
const auto fixitAvailableMarkers = m_diagnosticManager.takeFixItAvailableMarkers();
|
||||||
const auto creator = creatorForHeaderErrorDiagnosticWidget(firstHeaderErrorDiagnostic);
|
const auto creator = creatorForHeaderErrorDiagnosticWidget(firstHeaderErrorDiagnostic);
|
||||||
@@ -368,6 +368,8 @@ void ClangEditorDocumentProcessor::updateProjectPartAndTranslationUnitForEditor(
|
|||||||
registerTranslationUnitForEditor(projectPart.data());
|
registerTranslationUnitForEditor(projectPart.data());
|
||||||
|
|
||||||
m_projectPart = projectPart;
|
m_projectPart = projectPart;
|
||||||
|
m_isProjectFile = m_parser->projectPartInfo().hints
|
||||||
|
& CppTools::ProjectPartInfo::IsFromProjectMatch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ private:
|
|||||||
IpcCommunicator &m_ipcCommunicator;
|
IpcCommunicator &m_ipcCommunicator;
|
||||||
QSharedPointer<ClangEditorDocumentParser> m_parser;
|
QSharedPointer<ClangEditorDocumentParser> m_parser;
|
||||||
CppTools::ProjectPart::Ptr m_projectPart;
|
CppTools::ProjectPart::Ptr m_projectPart;
|
||||||
|
bool m_isProjectFile = false;
|
||||||
QFutureWatcher<void> m_parserWatcher;
|
QFutureWatcher<void> m_parserWatcher;
|
||||||
QTimer m_updateTranslationUnitTimer;
|
QTimer m_updateTranslationUnitTimer;
|
||||||
unsigned m_parserRevision;
|
unsigned m_parserRevision;
|
||||||
|
|||||||
@@ -64,7 +64,8 @@ Core::Id cartegoryForSeverity(ClangBackEnd::DiagnosticSeverity severity)
|
|||||||
|
|
||||||
ClangTextMark::ClangTextMark(const QString &fileName,
|
ClangTextMark::ClangTextMark(const QString &fileName,
|
||||||
const ClangBackEnd::DiagnosticContainer &diagnostic,
|
const ClangBackEnd::DiagnosticContainer &diagnostic,
|
||||||
const RemovedFromEditorHandler &removedHandler)
|
const RemovedFromEditorHandler &removedHandler,
|
||||||
|
bool showLineAnnotations)
|
||||||
: TextEditor::TextMark(fileName,
|
: TextEditor::TextMark(fileName,
|
||||||
int(diagnostic.location().line()),
|
int(diagnostic.location().line()),
|
||||||
cartegoryForSeverity(diagnostic.severity()))
|
cartegoryForSeverity(diagnostic.severity()))
|
||||||
@@ -79,7 +80,8 @@ ClangTextMark::ClangTextMark(const QString &fileName,
|
|||||||
setPriority(warning ? TextEditor::TextMark::NormalPriority
|
setPriority(warning ? TextEditor::TextMark::NormalPriority
|
||||||
: TextEditor::TextMark::HighPriority);
|
: TextEditor::TextMark::HighPriority);
|
||||||
updateIcon();
|
updateIcon();
|
||||||
setLineAnnotation(diagnostic.text().toString());
|
if (showLineAnnotations)
|
||||||
|
setLineAnnotation(diagnostic.text().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangTextMark::updateIcon(bool valid)
|
void ClangTextMark::updateIcon(bool valid)
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ public:
|
|||||||
|
|
||||||
ClangTextMark(const QString &fileName,
|
ClangTextMark(const QString &fileName,
|
||||||
const ClangBackEnd::DiagnosticContainer &diagnostic,
|
const ClangBackEnd::DiagnosticContainer &diagnostic,
|
||||||
const RemovedFromEditorHandler &removedHandler);
|
const RemovedFromEditorHandler &removedHandler,
|
||||||
|
bool showLineAnnotations);
|
||||||
|
|
||||||
void updateIcon(bool valid = true);
|
void updateIcon(bool valid = true);
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user