-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathlsp_text_synchronization.go
154 lines (123 loc) · 4.99 KB
/
lsp_text_synchronization.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
150
151
152
153
154
//
// Copyright 2024 Cristian Maglie. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
package lsp
import (
"fmt"
"strconv"
)
type DidOpenTextDocumentParams struct {
// The document that was opened.
TextDocument TextDocumentItem `json:"textDocument,required"`
}
type DidCloseTextDocumentParams struct {
// The document that was closed.
TextDocument TextDocumentIdentifier `json:"textDocument,required"`
}
type DidChangeTextDocumentParams struct {
// The document that did change. The version number points
// to the version after all provided content changes have
// been applied.
TextDocument VersionedTextDocumentIdentifier `json:"textDocument,required"`
// The actual content changes. The content changes describe single state
// changes to the document. So if there are two content changes c1 (at
// array index 0) and c2 (at array index 1) for a document in state S then
// c1 moves the document from S to S' and c2 from S' to S''. So c1 is
// computed on the state S and c2 is computed on the state S'.
//
// To mirror the content of a document using change events use the following
// approach:
// - start with the same initial content
// - apply the 'textDocument/didChange' notifications in the order you
// receive them.
// - apply the `TextDocumentContentChangeEvent`s in a single notification
// in the order you receive them.
ContentChanges []TextDocumentContentChangeEvent `json:"contentChanges,required"`
}
type TextDocumentIdentifier struct {
// The text document's URI.
URI DocumentURI `json:"uri,required"`
}
func (t TextDocumentIdentifier) String() string {
return t.URI.String()
}
type VersionedTextDocumentIdentifier struct {
TextDocumentIdentifier
// The version number of this document.
//
// The version number of a document will increase after each change,
// including undo/redo. The number doesn't need to be consecutive.
Version int `json:"version,required"`
}
func (v VersionedTextDocumentIdentifier) String() string {
return fmt.Sprintf("%s@%d", v.TextDocumentIdentifier, v.Version)
}
// TextDocumentContentChangeEvent An event describing a change to a text document. If range and rangeLength are
// omitted the new text is considered to be the full content of the document.
type TextDocumentContentChangeEvent struct {
// The range of the document that changed.
Range *Range `json:"range,omitempty"`
// The optional length of the range that got replaced.
//
// @deprecated use range instead.
RangeLength *int `json:"rangeLength,omitempty"`
// The new text for the provided range or the new text of the whole document if range and rangeLength are omitted.
Text string `json:"text,required"`
}
func (change TextDocumentContentChangeEvent) String() string {
if change.Range == nil {
return fmt.Sprintf("FULLTEXT -> %s", strconv.Quote(change.Text))
}
l := ""
if change.RangeLength != nil {
l = fmt.Sprintf(" (len=%d)", *change.RangeLength)
}
return fmt.Sprintf("%s%s -> %s", change.Range, l, strconv.Quote(change.Text))
}
type TextDocumentItem struct {
// The text document's URI.
URI DocumentURI `json:"uri,required"`
// The text document's language identifier.
LanguageID string `json:"languageId,required"`
// The version number of this document (it will increase after each
// change, including undo/redo).
Version int `json:"version,required"`
// The content of the opened text document.
Text string `json:"text,required"`
}
func (t TextDocumentItem) String() string {
return fmt.Sprintf("%s@%d as '%s'", t.URI, t.Version, t.LanguageID)
}
type DidSaveTextDocumentParams struct {
// The document that was saved.
TextDocument TextDocumentIdentifier `json:"textDocument,required"`
// Optional the content when saved. Depends on the includeText value
// when the save notification was requested.
Text string `json:"text,omitempty"`
}
type RenameParams struct {
TextDocumentPositionParams
*WorkDoneProgressParams
// The new name of the symbol. If the given name is not valid the
// request must return a [ResponseError](#ResponseError) with an
// appropriate message set.
NewName string `json:"newName,required"`
}
// WillSaveTextDocumentParams The parameters send in a will save text document notification.
type WillSaveTextDocumentParams struct {
// The document that will be saved.
RextDocument TextDocumentIdentifier `json:"textDocument,required"`
// The 'TextDocumentSaveReason'.
Reason TextDocumentSaveReason `json:"reason,required"`
}
// TextDocumentSaveReason Represents reasons why a text document is saved.
type TextDocumentSaveReason int
// TextDocumentSaveReasonManual Manually triggered, e.g. by the user pressing save, by starting
// debugging, or by an API call.
const TextDocumentSaveReasonManual TextDocumentSaveReason = 1
// TextDocumentSaveReasonAfterDelay Automatic after a delay.
const TextDocumentSaveReasonAfterDelay TextDocumentSaveReason = 2
// TextDocumentSaveReasonFocusOut When the editor lost focus.
const TextDocumentSaveReasonFocusOut TextDocumentSaveReason = 3