9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_DIAGNOSTICS_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_DIAGNOSTICS_H
13#include "clang/Basic/Diagnostic.h"
14#include "clang/Basic/LangOptions.h"
15#include "clang/Basic/SourceLocation.h"
16#include "llvm/ADT/ArrayRef.h"
17#include "llvm/ADT/DenseSet.h"
18#include "llvm/ADT/SmallVector.h"
19#include "llvm/ADT/StringSet.h"
20#include "llvm/Support/JSON.h"
21#include "llvm/Support/SourceMgr.h"
32class ClangTidyContext;
67 DiagnosticsEngine::Level
Severity = DiagnosticsEngine::Note;
85 llvm::SmallVector<TextEdit, 1>
Edits;
88 llvm::SmallVector<std::pair<ChangeAnnotationIdentifier, ChangeAnnotation>>
112 llvm::SmallVector<DiagnosticTag, 1>
Tags;
132 llvm::StringRef
Name);
144 const Preprocessor *PP)
override;
147 const clang::Diagnostic &
Info)
override;
151 using DiagFixer = std::function<std::vector<Fix>(DiagnosticsEngine::Level,
152 const clang::Diagnostic &)>;
154 DiagnosticsEngine::Level,
const clang::Diagnostic &)>;
156 std::function<void(
const clang::Diagnostic &,
clangd::Diag &)>;
168 void flushLastDiag();
173 std::vector<Diag> Output;
174 std::optional<LangOptions> LangOpts;
175 std::optional<Diag> LastDiag;
176 std::optional<FullSourceLoc> LastDiagLoc;
177 bool LastDiagOriginallyError =
false;
178 SourceManager *OrigSrcMgr =
nullptr;
180 llvm::DenseSet<std::pair<unsigned, unsigned>> IncludedErrorLocations;
185 const llvm::StringSet<> &Suppressed,
186 const LangOptions &);
llvm::SmallString< 256U > Name
StoreDiags collects the diagnostics that can later be reported by clangd.
void contributeFixes(DiagFixer Fixer)
If set, possibly adds fixes for diagnostics using Fixer.
void setLevelAdjuster(LevelAdjuster Adjuster)
If set, this allows the client of this class to adjust the level of diagnostics, such as promoting wa...
std::function< void(const clang::Diagnostic &, clangd::Diag &)> DiagCallback
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &Info) override
std::vector< Diag > take(const clang::tidy::ClangTidyContext *Tidy=nullptr)
void setDiagCallback(DiagCallback CB)
Invokes a callback every time a diagnostics is completely formed.
std::function< DiagnosticsEngine::Level(DiagnosticsEngine::Level, const clang::Diagnostic &)> LevelAdjuster
void BeginSourceFile(const LangOptions &Opts, const Preprocessor *PP) override
std::function< std::vector< Fix >(DiagnosticsEngine::Level, const clang::Diagnostic &)> DiagFixer
When passed a main diagnostic, returns fixes to add to it.
void EndSourceFile() override
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
@ Info
An information message.
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.
bool isBuiltinDiagnosticSuppressed(unsigned ID, const llvm::StringSet<> &Suppress, const LangOptions &LangOpts)
Determine whether a (non-clang-tidy) diagnostic is suppressed by config.
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const CodeCompletion &C)
llvm::StringRef normalizeSuppressedCode(llvm::StringRef Code)
Take a user-specified diagnostic code, and convert it to a normalized form stored in the config and c...
Diag toDiag(const llvm::SMDiagnostic &D, Diag::DiagSource Source)
int getSeverity(DiagnosticsEngine::Level L)
Convert from clang diagnostic level to LSP severity.
std::optional< std::string > getDiagnosticDocURI(Diag::DiagSource Source, unsigned ID, llvm::StringRef Name)
Returns a URI providing more information about a particular diagnostic.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
bool EmbedFixesInDiagnostics
If true, Clangd uses an LSP extension to embed the fixes with the diagnostics that are sent to the cl...
bool SendDiagnosticCategory
If true, Clangd uses an LSP extension to send the diagnostic's category to the client.
bool DisplayFixesCount
If true, Clangd will add a number of available fixes to the diagnostic's message.
bool EmitRelatedLocations
If true, Clangd uses the relatedInformation field to include other locations (in particular attached ...
Contains basic information about a diagnostic.
llvm::json::Object OpaqueData
DiagnosticsEngine::Level Severity
std::optional< std::string > AbsFile
A top-level diagnostic that may have Notes and Fixes.
std::vector< Fix > Fixes
Alternative fixes for this diagnostic, one should be chosen.
llvm::SmallVector< DiagnosticTag, 1 > Tags
enum clang::clangd::Diag::DiagSource Source
std::vector< Note > Notes
Elaborate on the problem, usually pointing to a related piece of code.
Represents a single fix-it that editor can apply to fix the error.
llvm::SmallVector< std::pair< ChangeAnnotationIdentifier, ChangeAnnotation > > Annotations
Annotations for the Edits.
std::string Message
Message for the fix-it.
llvm::SmallVector< TextEdit, 1 > Edits
TextEdits from clang's fix-its. Must be non-empty.
Represents a note for the diagnostic.