@@ -28,19 +28,19 @@ var (
28
28
jsons = make (sortedMap [string ])
29
29
)
30
30
31
- func generateOutput (model Model ) {
31
+ func generateOutput (model * Model ) {
32
32
for _ , r := range model .Requests {
33
- genDecl (r .Method , r .Params , r .Result , r .Direction )
34
- genCase (r .Method , r .Params , r .Result , r .Direction )
35
- genFunc (r .Method , r .Params , r .Result , r .Direction , false )
33
+ genDecl (model , r .Method , r .Params , r .Result , r .Direction )
34
+ genCase (model , r .Method , r .Params , r .Result , r .Direction )
35
+ genFunc (model , r .Method , r .Params , r .Result , r .Direction , false )
36
36
}
37
37
for _ , n := range model .Notifications {
38
38
if n .Method == "$/cancelRequest" {
39
39
continue // handled internally by jsonrpc2
40
40
}
41
- genDecl (n .Method , n .Params , nil , n .Direction )
42
- genCase (n .Method , n .Params , nil , n .Direction )
43
- genFunc (n .Method , n .Params , nil , n .Direction , true )
41
+ genDecl (model , n .Method , n .Params , nil , n .Direction )
42
+ genCase (model , n .Method , n .Params , nil , n .Direction )
43
+ genFunc (model , n .Method , n .Params , nil , n .Direction , true )
44
44
}
45
45
genStructs (model )
46
46
genAliases (model )
@@ -49,7 +49,7 @@ func generateOutput(model Model) {
49
49
genMarshal ()
50
50
}
51
51
52
- func genDecl (method string , param , result * Type , dir string ) {
52
+ func genDecl (model * Model , method string , param , result * Type , dir string ) {
53
53
fname := methodName (method )
54
54
p := ""
55
55
if notNil (param ) {
@@ -71,7 +71,8 @@ func genDecl(method string, param, result *Type, dir string) {
71
71
p = ", *ParamConfiguration"
72
72
ret = "([]LSPAny, error)"
73
73
}
74
- msg := fmt .Sprintf ("\t %s(context.Context%s) %s // %s\n " , fname , p , ret , method )
74
+ fragment := strings .ReplaceAll (strings .TrimPrefix (method , "$/" ), "/" , "_" )
75
+ msg := fmt .Sprintf ("\t %s\t %s(context.Context%s) %s\n " , lspLink (model , fragment ), fname , p , ret )
75
76
switch dir {
76
77
case "clientToServer" :
77
78
sdecls [method ] = msg
@@ -85,7 +86,7 @@ func genDecl(method string, param, result *Type, dir string) {
85
86
}
86
87
}
87
88
88
- func genCase (method string , param , result * Type , dir string ) {
89
+ func genCase (model * Model , method string , param , result * Type , dir string ) {
89
90
out := new (bytes.Buffer )
90
91
fmt .Fprintf (out , "\t case %q:\n " , method )
91
92
var p string
@@ -127,7 +128,7 @@ func genCase(method string, param, result *Type, dir string) {
127
128
}
128
129
}
129
130
130
- func genFunc (method string , param , result * Type , dir string , isnotify bool ) {
131
+ func genFunc (model * Model , method string , param , result * Type , dir string , isnotify bool ) {
131
132
out := new (bytes.Buffer )
132
133
var p , r string
133
134
var goResult string
@@ -202,7 +203,7 @@ func genFunc(method string, param, result *Type, dir string, isnotify bool) {
202
203
}
203
204
}
204
205
205
- func genStructs (model Model ) {
206
+ func genStructs (model * Model ) {
206
207
structures := make (map [string ]* Structure ) // for expanding Extends
207
208
for _ , s := range model .Structures {
208
209
structures [s .Name ] = s
@@ -215,6 +216,8 @@ func genStructs(model Model) {
215
216
// a weird case, and needed only so the generated code contains the old gopls code
216
217
nm = "DocumentDiagnosticParams"
217
218
}
219
+ fmt .Fprintf (out , "//\n " )
220
+ out .WriteString (lspLink (model , camelCase (s .Name )))
218
221
fmt .Fprintf (out , "type %s struct {%s\n " , nm , linex (s .Line ))
219
222
// for gpls compatibilitye, embed most extensions, but expand the rest some day
220
223
props := append ([]NameType {}, s .Properties ... )
@@ -245,6 +248,19 @@ func genStructs(model Model) {
245
248
246
249
}
247
250
251
+ // "FooBar" -> "fooBar"
252
+ func camelCase (TitleCased string ) string {
253
+ return strings .ToLower (TitleCased [:1 ]) + TitleCased [1 :]
254
+ }
255
+
256
+ func lspLink (model * Model , fragment string ) string {
257
+ // Derive URL version from metaData.version in JSON file.
258
+ parts := strings .Split (model .Version .Version , "." ) // e.g. "3.17.0"
259
+ return fmt .Sprintf ("// See https://microsoft.github.io/language-server-protocol/specifications/lsp/%s.%s/specification#%s\n " ,
260
+ parts [0 ], parts [1 ], // major.minor
261
+ fragment )
262
+ }
263
+
248
264
func genProps (out * bytes.Buffer , props []NameType , name string ) {
249
265
for _ , p := range props {
250
266
tp := goplsName (p .Type )
@@ -263,7 +279,7 @@ func genProps(out *bytes.Buffer, props []NameType, name string) {
263
279
}
264
280
}
265
281
266
- func genAliases (model Model ) {
282
+ func genAliases (model * Model ) {
267
283
for _ , ta := range model .TypeAliases {
268
284
out := new (bytes.Buffer )
269
285
generateDoc (out , ta .Documentation )
@@ -272,6 +288,8 @@ func genAliases(model Model) {
272
288
continue // renamed the type, e.g., "DocumentDiagnosticReport", an or-type to "string"
273
289
}
274
290
tp := goplsName (ta .Type )
291
+ fmt .Fprintf (out , "//\n " )
292
+ out .WriteString (lspLink (model , camelCase (ta .Name )))
275
293
fmt .Fprintf (out , "type %s = %s // (alias)\n " , nm , tp )
276
294
types [nm ] = out .String ()
277
295
}
@@ -320,7 +338,7 @@ func genGenTypes() {
320
338
types [nm ] = out .String ()
321
339
}
322
340
}
323
- func genConsts (model Model ) {
341
+ func genConsts (model * Model ) {
324
342
for _ , e := range model .Enumerations {
325
343
out := new (bytes.Buffer )
326
344
generateDoc (out , e .Documentation )
0 commit comments