Skip to content

Commit d9c37f4

Browse files
authored
Merge pull request #21 from go-language-server/lsp-3.16
Support lsp 3.16.0
2 parents b19b78e + 6cee1eb commit d9c37f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+12380
-2870
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ linters-settings:
2727
min-complexity: 20
2828
goconst:
2929
min-len: 3
30-
min-occurrences: 3
30+
min-occurrences: 4
3131
gocritic:
3232
enabled-tags:
3333
- diagnostic

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ tools/%: ## install an individual dependent tool
116116
@${MAKE} tools/bin/$* 1>/dev/null
117117

118118
tools/bin/%: ${TOOLS_DIR}/go.mod ${TOOLS_DIR}/go.sum
119-
cd tools; \
119+
@cd tools; \
120120
for t in ${TOOLS}; do \
121121
if [ -z '$*' ] || [ $$(basename $$t) = '$*' ]; then \
122122
echo "Install $$t ..." >&2; \

basic.go

Lines changed: 144 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ import (
1616
// For clarity, the type of such a field is declared as a DocumentURI.
1717
// Over the wire, it will still be transferred as a string, but this guarantees
1818
// that the contents of that string can be parsed as a valid URI.
19-
type DocumentURI string
19+
type DocumentURI = uri.URI
20+
21+
// URI a tagging interface for normal non document URIs.
22+
//
23+
// @since 3.16.0.
24+
type URI = uri.URI
2025

2126
// EOL denotes represents the character offset.
2227
var EOL = []string{"\n", "\r\n", "\r"}
@@ -26,14 +31,14 @@ var EOL = []string{"\n", "\r\n", "\r"}
2631
// A position is between two characters like an "insert" cursor in a editor.
2732
type Position struct {
2833
// Line position in a document (zero-based).
29-
Line float64 `json:"line"`
34+
Line uint32 `json:"line"`
3035

3136
// Character offset on a line in a document (zero-based). Assuming that the line is
3237
// represented as a string, the `character` value represents the gap between the
3338
// `character` and `character + 1`.
3439
// If the character value is greater than the line length it defaults back to the
3540
// line length.
36-
Character float64 `json:"character"`
41+
Character uint32 `json:"character"`
3742
}
3843

3944
// Range represents a text document expressed as (zero-based) start and end positions.
@@ -50,8 +55,8 @@ type Range struct {
5055

5156
// Location represents a location inside a resource, such as a line inside a text file.
5257
type Location struct {
53-
URI uri.URI `json:"uri"`
54-
Range Range `json:"range"`
58+
URI DocumentURI `json:"uri"`
59+
Range Range `json:"range"`
5560
}
5661

5762
// LocationLink represents a link between a source and a target location.
@@ -62,7 +67,7 @@ type LocationLink struct {
6267
OriginSelectionRange *Range `json:"originSelectionRange,omitempty"`
6368

6469
// TargetURI is the target resource identifier of this link.
65-
TargetURI uri.URI `json:"targetUri"`
70+
TargetURI DocumentURI `json:"targetUri"`
6671

6772
// TargetRange is the full target range of this link. If the target for example is a symbol then target range is the
6873
// range enclosing this symbol not including leading/trailing whitespace but everything else
@@ -74,6 +79,14 @@ type LocationLink struct {
7479
TargetSelectionRange Range `json:"targetSelectionRange"`
7580
}
7681

82+
// CodeDescription is the structure to capture a description for an error code.
83+
//
84+
// @since 3.16.0.
85+
type CodeDescription struct {
86+
// Href an URI to open with more information about the diagnostic error.
87+
Href URI `json:"href"`
88+
}
89+
7790
// Diagnostic represents a diagnostic, such as a compiler error or warning.
7891
//
7992
// Diagnostic objects are only valid in the scope of a resource.
@@ -86,7 +99,12 @@ type Diagnostic struct {
8699
Severity DiagnosticSeverity `json:"severity,omitempty"`
87100

88101
// Code is the diagnostic's code, which might appear in the user interface.
89-
Code interface{} `json:"code,omitempty"`
102+
Code interface{} `json:"code,omitempty"` // int32 | string;
103+
104+
// CodeDescription an optional property to describe the error code.
105+
//
106+
// @since 3.16.0.
107+
CodeDescription *CodeDescription `json:"codeDescription,omitempty"`
90108

91109
// Source a human-readable string describing the source of this
92110
// diagnostic, e.g. 'typescript' or 'super lint'.
@@ -103,35 +121,42 @@ type Diagnostic struct {
103121
// RelatedInformation an array of related diagnostic information, e.g. when symbol-names within
104122
// a scope collide all definitions can be marked via this property.
105123
RelatedInformation []DiagnosticRelatedInformation `json:"relatedInformation,omitempty"`
124+
125+
// Data is a data entry field that is preserved between a
126+
// "textDocument/publishDiagnostics" notification and
127+
// "textDocument/codeAction" request.
128+
//
129+
// @since 3.16.0.
130+
Data interface{} `json:"data,omitempty"`
106131
}
107132

108133
// DiagnosticSeverity indicates the severity of a Diagnostic message.
109134
type DiagnosticSeverity float64
110135

111136
const (
112-
// SeverityError reports an error.
113-
SeverityError DiagnosticSeverity = 1
137+
// DiagnosticSeverityError reports an error.
138+
DiagnosticSeverityError DiagnosticSeverity = 1
114139

115-
// SeverityWarning reports a warning.
116-
SeverityWarning DiagnosticSeverity = 2
140+
// DiagnosticSeverityWarning reports a warning.
141+
DiagnosticSeverityWarning DiagnosticSeverity = 2
117142

118-
// SeverityInformation reports an information.
119-
SeverityInformation DiagnosticSeverity = 3
143+
// DiagnosticSeverityInformation reports an information.
144+
DiagnosticSeverityInformation DiagnosticSeverity = 3
120145

121-
// SeverityHint reports a hint.
122-
SeverityHint DiagnosticSeverity = 4
146+
// DiagnosticSeverityHint reports a hint.
147+
DiagnosticSeverityHint DiagnosticSeverity = 4
123148
)
124149

125150
// String implements fmt.Stringer.
126151
func (d DiagnosticSeverity) String() string {
127152
switch d {
128-
case SeverityError:
153+
case DiagnosticSeverityError:
129154
return "Error"
130-
case SeverityWarning:
155+
case DiagnosticSeverityWarning:
131156
return "Warning"
132-
case SeverityInformation:
157+
case DiagnosticSeverityInformation:
133158
return "Information"
134-
case SeverityHint:
159+
case DiagnosticSeverityHint:
135160
return "Hint"
136161
default:
137162
return strconv.FormatFloat(float64(d), 'f', -10, 64)
@@ -145,24 +170,24 @@ type DiagnosticTag float64
145170

146171
// list of DiagnosticTag.
147172
const (
148-
// DiagnosticUnnecessary unused or unnecessary code.
173+
// DiagnosticTagUnnecessary unused or unnecessary code.
149174
//
150175
// Clients are allowed to render diagnostics with this tag faded out instead of having
151176
// an error squiggle.
152-
DiagnosticUnnecessary DiagnosticTag = 1
177+
DiagnosticTagUnnecessary DiagnosticTag = 1
153178

154-
// DiagnosticDeprecated deprecated or obsolete code.
179+
// DiagnosticTagDeprecated deprecated or obsolete code.
155180
//
156181
// Clients are allowed to rendered diagnostics with this tag strike through.
157-
DiagnosticDeprecated DiagnosticTag = 2
182+
DiagnosticTagDeprecated DiagnosticTag = 2
158183
)
159184

160185
// String implements fmt.Stringer.
161186
func (d DiagnosticTag) String() string {
162187
switch d {
163-
case DiagnosticUnnecessary:
188+
case DiagnosticTagUnnecessary:
164189
return "Unnecessary"
165-
case DiagnosticDeprecated:
190+
case DiagnosticTagDeprecated:
166191
return "Deprecated"
167192
default:
168193
return strconv.FormatFloat(float64(d), 'f', -10, 64)
@@ -197,6 +222,39 @@ type Command struct {
197222
Arguments []interface{} `json:"arguments,omitempty"`
198223
}
199224

225+
// ChangeAnnotation is the additional information that describes document changes.
226+
//
227+
// @since 3.16.0.
228+
type ChangeAnnotation struct {
229+
// Label a human-readable string describing the actual change. The string
230+
// is rendered prominent in the user interface.
231+
Label string `json:"label"`
232+
233+
// NeedsConfirmation is a flag which indicates that user confirmation is needed
234+
// before applying the change.
235+
NeedsConfirmation bool `json:"needsConfirmation,omitempty"`
236+
237+
// Description is a human-readable string which is rendered less prominent in
238+
// the user interface.
239+
Description string `json:"description,omitempty"`
240+
}
241+
242+
// ChangeAnnotationIdentifier an identifier referring to a change annotation managed by a workspace
243+
// edit.
244+
//
245+
// @since 3.16.0.
246+
type ChangeAnnotationIdentifier string
247+
248+
// AnnotatedTextEdit is a special text edit with an additional change annotation.
249+
//
250+
// @since 3.16.0.
251+
type AnnotatedTextEdit struct {
252+
TextEdit
253+
254+
// AnnotationID is the actual annotation identifier.
255+
AnnotationID ChangeAnnotationIdentifier `json:"annotationId"`
256+
}
257+
200258
// TextEdit is a textual edit applicable to a text document.
201259
type TextEdit struct {
202260
// Range is the range of the text document to be manipulated.
@@ -218,7 +276,10 @@ type TextDocumentEdit struct {
218276
TextDocument VersionedTextDocumentIdentifier `json:"textDocument"`
219277

220278
// Edits is the edits to be applied.
221-
Edits []TextEdit `json:"edits"`
279+
//
280+
// @since 3.16.0 - support for AnnotatedTextEdit.
281+
// This is guarded by the client capability "workspace.workspaceEdit.changeAnnotationSupport".
282+
Edits []TextEdit `json:"edits"` // []TextEdit | []AnnotatedTextEdit
222283
}
223284

224285
// ResourceOperationKind is the file event type.
@@ -250,10 +311,15 @@ type CreateFile struct {
250311
Kind ResourceOperationKind `json:"kind"` // should be `create`
251312

252313
// URI is the resource to create.
253-
URI uri.URI `json:"uri"`
314+
URI DocumentURI `json:"uri"`
254315

255316
// Options additional options.
256317
Options *CreateFileOptions `json:"options,omitempty"`
318+
319+
// AnnotationID an optional annotation identifier describing the operation.
320+
//
321+
// @since 3.16.0.
322+
AnnotationID ChangeAnnotationIdentifier `json:"annotationId,omitempty"`
257323
}
258324

259325
// RenameFileOptions represents a rename file options.
@@ -271,13 +337,18 @@ type RenameFile struct {
271337
Kind ResourceOperationKind `json:"kind"` // should be `rename`
272338

273339
// OldURI is the old (existing) location.
274-
OldURI uri.URI `json:"oldUri"`
340+
OldURI DocumentURI `json:"oldUri"`
275341

276342
// NewURI is the new location.
277-
NewURI uri.URI `json:"newUri"`
343+
NewURI DocumentURI `json:"newUri"`
278344

279345
// Options rename options.
280346
Options *RenameFileOptions `json:"options,omitempty"`
347+
348+
// AnnotationID an optional annotation identifier describing the operation.
349+
//
350+
// @since 3.16.0.
351+
AnnotationID ChangeAnnotationIdentifier `json:"annotationId,omitempty"`
281352
}
282353

283354
// DeleteFileOptions represents a delete file options.
@@ -295,10 +366,15 @@ type DeleteFile struct {
295366
Kind ResourceOperationKind `json:"kind"` // should be `delete`
296367

297368
// URI is the file to delete.
298-
URI uri.URI `json:"uri"`
369+
URI DocumentURI `json:"uri"`
299370

300371
// Options delete options.
301372
Options *DeleteFileOptions `json:"options,omitempty"`
373+
374+
// AnnotationID an optional annotation identifier describing the operation.
375+
//
376+
// @since 3.16.0.
377+
AnnotationID ChangeAnnotationIdentifier `json:"annotationId,omitempty"`
302378
}
303379

304380
// WorkspaceEdit represent a changes to many resources managed in the workspace.
@@ -307,7 +383,7 @@ type DeleteFile struct {
307383
// If the client can handle versioned document edits and if documentChanges are present, the latter are preferred over changes.
308384
type WorkspaceEdit struct {
309385
// Changes holds changes to existing resources.
310-
Changes map[uri.URI][]TextEdit `json:"changes,omitempty"`
386+
Changes map[DocumentURI][]TextEdit `json:"changes,omitempty"`
311387

312388
// DocumentChanges depending on the client capability `workspace.workspaceEdit.resourceOperations` document changes
313389
// are either an array of `TextDocumentEdit`s to express changes to n different text documents
@@ -320,25 +396,35 @@ type WorkspaceEdit struct {
320396
// If a client neither supports `documentChanges` nor `workspace.workspaceEdit.resourceOperations` then
321397
// only plain `TextEdit`s using the `changes` property are supported.
322398
DocumentChanges []TextDocumentEdit `json:"documentChanges,omitempty"`
399+
400+
// ChangeAnnotations is a map of change annotations that can be referenced in
401+
// "AnnotatedTextEdit"s or create, rename and delete file / folder
402+
// operations.
403+
//
404+
// Whether clients honor this property depends on the client capability
405+
// "workspace.changeAnnotationSupport".
406+
//
407+
// @since 3.16.0.
408+
ChangeAnnotations map[ChangeAnnotationIdentifier]ChangeAnnotation `json:"changeAnnotations,omitempty"`
323409
}
324410

325411
// TextDocumentIdentifier indicates the using a URI. On the protocol level, URIs are passed as strings.
326412
type TextDocumentIdentifier struct {
327413
// URI is the text document's URI.
328-
URI uri.URI `json:"uri"`
414+
URI DocumentURI `json:"uri"`
329415
}
330416

331417
// TextDocumentItem represent an item to transfer a text document from the client to the server.
332418
type TextDocumentItem struct {
333419
// URI is the text document's URI.
334-
URI uri.URI `json:"uri"`
420+
URI DocumentURI `json:"uri"`
335421

336422
// LanguageID is the text document's language identifier.
337423
LanguageID LanguageIdentifier `json:"languageId"`
338424

339425
// Version is the version number of this document (it will increase after each
340426
// change, including undo/redo).
341-
Version float64 `json:"version"`
427+
Version int32 `json:"version"`
342428

343429
// Text is the content of the opened text document.
344430
Text string `json:"text"`
@@ -584,11 +670,11 @@ var languageIdentifierMap = map[string]LanguageIdentifier{
584670
// ToLanguageIdentifier converts ft to LanguageIdentifier.
585671
func ToLanguageIdentifier(ft string) LanguageIdentifier {
586672
langID, ok := languageIdentifierMap[ft]
587-
if !ok {
588-
return LanguageIdentifier(ft)
673+
if ok {
674+
return langID
589675
}
590676

591-
return langID
677+
return LanguageIdentifier(ft)
592678
}
593679

594680
// VersionedTextDocumentIdentifier represents an identifier to denote a specific version of a text document.
@@ -597,14 +683,29 @@ type VersionedTextDocumentIdentifier struct {
597683

598684
// Version is the version number of this document.
599685
//
600-
// If a versioned text document identifier is sent from the server to the client and the file is not open in the editor
601-
// (the server has not received an open notification before) the server can send
602-
// `null` to indicate that the version is known and the content on disk is the
603-
// truth (as speced with document content ownership).
604-
//
605686
// The version number of a document will increase after each change, including
606687
// undo/redo. The number doesn't need to be consecutive.
607-
Version *uint64 `json:"version"`
688+
Version int32 `json:"version"`
689+
}
690+
691+
// OptionalVersionedTextDocumentIdentifier represents an identifier which optionally denotes a specific version of a text document.
692+
//
693+
// This information usually flows from the server to the client.
694+
//
695+
// @since 3.16.0.
696+
type OptionalVersionedTextDocumentIdentifier struct {
697+
TextDocumentIdentifier
698+
699+
// Version is the version number of this document. If an optional versioned text document
700+
// identifier is sent from the server to the client and the file is not
701+
// open in the editor (the server has not received an open notification
702+
// before) the server can send `null` to indicate that the version is
703+
// known and the content on disk is the master (as specified with document
704+
// content ownership).
705+
//
706+
// The version number of a document will increase after each change,
707+
// including undo/redo. The number doesn't need to be consecutive.
708+
Version *int32 `json:"version"` // int32 | null
608709
}
609710

610711
// TextDocumentPositionParams is a parameter literal used in requests to pass a text document and a position inside that document.

0 commit comments

Comments
 (0)