9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_DIAGNOSTICS_H 10 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_DIAGNOSTICS_H 14 #include "clang/Basic/Diagnostic.h" 15 #include "clang/Basic/LangOptions.h" 16 #include "llvm/ADT/ArrayRef.h" 17 #include "llvm/ADT/DenseSet.h" 18 #include "llvm/ADT/None.h" 19 #include "llvm/ADT/Optional.h" 20 #include "llvm/ADT/STLExtras.h" 21 #include "llvm/ADT/StringSet.h" 27 class ClangTidyContext;
34 bool EmbedFixesInDiagnostics =
false;
39 bool EmitRelatedLocations =
false;
45 bool SendDiagnosticCategory =
false;
49 bool DisplayFixesCount =
true;
62 DiagnosticsEngine::Level Severity = DiagnosticsEngine::Note;
66 bool InsideMainFile =
false;
75 llvm::SmallVector<TextEdit, 1>
Edits;
77 llvm::raw_ostream &
operator<<(llvm::raw_ostream &OS,
const Fix &F);
124 void BeginSourceFile(
const LangOptions &Opts,
const Preprocessor *)
override;
125 void EndSourceFile()
override;
126 void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
127 const clang::Diagnostic &
Info)
override;
129 using DiagFixer = std::function<std::vector<Fix>(DiagnosticsEngine::Level,
130 const clang::Diagnostic &)>;
131 using LevelAdjuster = std::function<DiagnosticsEngine::Level(
132 DiagnosticsEngine::Level,
const clang::Diagnostic &)>;
141 void flushLastDiag();
144 LevelAdjuster Adjuster =
nullptr;
145 std::vector<Diag> Output;
146 llvm::Optional<LangOptions> LangOpts;
147 llvm::Optional<Diag> LastDiag;
149 bool LastDiagWasAdjusted =
false;
150 llvm::DenseSet<int> IncludeLinesWithErrors;
151 bool LastPrimaryDiagnosticWasSuppressed =
false;
157 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_DIAGNOSTICS_H
StoreDiags collects the diagnostics that can later be reported by clangd.
Contains basic information about a diagnostic.
CodeAction toCodeAction(const Fix &F, const URIForFile &File)
Convert from Fix to LSP CodeAction.
void contributeFixes(DiagFixer Fixer)
If set, possibly adds fixes for diagnostics using Fixer.
A code action represents a change that can be performed in code, e.g.
std::function< DiagnosticsEngine::Level(DiagnosticsEngine::Level, const clang::Diagnostic &)> LevelAdjuster
A top-level diagnostic that may have Notes and Fixes.
std::string Message
Message for the fix-it.
std::vector< Fix > Fixes
Alternative fixes for this diagnostic, one should be chosen.
llvm::SmallVector< TextEdit, 1 > Edits
TextEdits from clang's fix-its. Must be non-empty.
void toLSPDiags(const Diag &D, const URIForFile &File, const ClangdDiagnosticOptions &Opts, llvm::function_ref< void(clangd::Diagnostic, llvm::ArrayRef< Fix >)> OutFn)
Conversion to LSP diagnostics.
int getSeverity(DiagnosticsEngine::Level L)
Convert from clang diagnostic level to LSP severity.
Represents a single fix-it that editor can apply to fix the error.
std::vector< Note > Notes
Elaborate on the problem, usually pointing to a related piece of code.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Represents a note for the diagnostic.
std::function< std::vector< Fix >(DiagnosticsEngine::Level, const clang::Diagnostic &)> DiagFixer
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const CodeCompletion &C)
void setLevelAdjuster(LevelAdjuster Adjuster)
If set, this allows the client of this class to adjust the level of diagnostics, such as promoting wa...
llvm::Optional< std::string > AbsFile