-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
diagnostics.go
149 lines (122 loc) · 4.52 KB
/
diagnostics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// SPDX-FileCopyrightText: 2019 The Go Language Server Authors
// SPDX-License-Identifier: BSD-3-Clause
package protocol
import (
"strconv"
)
// Diagnostic represents a diagnostic, such as a compiler error or warning.
//
// Diagnostic objects are only valid in the scope of a resource.
type Diagnostic struct {
// Range is the range at which the message applies.
Range Range `json:"range"`
// Severity is the diagnostic's severity. Can be omitted. If omitted it is up to the
// client to interpret diagnostics as error, warning, info or hint.
Severity DiagnosticSeverity `json:"severity,omitempty"`
// Code is the diagnostic's code, which might appear in the user interface.
Code interface{} `json:"code,omitempty"` // int32 | string;
// CodeDescription an optional property to describe the error code.
//
// @since 3.16.0.
CodeDescription *CodeDescription `json:"codeDescription,omitempty"`
// Source a human-readable string describing the source of this
// diagnostic, e.g. 'typescript' or 'super lint'.
Source string `json:"source,omitempty"`
// Message is the diagnostic's message.
Message string `json:"message"`
// Tags is the additional metadata about the diagnostic.
//
// @since 3.15.0.
Tags []DiagnosticTag `json:"tags,omitempty"`
// RelatedInformation an array of related diagnostic information, e.g. when symbol-names within
// a scope collide all definitions can be marked via this property.
RelatedInformation []DiagnosticRelatedInformation `json:"relatedInformation,omitempty"`
// Data is a data entry field that is preserved between a
// "textDocument/publishDiagnostics" notification and
// "textDocument/codeAction" request.
//
// @since 3.16.0.
Data interface{} `json:"data,omitempty"`
}
// DiagnosticSeverity indicates the severity of a Diagnostic message.
type DiagnosticSeverity float64
const (
// DiagnosticSeverityError reports an error.
DiagnosticSeverityError DiagnosticSeverity = 1
// DiagnosticSeverityWarning reports a warning.
DiagnosticSeverityWarning DiagnosticSeverity = 2
// DiagnosticSeverityInformation reports an information.
DiagnosticSeverityInformation DiagnosticSeverity = 3
// DiagnosticSeverityHint reports a hint.
DiagnosticSeverityHint DiagnosticSeverity = 4
)
// String implements fmt.Stringer.
func (d DiagnosticSeverity) String() string {
switch d {
case DiagnosticSeverityError:
return "Error"
case DiagnosticSeverityWarning:
return "Warning"
case DiagnosticSeverityInformation:
return "Information"
case DiagnosticSeverityHint:
return "Hint"
default:
return strconv.FormatFloat(float64(d), 'f', -10, 64)
}
}
// CodeDescription is the structure to capture a description for an error code.
//
// @since 3.16.0.
type CodeDescription struct {
// Href an URI to open with more information about the diagnostic error.
Href URI `json:"href"`
}
// DiagnosticTag is the diagnostic tags.
//
// @since 3.15.0.
type DiagnosticTag float64
// list of DiagnosticTag.
const (
// DiagnosticTagUnnecessary unused or unnecessary code.
//
// Clients are allowed to render diagnostics with this tag faded out instead of having
// an error squiggle.
DiagnosticTagUnnecessary DiagnosticTag = 1
// DiagnosticTagDeprecated deprecated or obsolete code.
//
// Clients are allowed to rendered diagnostics with this tag strike through.
DiagnosticTagDeprecated DiagnosticTag = 2
)
// String implements fmt.Stringer.
func (d DiagnosticTag) String() string {
switch d {
case DiagnosticTagUnnecessary:
return "Unnecessary"
case DiagnosticTagDeprecated:
return "Deprecated"
default:
return strconv.FormatFloat(float64(d), 'f', -10, 64)
}
}
// DiagnosticRelatedInformation represents a related message and source code location for a diagnostic.
//
// This should be used to point to code locations that cause or related to a diagnostics, e.g when duplicating
// a symbol in a scope.
type DiagnosticRelatedInformation struct {
// Location is the location of this related diagnostic information.
Location Location `json:"location"`
// Message is the message of this related diagnostic information.
Message string `json:"message"`
}
// PublishDiagnosticsParams represents a params of PublishDiagnostics notification.
type PublishDiagnosticsParams struct {
// URI is the URI for which diagnostic information is reported.
URI DocumentURI `json:"uri"`
// Version optional the version number of the document the diagnostics are published for.
//
// @since 3.15
Version uint32 `json:"version,omitempty"`
// Diagnostics an array of diagnostic information items.
Diagnostics []Diagnostic `json:"diagnostics"`
}