nixd
Loading...
Searching...
No Matches
JSONDiagnostic.cpp
Go to the documentation of this file.
3#include "nixf/Basic/Range.h"
4
5using namespace nixf;
6using nlohmann::json;
7
8void nixf::to_json(json &R, const LexerCursor &LC) {
9 R = json{
10 {"line", LC.line()},
11 {"column", LC.column()},
12 {"offset", LC.offset()},
13 };
14}
15
16void nixf::to_json(json &R, const LexerCursorRange &LCR) {
17 R = json{
18 {"lCur", LCR.lCur()},
19 {"rCur", LCR.rCur()},
20 };
21}
22
23void nixf::to_json(json &R, const PartialDiagnostic &PD) {
24 R = json{
25 {"args", PD.args()},
26 {"tag", PD.tags()},
27 {"range", PD.range()},
28 };
29}
30
31void nixf::to_json(json &R, const Diagnostic &D) {
32 to_json(R, static_cast<const PartialDiagnostic &>(D));
33 R["kind"] = D.kind();
34 R["severity"] = Diagnostic::severity(D.kind());
35 R["message"] = D.message();
36 R["sname"] = D.sname();
37 R["notes"] = D.notes();
38 R["fixes"] = D.fixes();
39}
40
41void nixf::to_json(json &R, const Note &N) {
42 to_json(R, static_cast<const PartialDiagnostic &>(N));
43 R["kind"] = N.kind();
44 R["sname"] = N.sname();
45 R["message"] = N.message();
46}
47
48void nixf::to_json(json &R, const Fix &F) {
49 R = json{
50 {"edits", F.edits()},
51 {"message", F.message()},
52 };
53}
54
55void nixf::to_json(json &R, const TextEdit &D) {
56 R = json{
57 {"range", D.oldRange()},
58 {"newText", D.newText()},
59 };
60}
Provide jsonified diagnostic, for other languages/structured output.
static const char * message(DiagnosticKind Kind)
DiagnosticKind kind() const
Definition Diagnostic.h:176
static const char * sname(DiagnosticKind Kind)
const std::vector< Fix > & fixes() const
Definition Diagnostic.h:207
const std::vector< Note > & notes() const
Definition Diagnostic.h:201
const std::vector< TextEdit > & edits() const
Definition Diagnostic.h:70
const std::string & message() const
Definition Diagnostic.h:71
LexerCursor lCur() const
Definition Range.h:116
LexerCursor rCur() const
Definition Range.h:117
A point in the source file.
Definition Range.h:57
int64_t column() const
Column number, starting from 0.
Definition Range.h:96
std::size_t offset() const
Offset in the source file, starting from 0.
Definition Range.h:102
int64_t line() const
Line number, starting from 0.
Definition Range.h:93
NoteKind kind() const
Definition Diagnostic.h:135
static const char * sname(NoteKind Kind)
static const char * message(NoteKind Kind)
const std::vector< std::string > & args() const
Definition Diagnostic.h:92
const std::vector< DiagnosticTag > & tags() const
Definition Diagnostic.h:98
LexerCursorRange range() const
Definition Diagnostic.h:100
std::string_view newText() const
Definition Diagnostic.h:54
LexerCursorRange oldRange() const
Definition Diagnostic.h:53
void to_json(nlohmann::json &R, const LexerCursor &LC)