Skip to content

Commit 5c1ca11

Browse files
committed
basic: add more documentation and sort types
Signed-off-by: Koichi Shiraishi <[email protected]>
1 parent f794a95 commit 5c1ca11

File tree

2 files changed

+142
-115
lines changed

2 files changed

+142
-115
lines changed

basic.go

Lines changed: 88 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,37 @@ var EOL = []string{"\n", "\r\n", "\r"}
3030
//
3131
// The offsets are based on a UTF-16 string representation.
3232
// So a string of the form "a𐐀b" the character offset of the character "a" is 0,
33-
// the character offset of "𐐀" is 1 and the character offset of "b" is 3 since 𐐀 is represented using two code units in UTF-16.
33+
// the character offset of "𐐀" is 1 and the character offset of "b" is 3 since 𐐀 is represented using two code
34+
// units in UTF-16.
3435
//
35-
// To ensure that both client and server split the string into the same line representation the protocol
36-
// specifies the following end-of-line sequences: "\n", "\r\n' and "\r".
36+
// Positions are line end character agnostic. So you can not specify a position that
37+
// denotes "\r|\n" or "\n|" where "|" represents the character offset.
3738
//
3839
// A position is between two characters like an "insert" cursor in a editor.
3940
// Special values like for example "-1" to denote the end of a line are not supported.
4041
type Position struct {
4142
// Line position in a document (zero-based).
43+
//
44+
// If a line number is greater than the number of lines in a document, it defaults back to the number of lines in
45+
// the document.
46+
// If a line number is negative, it defaults to 0.
4247
Line uint32 `json:"line"`
4348

4449
// Character offset on a line in a document (zero-based).
4550
//
46-
// Assuming that the line is represented as a string, the "character" value represents the gap between the
51+
// Assuming that the line is represented as a string, the Character value represents the gap between the
4752
// "character" and "character + 1".
4853
//
49-
// If the character value is greater than the line length it defaults back to the
50-
// line length.
54+
// If the character value is greater than the line length it defaults back to the line length.
55+
// If a line number is negative, it defaults to 0.
5156
Character uint32 `json:"character"`
5257
}
5358

5459
// Range represents a text document expressed as (zero-based) start and end positions.
5560
//
5661
// A range is comparable to a selection in an editor. Therefore the end position is exclusive.
57-
// If you want to specify a range that contains a line including the line ending character(s) then use an end position denoting the start of the next line.
62+
// If you want to specify a range that contains a line including the line ending character(s) then use an end position
63+
// denoting the start of the next line.
5864
type Range struct {
5965
// Start is the range's start position.
6066
Start Position `json:"start"`
@@ -79,24 +85,21 @@ type LocationLink struct {
7985
// TargetURI is the target resource identifier of this link.
8086
TargetURI DocumentURI `json:"targetUri"`
8187

82-
// TargetRange is the full target range of this link. If the target for example is a symbol then target range is the
83-
// range enclosing this symbol not including leading/trailing whitespace but everything else
84-
// like comments. This information is typically used to highlight the range in the editor.
88+
// TargetRange is the full target range of this link.
89+
//
90+
// If the target for example is a symbol then target range is the range enclosing this symbol not including
91+
// leading/trailing whitespace but everything else like comments.
92+
//
93+
// This information is typically used to highlight the range in the editor.
8594
TargetRange Range `json:"targetRange"`
8695

87-
// TargetSelectionRange is the range that should be selected and revealed when this link is being followed, e.g the name of a function.
88-
// Must be contained by the the `targetRange`. See also `DocumentSymbol#range`
96+
// TargetSelectionRange is the range that should be selected and revealed when this link is being followed,
97+
// e.g the name of a function.
98+
//
99+
// Must be contained by the the TargetRange. See also DocumentSymbol#range
89100
TargetSelectionRange Range `json:"targetSelectionRange"`
90101
}
91102

92-
// CodeDescription is the structure to capture a description for an error code.
93-
//
94-
// @since 3.16.0.
95-
type CodeDescription struct {
96-
// Href an URI to open with more information about the diagnostic error.
97-
Href URI `json:"href"`
98-
}
99-
100103
// Diagnostic represents a diagnostic, such as a compiler error or warning.
101104
//
102105
// Diagnostic objects are only valid in the scope of a resource.
@@ -216,11 +219,22 @@ type DiagnosticRelatedInformation struct {
216219
Message string `json:"message"`
217220
}
218221

222+
// CodeDescription is the structure to capture a description for an error code.
223+
//
224+
// @since 3.16.0.
225+
type CodeDescription struct {
226+
// Href an URI to open with more information about the diagnostic error.
227+
Href URI `json:"href"`
228+
}
229+
219230
// Command represents a reference to a command. Provides a title which will be used to represent a command in the UI.
220231
//
221232
// Commands are identified by a string identifier.
222-
// The recommended way to handle commands is to implement their execution on the server side if the client and server provides the corresponding capabilities.
223-
// Alternatively the tool extension code could handle the command. The protocol currently doesn't specify a set of well-known commands.
233+
// The recommended way to handle commands is to implement their execution on the server side if the client and
234+
// server provides the corresponding capabilities.
235+
//
236+
// Alternatively the tool extension code could handle the command. The protocol currently doesn't specify
237+
// a set of well-known commands.
224238
type Command struct {
225239
// Title of the command, like `save`.
226240
Title string `json:"title"`
@@ -232,12 +246,24 @@ type Command struct {
232246
Arguments []interface{} `json:"arguments,omitempty"`
233247
}
234248

249+
// TextEdit is a textual edit applicable to a text document.
250+
type TextEdit struct {
251+
// Range is the range of the text document to be manipulated.
252+
//
253+
// To insert text into a document create a range where start == end.
254+
Range Range `json:"range"`
255+
256+
// NewText is the string to be inserted. For delete operations use an
257+
// empty string.
258+
NewText string `json:"newText"`
259+
}
260+
235261
// ChangeAnnotation is the additional information that describes document changes.
236262
//
237263
// @since 3.16.0.
238264
type ChangeAnnotation struct {
239-
// Label a human-readable string describing the actual change. The string
240-
// is rendered prominent in the user interface.
265+
// Label a human-readable string describing the actual change.
266+
// The string is rendered prominent in the user interface.
241267
Label string `json:"label"`
242268

243269
// NeedsConfirmation is a flag which indicates that user confirmation is needed
@@ -265,30 +291,23 @@ type AnnotatedTextEdit struct {
265291
AnnotationID ChangeAnnotationIdentifier `json:"annotationId"`
266292
}
267293

268-
// TextEdit is a textual edit applicable to a text document.
269-
type TextEdit struct {
270-
// Range is the range of the text document to be manipulated.
271-
// To insert text into a document create a range where start === end.
272-
Range Range `json:"range"`
273-
274-
// NewText is the string to be inserted. For delete operations use an
275-
// empty string.
276-
NewText string `json:"newText"`
277-
}
278-
279294
// TextDocumentEdit describes textual changes on a single text document.
280295
//
281-
// The text document is referred to as a VersionedTextDocumentIdentifier to allow clients to check the text document version before an edit is applied.
282-
// A TextDocumentEdit describes all changes on a version Si and after they are applied move the document to version Si+1.
283-
// So the creator of a TextDocumentEdit doesn't need to sort the array or do any kind of ordering. However the edits must be non overlapping.
296+
// The TextDocument is referred to as a OptionalVersionedTextDocumentIdentifier to allow clients to check the
297+
// text document version before an edit is applied.
298+
//
299+
// TextDocumentEdit describes all changes on a version "Si" and after they are applied move the document to
300+
// version "Si+1".
301+
// So the creator of a TextDocumentEdit doesn't need to sort the array or do any kind of ordering. However the
302+
// edits must be non overlapping.
284303
type TextDocumentEdit struct {
285304
// TextDocument is the text document to change.
286-
TextDocument VersionedTextDocumentIdentifier `json:"textDocument"`
305+
TextDocument OptionalVersionedTextDocumentIdentifier `json:"textDocument"`
287306

288307
// Edits is the edits to be applied.
289308
//
290309
// @since 3.16.0 - support for AnnotatedTextEdit.
291-
// This is guarded by the client capability "workspace.workspaceEdit.changeAnnotationSupport".
310+
// This is guarded by the client capability Workspace.WorkspaceEdit.ChangeAnnotationSupport.
292311
Edits []TextEdit `json:"edits"` // []TextEdit | []AnnotatedTextEdit
293312
}
294313

@@ -390,7 +409,8 @@ type DeleteFile struct {
390409
// WorkspaceEdit represent a changes to many resources managed in the workspace.
391410
//
392411
// The edit should either provide changes or documentChanges.
393-
// If the client can handle versioned document edits and if documentChanges are present, the latter are preferred over changes.
412+
// If the client can handle versioned document edits and if documentChanges are present, the latter are preferred over
413+
// changes.
394414
type WorkspaceEdit struct {
395415
// Changes holds changes to existing resources.
396416
Changes map[DocumentURI][]TextEdit `json:"changes,omitempty"`
@@ -698,7 +718,8 @@ type VersionedTextDocumentIdentifier struct {
698718
Version int32 `json:"version"`
699719
}
700720

701-
// OptionalVersionedTextDocumentIdentifier represents an identifier which optionally denotes a specific version of a text document.
721+
// OptionalVersionedTextDocumentIdentifier represents an identifier which optionally denotes a specific version of
722+
// a text document.
702723
//
703724
// This information usually flows from the server to the client.
704725
//
@@ -718,7 +739,8 @@ type OptionalVersionedTextDocumentIdentifier struct {
718739
Version *int32 `json:"version"` // int32 | null
719740
}
720741

721-
// TextDocumentPositionParams is a parameter literal used in requests to pass a text document and a position inside that document.
742+
// TextDocumentPositionParams is a parameter literal used in requests to pass a text document and a position
743+
// inside that document.
722744
type TextDocumentPositionParams struct {
723745
// TextDocument is the text document.
724746
TextDocument TextDocumentIdentifier `json:"textDocument"`
@@ -740,12 +762,18 @@ type DocumentFilter struct {
740762
// Pattern a glob pattern, like `*.{ts,js}`.
741763
//
742764
// Glob patterns can have the following syntax:
743-
// - `*` to match one or more characters in a path segment
744-
// - `?` to match on one character in a path segment
745-
// - `**` to match any number of path segments, including none
746-
// - `{}` to group conditions (e.g. `**​/*.{ts,js}` matches all TypeScript and JavaScript files)
747-
// - `[]` to declare a range of characters to match in a path segment (e.g., `example.[0-9]` to match on `example.0`, `example.1`, …)
748-
// - `[!...]` to negate a range of characters to match in a path segment (e.g., `example.[!0-9]` to match on `example.a`, `example.b`, but not `example.0`)
765+
// "*"
766+
// to match one or more characters in a path segment
767+
// "?"
768+
// to match on one character in a path segment
769+
// "**"
770+
// to match any number of path segments, including none
771+
// "{}"
772+
// to group conditions (e.g. `**​/*.{ts,js}` matches all TypeScript and JavaScript files)
773+
// "[]"
774+
// to declare a range of characters to match in a path segment (e.g., `example.[0-9]` to match on `example.0`, `example.1`, …)
775+
// "[!...]"
776+
// to negate a range of characters to match in a path segment (e.g., `example.[!0-9]` to match on `example.a`, `example.b`, but not `example.0`)
749777
Pattern string `json:"pattern,omitempty"`
750778
}
751779

@@ -776,18 +804,17 @@ const (
776804
// See https://help.github.com/articles/creating-and-highlighting-code-blocks/#syntax-highlighting
777805
//
778806
// Here is an example how such a string can be constructed using JavaScript / TypeScript:
779-
// ```typescript
780-
// * let markdown: MarkdownContent = {
781-
// * kind: MarkupKind.Markdown,
782-
// * value: [
783-
// * '# Header',
784-
// * 'Some text',
785-
// * '```typescript',
786-
// 'someCode();',
787-
// '```'
788-
// * ].join('\n')
789-
// * };
790-
// * ```
807+
//
808+
// let markdown: MarkdownContent = {
809+
// kind: MarkupKind.Markdown,
810+
// value: [
811+
// '# Header',
812+
// 'Some text',
813+
// '```typescript',
814+
// 'someCode();',
815+
// '```'
816+
// ].join('\n')
817+
// };
791818
//
792819
// NOTE: clients might sanitize the return markdown. A client could decide to
793820
// remove HTML from the markdown to avoid script execution.

basic_gojay.go

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -194,31 +194,6 @@ var (
194194
_ gojay.UnmarshalerJSONObject = (*LocationLink)(nil)
195195
)
196196

197-
// MarshalJSONObject implements gojay.MarshalerJSONObject.
198-
func (v *CodeDescription) MarshalJSONObject(enc *gojay.Encoder) {
199-
enc.StringKey(keyHref, string(v.Href))
200-
}
201-
202-
// IsNil implements gojay.MarshalerJSONObject.
203-
func (v *CodeDescription) IsNil() bool { return v == nil }
204-
205-
// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject.
206-
func (v *CodeDescription) UnmarshalJSONObject(dec *gojay.Decoder, k string) error {
207-
if k == keyHref {
208-
return dec.String((*string)(&v.Href))
209-
}
210-
return nil
211-
}
212-
213-
// NKeys implements gojay.UnmarshalerJSONObject.
214-
func (v *CodeDescription) NKeys() int { return 1 }
215-
216-
// compile time check whether the CodeDescription implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces.
217-
var (
218-
_ gojay.MarshalerJSONObject = (*CodeDescription)(nil)
219-
_ gojay.UnmarshalerJSONObject = (*CodeDescription)(nil)
220-
)
221-
222197
// MarshalJSONObject implements gojay.MarshalerJSONObject.
223198
func (v *Diagnostic) MarshalJSONObject(enc *gojay.Encoder) {
224199
enc.ObjectKey(keyRange, &v.Range)
@@ -335,6 +310,31 @@ var (
335310
_ gojay.UnmarshalerJSONObject = (*DiagnosticRelatedInformation)(nil)
336311
)
337312

313+
// MarshalJSONObject implements gojay.MarshalerJSONObject.
314+
func (v *CodeDescription) MarshalJSONObject(enc *gojay.Encoder) {
315+
enc.StringKey(keyHref, string(v.Href))
316+
}
317+
318+
// IsNil implements gojay.MarshalerJSONObject.
319+
func (v *CodeDescription) IsNil() bool { return v == nil }
320+
321+
// UnmarshalJSONObject implements gojay.UnmarshalerJSONObject.
322+
func (v *CodeDescription) UnmarshalJSONObject(dec *gojay.Decoder, k string) error {
323+
if k == keyHref {
324+
return dec.String((*string)(&v.Href))
325+
}
326+
return nil
327+
}
328+
329+
// NKeys implements gojay.UnmarshalerJSONObject.
330+
func (v *CodeDescription) NKeys() int { return 1 }
331+
332+
// compile time check whether the CodeDescription implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces.
333+
var (
334+
_ gojay.MarshalerJSONObject = (*CodeDescription)(nil)
335+
_ gojay.UnmarshalerJSONObject = (*CodeDescription)(nil)
336+
)
337+
338338
// DiagnosticRelatedInformations represents a slice of DiagnosticRelatedInformation.
339339
type DiagnosticRelatedInformations []DiagnosticRelatedInformation
340340

@@ -396,6 +396,35 @@ var (
396396
_ gojay.UnmarshalerJSONObject = (*Command)(nil)
397397
)
398398

399+
// MarshalJSONObject implements gojay.MarshalerJSONObject.
400+
func (v *TextEdit) MarshalJSONObject(enc *gojay.Encoder) {
401+
enc.ObjectKey(keyRange, &v.Range)
402+
enc.StringKey(keyNewText, v.NewText)
403+
}
404+
405+
// IsNil returns wether the structure is nil value or not.
406+
func (v *TextEdit) IsNil() bool { return v == nil }
407+
408+
// UnmarshalJSONObject implements gojay's UnmarshalerJSONObject.
409+
func (v *TextEdit) UnmarshalJSONObject(dec *gojay.Decoder, k string) error {
410+
switch k {
411+
case keyRange:
412+
return dec.Object(&v.Range)
413+
case keyNewText:
414+
return dec.String(&v.NewText)
415+
}
416+
return nil
417+
}
418+
419+
// NKeys returns the number of keys to unmarshal.
420+
func (v *TextEdit) NKeys() int { return 2 }
421+
422+
// compile time check whether the TextEdit implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces.
423+
var (
424+
_ gojay.MarshalerJSONObject = (*TextEdit)(nil)
425+
_ gojay.UnmarshalerJSONObject = (*TextEdit)(nil)
426+
)
427+
399428
// MarshalJSONObject implements gojay.MarshalerJSONObject.
400429
func (v *ChangeAnnotation) MarshalJSONObject(enc *gojay.Encoder) {
401430
enc.StringKey(keyLabel, v.Label)
@@ -460,35 +489,6 @@ var (
460489
_ gojay.UnmarshalerJSONObject = (*AnnotatedTextEdit)(nil)
461490
)
462491

463-
// MarshalJSONObject implements gojay.MarshalerJSONObject.
464-
func (v *TextEdit) MarshalJSONObject(enc *gojay.Encoder) {
465-
enc.ObjectKey(keyRange, &v.Range)
466-
enc.StringKey(keyNewText, v.NewText)
467-
}
468-
469-
// IsNil returns wether the structure is nil value or not.
470-
func (v *TextEdit) IsNil() bool { return v == nil }
471-
472-
// UnmarshalJSONObject implements gojay's UnmarshalerJSONObject.
473-
func (v *TextEdit) UnmarshalJSONObject(dec *gojay.Decoder, k string) error {
474-
switch k {
475-
case keyRange:
476-
return dec.Object(&v.Range)
477-
case keyNewText:
478-
return dec.String(&v.NewText)
479-
}
480-
return nil
481-
}
482-
483-
// NKeys returns the number of keys to unmarshal.
484-
func (v *TextEdit) NKeys() int { return 2 }
485-
486-
// compile time check whether the TextEdit implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces.
487-
var (
488-
_ gojay.MarshalerJSONObject = (*TextEdit)(nil)
489-
_ gojay.UnmarshalerJSONObject = (*TextEdit)(nil)
490-
)
491-
492492
// TextEdits represents a slice of TextEdit.
493493
type TextEdits []TextEdit
494494

0 commit comments

Comments
 (0)