Skip to content

Commit 9e4886e

Browse files
committed
basic,diagnostic: move diagnostic related to diagnostics.go
Signed-off-by: Koichi Shiraishi <[email protected]>
1 parent 6da8bea commit 9e4886e

10 files changed

+741
-735
lines changed

basic.go

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
package protocol
55

66
import (
7-
"strconv"
8-
97
"go.lsp.dev/uri"
108
)
119

@@ -99,125 +97,6 @@ type LocationLink struct {
9997
TargetSelectionRange Range `json:"targetSelectionRange"`
10098
}
10199

102-
// Diagnostic represents a diagnostic, such as a compiler error or warning.
103-
//
104-
// Diagnostic objects are only valid in the scope of a resource.
105-
type Diagnostic struct {
106-
// Range is the range at which the message applies.
107-
Range Range `json:"range"`
108-
109-
// Severity is the diagnostic's severity. Can be omitted. If omitted it is up to the
110-
// client to interpret diagnostics as error, warning, info or hint.
111-
Severity DiagnosticSeverity `json:"severity,omitempty"`
112-
113-
// Code is the diagnostic's code, which might appear in the user interface.
114-
Code interface{} `json:"code,omitempty"` // int32 | string;
115-
116-
// CodeDescription an optional property to describe the error code.
117-
//
118-
// @since 3.16.0.
119-
CodeDescription *CodeDescription `json:"codeDescription,omitempty"`
120-
121-
// Source a human-readable string describing the source of this
122-
// diagnostic, e.g. 'typescript' or 'super lint'.
123-
Source string `json:"source,omitempty"`
124-
125-
// Message is the diagnostic's message.
126-
Message string `json:"message"`
127-
128-
// Tags is the additional metadata about the diagnostic.
129-
//
130-
// @since 3.15.0.
131-
Tags []DiagnosticTag `json:"tags,omitempty"`
132-
133-
// RelatedInformation an array of related diagnostic information, e.g. when symbol-names within
134-
// a scope collide all definitions can be marked via this property.
135-
RelatedInformation []DiagnosticRelatedInformation `json:"relatedInformation,omitempty"`
136-
137-
// Data is a data entry field that is preserved between a
138-
// "textDocument/publishDiagnostics" notification and
139-
// "textDocument/codeAction" request.
140-
//
141-
// @since 3.16.0.
142-
Data interface{} `json:"data,omitempty"`
143-
}
144-
145-
// DiagnosticSeverity indicates the severity of a Diagnostic message.
146-
type DiagnosticSeverity float64
147-
148-
const (
149-
// DiagnosticSeverityError reports an error.
150-
DiagnosticSeverityError DiagnosticSeverity = 1
151-
152-
// DiagnosticSeverityWarning reports a warning.
153-
DiagnosticSeverityWarning DiagnosticSeverity = 2
154-
155-
// DiagnosticSeverityInformation reports an information.
156-
DiagnosticSeverityInformation DiagnosticSeverity = 3
157-
158-
// DiagnosticSeverityHint reports a hint.
159-
DiagnosticSeverityHint DiagnosticSeverity = 4
160-
)
161-
162-
// String implements fmt.Stringer.
163-
func (d DiagnosticSeverity) String() string {
164-
switch d {
165-
case DiagnosticSeverityError:
166-
return "Error"
167-
case DiagnosticSeverityWarning:
168-
return "Warning"
169-
case DiagnosticSeverityInformation:
170-
return "Information"
171-
case DiagnosticSeverityHint:
172-
return "Hint"
173-
default:
174-
return strconv.FormatFloat(float64(d), 'f', -10, 64)
175-
}
176-
}
177-
178-
// DiagnosticTag is the diagnostic tags.
179-
//
180-
// @since 3.15.0.
181-
type DiagnosticTag float64
182-
183-
// list of DiagnosticTag.
184-
const (
185-
// DiagnosticTagUnnecessary unused or unnecessary code.
186-
//
187-
// Clients are allowed to render diagnostics with this tag faded out instead of having
188-
// an error squiggle.
189-
DiagnosticTagUnnecessary DiagnosticTag = 1
190-
191-
// DiagnosticTagDeprecated deprecated or obsolete code.
192-
//
193-
// Clients are allowed to rendered diagnostics with this tag strike through.
194-
DiagnosticTagDeprecated DiagnosticTag = 2
195-
)
196-
197-
// String implements fmt.Stringer.
198-
func (d DiagnosticTag) String() string {
199-
switch d {
200-
case DiagnosticTagUnnecessary:
201-
return "Unnecessary"
202-
case DiagnosticTagDeprecated:
203-
return "Deprecated"
204-
default:
205-
return strconv.FormatFloat(float64(d), 'f', -10, 64)
206-
}
207-
}
208-
209-
// DiagnosticRelatedInformation represents a related message and source code location for a diagnostic.
210-
//
211-
// This should be used to point to code locations that cause or related to a diagnostics, e.g when duplicating
212-
// a symbol in a scope.
213-
type DiagnosticRelatedInformation struct {
214-
// Location is the location of this related diagnostic information.
215-
Location Location `json:"location"`
216-
217-
// Message is the message of this related diagnostic information.
218-
Message string `json:"message"`
219-
}
220-
221100
// CodeDescription is the structure to capture a description for an error code.
222101
//
223102
// @since 3.16.0.

basic_gojay.go

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -193,122 +193,6 @@ var (
193193
_ gojay.UnmarshalerJSONObject = (*LocationLink)(nil)
194194
)
195195

196-
// MarshalJSONObject implements gojay.MarshalerJSONObject.
197-
func (v *Diagnostic) MarshalJSONObject(enc *gojay.Encoder) {
198-
enc.ObjectKey(keyRange, &v.Range)
199-
enc.Float64KeyOmitEmpty(keySeverity, float64(v.Severity))
200-
enc.AddInterfaceKeyOmitEmpty(keyCode, v.Code)
201-
enc.ObjectKeyOmitEmpty(keyCodeDescription, v.CodeDescription)
202-
enc.StringKeyOmitEmpty(keySource, v.Source)
203-
enc.StringKey(keyMessage, v.Message)
204-
enc.ArrayKeyOmitEmpty(keyTags, DiagnosticTags(v.Tags))
205-
enc.ArrayKeyOmitEmpty(keyRelatedInformation, DiagnosticRelatedInformations(v.RelatedInformation))
206-
enc.AddInterfaceKeyOmitEmpty(keyData, v.Data)
207-
}
208-
209-
// IsNil returns wether the structure is nil value or not.
210-
func (v *Diagnostic) IsNil() bool { return v == nil }
211-
212-
// UnmarshalJSONObject implements gojay's UnmarshalerJSONObject.
213-
func (v *Diagnostic) UnmarshalJSONObject(dec *gojay.Decoder, k string) error {
214-
switch k {
215-
case keyRange:
216-
return dec.Object(&v.Range)
217-
case keySeverity:
218-
return dec.Float64((*float64)(&v.Severity))
219-
case keyCode:
220-
return dec.Interface(&v.Code)
221-
case keyCodeDescription:
222-
if v.CodeDescription == nil {
223-
v.CodeDescription = &CodeDescription{}
224-
}
225-
return dec.Object(v.CodeDescription)
226-
case keySource:
227-
return dec.String(&v.Source)
228-
case keyMessage:
229-
return dec.String(&v.Message)
230-
case keyTags:
231-
return dec.Array((*DiagnosticTags)(&v.Tags))
232-
case keyRelatedInformation:
233-
values := DiagnosticRelatedInformations{}
234-
err := dec.Array(&values)
235-
if err == nil && len(values) > 0 {
236-
v.RelatedInformation = []DiagnosticRelatedInformation(values)
237-
}
238-
return err
239-
case keyData:
240-
return dec.Interface(&v.Data)
241-
}
242-
return nil
243-
}
244-
245-
// NKeys returns the number of keys to unmarshal.
246-
func (v *Diagnostic) NKeys() int { return 9 }
247-
248-
// compile time check whether the Diagnostic implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces.
249-
var (
250-
_ gojay.MarshalerJSONObject = (*Diagnostic)(nil)
251-
_ gojay.UnmarshalerJSONObject = (*Diagnostic)(nil)
252-
)
253-
254-
// DiagnosticTags represents a slice of DiagnosticTag.
255-
type DiagnosticTags []DiagnosticTag
256-
257-
// MarshalJSONArray implements gojay.MarshalerJSONArray.
258-
func (v DiagnosticTags) MarshalJSONArray(enc *gojay.Encoder) {
259-
for i := range v {
260-
enc.Float64(float64(v[i]))
261-
}
262-
}
263-
264-
// IsNil implements gojay.MarshalerJSONArray.
265-
func (v DiagnosticTags) IsNil() bool { return len(v) == 0 }
266-
267-
// UnmarshalJSONArray implements gojay.UnmarshalerJSONArray.
268-
func (v *DiagnosticTags) UnmarshalJSONArray(dec *gojay.Decoder) error {
269-
var value DiagnosticTag
270-
if err := dec.Float64((*float64)(&value)); err != nil {
271-
return err
272-
}
273-
*v = append(*v, value)
274-
return nil
275-
}
276-
277-
// compile time check whether the CodeActionKinds implements a gojay.MarshalerJSONArray and gojay.UnmarshalerJSONArray interfaces.
278-
var (
279-
_ gojay.MarshalerJSONArray = (*DiagnosticTags)(nil)
280-
_ gojay.UnmarshalerJSONArray = (*DiagnosticTags)(nil)
281-
)
282-
283-
// MarshalJSONObject implements gojay.MarshalerJSONObject.
284-
func (v *DiagnosticRelatedInformation) MarshalJSONObject(enc *gojay.Encoder) {
285-
enc.ObjectKey(keyLocation, &v.Location)
286-
enc.StringKey(keyMessage, v.Message)
287-
}
288-
289-
// IsNil returns wether the structure is nil value or not.
290-
func (v *DiagnosticRelatedInformation) IsNil() bool { return v == nil }
291-
292-
// UnmarshalJSONObject implements gojay's UnmarshalerJSONObject.
293-
func (v *DiagnosticRelatedInformation) UnmarshalJSONObject(dec *gojay.Decoder, k string) error {
294-
switch k {
295-
case keyLocation:
296-
return dec.Object(&v.Location)
297-
case keyMessage:
298-
return dec.String(&v.Message)
299-
}
300-
return nil
301-
}
302-
303-
// NKeys returns the number of keys to unmarshal.
304-
func (v *DiagnosticRelatedInformation) NKeys() int { return 2 }
305-
306-
// compile time check whether the DiagnosticRelatedInformation implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces.
307-
var (
308-
_ gojay.MarshalerJSONObject = (*DiagnosticRelatedInformation)(nil)
309-
_ gojay.UnmarshalerJSONObject = (*DiagnosticRelatedInformation)(nil)
310-
)
311-
312196
// MarshalJSONObject implements gojay.MarshalerJSONObject.
313197
func (v *CodeDescription) MarshalJSONObject(enc *gojay.Encoder) {
314198
enc.StringKey(keyHref, string(v.Href))

basic_gojay_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ func TestLocationLink(t *testing.T) { testLocationLink(t, gojay.Marshal, gojay.U
2222

2323
func TestCodeDescription(t *testing.T) { testCodeDescription(t, gojay.Marshal, gojay.Unsafe.Unmarshal) }
2424

25-
func TestDiagnostic(t *testing.T) { testDiagnostic(t, gojay.Marshal, gojay.Unsafe.Unmarshal) }
26-
27-
func TestDiagnosticRelatedInformation(t *testing.T) {
28-
testDiagnosticRelatedInformation(t, gojay.Marshal, gojay.Unsafe.Unmarshal)
29-
}
30-
3125
func TestCommand(t *testing.T) { testCommand(t, gojay.Marshal, gojay.Unsafe.Unmarshal) }
3226

3327
func TestChangeAnnotation(t *testing.T) {

basic_json_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ func TestLocationLink(t *testing.T) { testLocationLink(t, json.Marshal, json.Unm
2121

2222
func TestCodeDescription(t *testing.T) { testCodeDescription(t, json.Marshal, json.Unmarshal) }
2323

24-
func TestDiagnostic(t *testing.T) { testDiagnostic(t, json.Marshal, json.Unmarshal) }
25-
26-
func TestDiagnosticRelatedInformation(t *testing.T) {
27-
testDiagnosticRelatedInformation(t, json.Marshal, json.Unmarshal)
28-
}
29-
3024
func TestCommand(t *testing.T) { testCommand(t, json.Marshal, json.Unmarshal) }
3125

3226
func TestChangeAnnotation(t *testing.T) { testChangeAnnotation(t, json.Marshal, json.Unmarshal) }

0 commit comments

Comments
 (0)