You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are no actual changes, but it's good to be up to date.
And README.md changed to suppress markdown warnings.
Change-Id: I013ed9065963f41002c7fb946f38188fa3a1ddb1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/491296
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Peter Weinberger <pjw@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Copy file name to clipboardExpand all lines: gopls/internal/lsp/protocol/generate/README.md
+8Lines changed: 8 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,7 @@ web page, or in the vscode-languageserver-node repository. This code uses the la
13
13
exact version can be tied to a githash. By default, the command will download the `github.com/microsoft/vscode-languageserver-node` repository to a temporary directory.
14
14
15
15
The specification has five sections
16
+
16
17
1. Requests, which describe the Request and Response types for request methods (e.g., *textDocument/didChange*),
17
18
2. Notifications, which describe the Request types for notification methods,
18
19
3. Structures, which describe named struct-like types,
@@ -28,13 +29,15 @@ may need to be modified to avoid name collisions. (See the `disambiguate` map, a
28
29
Finally, the specified types are Typescript types, which are quite different from Go types.
29
30
30
31
### Optionality
32
+
31
33
The specification can mark fields in structs as Optional. The client distinguishes between missing
32
34
fields and `null` fields in some cases. The Go translation for an optional type
33
35
should be making sure the field's value
34
36
can be `nil`, and adding the json tag `,omitempty`. The former condition would be satisfied by
35
37
adding `*` to the field's type if the type is not a reference type.
36
38
37
39
### Types
40
+
38
41
The specification uses a number of different types, only a few of which correspond directly to Go types.
39
42
The specification's types are "base", "reference", "map", "literal", "stringLiteral", "tuple", "and", "or".
40
43
The "base" types correspond directly to Go types, although some Go types needs to be chosen for `URI` and `DocumentUri`. (The "base" types`RegExp`, `BooleanLiteral`, `NumericLiteral` never occur.)
@@ -70,6 +73,7 @@ will have one of the permitted types. (`nil` is always allowed.) There are about
70
73
have a single non-null component, and these are converted to the component type.
71
74
72
75
## Processing
76
+
73
77
The code parses the json specification file, and scans all the types. It assigns names, as described
74
78
above, to the types that are unnamed in the specification, and constructs Go equivalents as required.
75
79
(Most of this code is in typenames.go.)
@@ -80,6 +84,7 @@ of the Request or Notification. tsjson.go contains the custom marshaling and unm
80
84
And tsprotocol.go contains the type and const definitions.
81
85
82
86
### Accommodating gopls
87
+
83
88
As the code generates output, mostly in generateoutput.go and main.go,
84
89
it makes adjustments so that no changes are required to the existing Go code.
85
90
(Organizing the computation this way makes the code's structure simpler, but results in
@@ -107,6 +112,7 @@ The solution is to make `LSPAny` an `interface{}`. Another instance is `_Initial
107
112
whose type is an "or" of 3 stringLiterals, which just becomes a `string`.
108
113
109
114
### Checking
115
+
110
116
`TestAll(t *testing.T)` checks that there are no unexpected fields in the json specification.
111
117
112
118
While the code is executing, it checks that all the entries in the maps in tables.go are used.
@@ -119,6 +125,7 @@ that the older, more heuristic, code did not generate. (And the unused type `_In
119
125
slightly between the new and the old, and is not worth fixing.)
120
126
121
127
### Some history
128
+
122
129
The original stub code was written by hand, but with the protocol under active development, that
123
130
couldn't last. The web page existed before the json specification, but it lagged the implementation
124
131
and was hard to process by machine. So the earlier version of the generating code was written in Typescript, and
@@ -128,6 +135,7 @@ to pick out the elements of the protocol, and another set of overlapping heurist
128
135
The output was functional, but idiosyncratic, and the code was fragile and barely maintainable.
129
136
130
137
### The future
138
+
131
139
Most of the adjustments using the maps in tables.go could be removed by making changes, mostly to names,
132
140
in the gopls code. Using more "or" types in gopls requires more elaborate, but stereotyped, changes.
133
141
But even without all the adjustments, making this its own module would face problems; a number of
0 commit comments