Skip to content

Commit 26e06f8

Browse files
committed
WIP6
Signed-off-by: Koichi Shiraishi <[email protected]>
1 parent 1b68a73 commit 26e06f8

File tree

15 files changed

+1177
-1141
lines changed

15 files changed

+1177
-1141
lines changed

protocol/client.go

Lines changed: 111 additions & 111 deletions
Large diffs are not rendered by default.

protocol/client_interface.go

Lines changed: 81 additions & 81 deletions
Large diffs are not rendered by default.

protocol/server.go

Lines changed: 125 additions & 125 deletions
Large diffs are not rendered by default.

protocol/server_interface.go

Lines changed: 281 additions & 281 deletions
Large diffs are not rendered by default.

protocol/types_generics.go

Lines changed: 347 additions & 347 deletions
Large diffs are not rendered by default.

tools/protocol-gen/generator/client_server.go

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,28 @@ func (gen *Generator) ClientToServer(clientNotifications, bidiNotifications []*p
2020
g.PP(`const (`)
2121
if len(bidiNotifications) > 0 {
2222
slices.SortFunc(bidiNotifications, func(a, b *protocol.Notification) int {
23-
if !strings.Contains(a.Method, "/") && !strings.Contains(b.Method, "/") {
24-
return cmp.Compare(a.Method, b.Method)
25-
}
26-
return cmp.Compare(strings.ToLower(a.Method), strings.ToLower(b.Method))
23+
return cmp.Compare(strings.ToLower(a.TypeName), strings.ToLower(b.TypeName))
2724
})
2825
for _, meth := range bidiNotifications {
2926
g.PP(` `, `MethodClient`+normalizeMethodName(meth.Method), ` ClientMethod `, ` = `, strconv.Quote(meth.Method), ` // bidirect client notification`)
3027
}
3128
}
3229
slices.SortFunc(clientNotifications, func(a, b *protocol.Notification) int {
33-
if !strings.Contains(a.Method, "/") && !strings.Contains(b.Method, "/") {
34-
return cmp.Compare(a.Method, b.Method)
35-
}
36-
return cmp.Compare(strings.ToLower(a.Method), strings.ToLower(b.Method))
30+
return cmp.Compare(strings.ToLower(a.TypeName), strings.ToLower(b.TypeName))
3731
})
3832
for _, meth := range clientNotifications {
3933
g.PP(` `, `Method`+normalizeMethodName(meth.Method), ` ClientMethod `, ` = `, strconv.Quote(meth.Method), ` // client notification`)
4034
}
4135
if len(bidiRequests) > 0 {
4236
slices.SortFunc(bidiRequests, func(a, b *protocol.Request) int {
43-
if !strings.Contains(a.Method, "/") && !strings.Contains(b.Method, "/") {
44-
return cmp.Compare(a.Method, b.Method)
45-
}
46-
return cmp.Compare(strings.ToLower(a.Method), strings.ToLower(b.Method))
37+
return cmp.Compare(strings.ToLower(a.TypeName), strings.ToLower(b.TypeName))
4738
})
4839
for _, meth := range bidiRequests {
4940
g.PP(` `, `MethodClient`+normalizeMethodName(meth.Method), ` ClientMethod `, ` = `, strconv.Quote(meth.Method), ` // bidirect client request`)
5041
}
5142
}
5243
slices.SortFunc(clientRequests, func(a, b *protocol.Request) int {
53-
if !strings.Contains(a.Method, "/") && !strings.Contains(b.Method, "/") {
54-
return cmp.Compare(a.Method, b.Method)
55-
}
56-
return cmp.Compare(strings.ToLower(a.Method), strings.ToLower(b.Method))
44+
return cmp.Compare(strings.ToLower(a.TypeName), strings.ToLower(b.TypeName))
5745
})
5846
for _, meth := range clientRequests {
5947
g.PP(` `, `Method`+normalizeMethodName(meth.Method), ` ClientMethod `, ` = `, strconv.Quote(meth.Method), ` // client request`)
@@ -66,7 +54,8 @@ func (gen *Generator) ClientToServer(clientNotifications, bidiNotifications []*p
6654
reqests := append(bidiRequests, clientRequests...)
6755

6856
for i, notify := range notifications {
69-
meth := normalizeMethodName(notify.Method)
57+
meth := normalizeMethodName(notify.TypeName)
58+
meth = strings.TrimSuffix(meth, "Notification")
7059
// write Documentation
7160
if notify.Documentation != "" {
7261
g.PP(`// `, meth, normalizeDocumentation(notify.Documentation))
@@ -91,7 +80,10 @@ func (gen *Generator) ClientToServer(clientNotifications, bidiNotifications []*p
9180
}
9281
}
9382
for i, req := range reqests {
94-
meth := normalizeMethodName(req.Method)
83+
meth := normalizeMethodName(req.TypeName)
84+
if meth != "ShowMessageRequest" {
85+
meth = strings.TrimSuffix(meth, "Request")
86+
}
9587
// write Documentation
9688
if req.Documentation != "" {
9789
g.PP(`// `, meth, normalizeDocumentation(req.Documentation))
@@ -122,7 +114,8 @@ func (gen *Generator) ClientToServer(clientNotifications, bidiNotifications []*p
122114
g.PP(`type UnimplementedClient struct {}`)
123115
g.P("\n")
124116
for i, notify := range notifications {
125-
meth := normalizeMethodName(notify.Method)
117+
meth := normalizeMethodName(notify.TypeName)
118+
meth = strings.TrimSuffix(meth, "Notification")
126119
g.P(`func (UnimplementedClient) `)
127120
if err := gen.notification(g, meth, notify); err != nil {
128121
return err
@@ -136,7 +129,10 @@ func (gen *Generator) ClientToServer(clientNotifications, bidiNotifications []*p
136129
}
137130
}
138131
for i, req := range reqests {
139-
meth := normalizeMethodName(req.Method)
132+
meth := normalizeMethodName(req.TypeName)
133+
if meth != "ShowMessageRequest" {
134+
meth = strings.TrimSuffix(meth, "Request")
135+
}
140136
if meth == "" {
141137
continue
142138
}
@@ -172,40 +168,28 @@ func (gen *Generator) ServerToClient(serverNotifications, bidiNotifications []*p
172168
g.PP(`const (`)
173169
if len(bidiNotifications) > 0 {
174170
slices.SortFunc(bidiNotifications, func(a, b *protocol.Notification) int {
175-
if !strings.Contains(a.Method, "/") && !strings.Contains(b.Method, "/") {
176-
return cmp.Compare(a.Method, b.Method)
177-
}
178-
return cmp.Compare(a.Method, b.Method)
171+
return cmp.Compare(a.TypeName, b.TypeName)
179172
})
180173
for _, meth := range bidiNotifications {
181174
g.PP(` `, `MethodServer`+normalizeMethodName(meth.Method), ` ServerMethod `, ` = `, strconv.Quote(meth.Method), ` // bidirect server notification`)
182175
}
183176
}
184177
slices.SortFunc(serverNotifications, func(a, b *protocol.Notification) int {
185-
if !strings.Contains(a.Method, "/") && !strings.Contains(b.Method, "/") {
186-
return cmp.Compare(a.Method, b.Method)
187-
}
188-
return cmp.Compare(a.Method, b.Method)
178+
return cmp.Compare(a.TypeName, b.TypeName)
189179
})
190180
for _, meth := range serverNotifications {
191181
g.PP(` `, `Method`+normalizeMethodName(meth.Method), ` ServerMethod `, ` = `, strconv.Quote(meth.Method), ` // server notification`)
192182
}
193183
if len(bidiRequests) > 0 {
194184
slices.SortFunc(bidiRequests, func(a, b *protocol.Request) int {
195-
if !strings.Contains(a.Method, "/") && !strings.Contains(b.Method, "/") {
196-
return cmp.Compare(a.Method, b.Method)
197-
}
198-
return cmp.Compare(a.Method, b.Method)
185+
return cmp.Compare(a.TypeName, b.TypeName)
199186
})
200187
for _, meth := range bidiRequests {
201188
g.PP(` `, `MethodServer`+normalizeMethodName(meth.Method), ` ServerMethod `, ` = `, strconv.Quote(meth.Method), ` // bidirect server request`)
202189
}
203190
}
204191
slices.SortFunc(serverNequests, func(a, b *protocol.Request) int {
205-
if !strings.Contains(a.Method, "/") && !strings.Contains(b.Method, "/") {
206-
return cmp.Compare(a.Method, b.Method)
207-
}
208-
return cmp.Compare(a.Method, b.Method)
192+
return cmp.Compare(a.TypeName, b.TypeName)
209193
})
210194
for _, meth := range serverNequests {
211195
g.PP(` `, `Method`+normalizeMethodName(meth.Method), ` ServerMethod `, ` = `, strconv.Quote(meth.Method), ` // server request`)
@@ -218,7 +202,8 @@ func (gen *Generator) ServerToClient(serverNotifications, bidiNotifications []*p
218202
reqests := slices.Clip(serverNequests)
219203

220204
for i, notify := range notifications {
221-
meth := normalizeMethodName(notify.Method)
205+
meth := normalizeMethodName(notify.TypeName)
206+
meth = strings.TrimSuffix(meth, "Notification")
222207
// write Documentation
223208
if notify.Documentation != "" {
224209
g.PP(`// `, meth, normalizeDocumentation(notify.Documentation))
@@ -243,7 +228,10 @@ func (gen *Generator) ServerToClient(serverNotifications, bidiNotifications []*p
243228
}
244229
}
245230
for i, req := range reqests {
246-
meth := normalizeMethodName(req.Method)
231+
meth := normalizeMethodName(req.TypeName)
232+
if meth != "ShowMessageRequest" {
233+
meth = strings.TrimSuffix(meth, "Request")
234+
}
247235
// write Documentation
248236
if req.Documentation != "" {
249237
g.PP(`// `, meth, normalizeDocumentation(req.Documentation))
@@ -276,7 +264,8 @@ func (gen *Generator) ServerToClient(serverNotifications, bidiNotifications []*p
276264
g.PP(`type UnimplementedServer struct {}`)
277265
g.P("\n")
278266
for i, notify := range notifications {
279-
meth := normalizeMethodName(notify.Method)
267+
meth := normalizeMethodName(notify.TypeName)
268+
meth = strings.TrimSuffix(meth, "Notification")
280269
g.P(`func (UnimplementedServer) `)
281270
if err := gen.notification(g, meth, notify); err != nil {
282271
return err
@@ -290,7 +279,10 @@ func (gen *Generator) ServerToClient(serverNotifications, bidiNotifications []*p
290279
}
291280
}
292281
for i, req := range reqests {
293-
meth := normalizeMethodName(req.Method)
282+
meth := normalizeMethodName(req.TypeName)
283+
if meth != "ShowMessageRequest" {
284+
meth = strings.TrimSuffix(meth, "Request")
285+
}
294286
g.P(`func (UnimplementedServer) `)
295287
n, err := gen.request(g, meth, req)
296288
if err != nil {
@@ -419,7 +411,7 @@ func (gen *Generator) renderRequestsArrayType(g Printer, req *protocol.Request,
419411
gen.renderRequestssOrTypeNull(g, req, elem)
420412
default:
421413
genericsType := genericsType{
422-
Name: normalizeMethodName(req.Method) + "Result",
414+
Name: normalizeMethodName(req.TypeName) + "Result",
423415
Documentation: req.Documentation,
424416
Since: req.Since,
425417
Proposed: req.Proposed,

tools/protocol-gen/protocol/enum.go

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,32 @@ package protocol
55

66
// Enumeration defines an enumeration.
77
type Enumeration struct {
8-
// Whether the enumeration is deprecated or not. If deprecated the property contains the deprecation message.
9-
Deprecated string
10-
11-
// An optional documentation.
12-
Documentation string
13-
148
// The name of the enumeration.
159
Name string
1610

17-
// Whether this is a proposed enumeration. If omitted, the enumeration is final.
18-
Proposed bool
11+
// The type of the elements.
12+
Type EnumerationType
1913

20-
// Since when (release number) this enumeration is available. Is empty if not known.
21-
Since string
14+
// The enum values.
15+
Values []*EnumerationEntry
2216

2317
// Whether the enumeration supports custom values (e.g. values which are not part of the set defined in values). If omitted no custom values are supported.
2418
SupportsCustomValues bool
2519

26-
// The type of the elements.
27-
Type EnumerationType
20+
// An optional documentation.
21+
Documentation string
2822

29-
// The enum values.
30-
Values []*EnumerationEntry
23+
// Since when (release number) this enumeration is available. Is empty if not known.
24+
Since string
25+
26+
// All since tags in case there was more than one tag. Is undefined if not known.
27+
SinceTags []string
28+
29+
// Whether this is a proposed enumeration. If omitted, the enumeration is final.
30+
Proposed bool
31+
32+
// Whether the enumeration is deprecated or not. If deprecated the property contains the deprecation message.
33+
Deprecated string
3134
}
3235

3336
func (Enumeration) isTypeDecl() {}
@@ -50,21 +53,27 @@ const (
5053

5154
// EnumerationEntry defines an enumeration entry.
5255
type EnumerationEntry struct {
53-
// Whether the enum entry is deprecated or not. If deprecated the property contains the deprecation message.
54-
Deprecated string
56+
// The name of the enum item.
57+
Name string
58+
59+
// The value (string or number).
60+
Value any
5561

5662
// An optional documentation.
5763
Documentation string
5864

59-
// The name of the enum item.
60-
Name string
65+
// Since when (release number) this enumeration entry is available. Is undefined if not known.
66+
Since string
67+
68+
// All since tags in case there was more than one tag. Is undefined if not known.
69+
SinceTags []string
6170

6271
// Whether this is a proposed enumeration entry. If omitted, the enumeration entry is final.
6372
Proposed bool
6473

65-
// Since when (release number) this enumeration entry is available. Is undefined if not known.
66-
Since string
74+
// Whether the enum entry is deprecated or not. If deprecated the property contains the deprecation message.
75+
Deprecated string
6776

68-
// The value (string or number).
69-
Value any
77+
// The type name of the request if any.
78+
TypeName string
7079
}

tools/protocol-gen/protocol/notification.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,37 @@ package protocol
55

66
// Notification represents a LSP notification.
77
type Notification struct {
8-
// Whether the notification is deprecated or not.
9-
// If deprecated the property contains the deprecation message.
10-
Deprecated string
11-
12-
// An optional documentation.
13-
Documentation string
14-
15-
// The direction in which this notification is sent in the protocol.
16-
MessageDirection MessageDirection
17-
188
// The request's method name.
199
Method string
2010

2111
// The parameter type(s) if any.
2212
Params []Type
2313

24-
// Whether this is a proposed notification. If omitted the notification is final.
25-
Proposed bool
26-
2714
// Optional a dynamic registration method if it different from the request's method.
2815
RegistrationMethod string
2916

3017
// Optional registration options if the notification supports dynamic registration.
3118
RegistrationOptions Type
3219

20+
// The direction in which this notification is sent in the protocol.
21+
MessageDirection MessageDirection
22+
23+
// An optional documentation.
24+
Documentation string
25+
3326
// Since when (release number) this notification is available. Is undefined if not knownz.
3427
Since string
28+
29+
// All since tags in case there was more than one tag. Is undefined if not known.
30+
SinceTags []string
31+
32+
// Whether this is a proposed notification. If omitted the notification is final.
33+
Proposed bool
34+
35+
// Whether the notification is deprecated or not.
36+
// If deprecated the property contains the deprecation message.
37+
Deprecated string
38+
39+
// The type name of the request if any.
40+
TypeName string
3541
}

tools/protocol-gen/protocol/property.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,30 @@ package protocol
55

66
// Property represents an object property.
77
type Property struct {
8-
// Whether the property is deprecated or not. If deprecated the property contains the deprecation message.
9-
Deprecated string
10-
11-
// An optional documentation.
12-
Documentation string
13-
14-
// The property JSON name.
15-
JSONName string
16-
178
// The property name.
189
Name string
1910

11+
// The type of the property.
12+
Type Type
13+
2014
// Whether the property is optional. If omitted, the property is mandatory.
2115
Optional bool
2216

23-
// Whether this is a proposed property. If omitted, the structure is final.
24-
Proposed bool
17+
// An optional documentation.
18+
Documentation string
2519

2620
// Since when (release number) this property is available. Is undefined if not known.
2721
Since string
2822

29-
// The type of the property.
30-
Type Type
23+
// All since tags in case there was more than one tag. Is undefined if not known.
24+
SinceTags []string
25+
26+
// Whether this is a proposed property. If omitted, the structure is final.
27+
Proposed bool
28+
29+
// Whether the property is deprecated or not. If deprecated the property contains the deprecation message.
30+
Deprecated string
31+
32+
// The property JSON name.
33+
JSONName string
3134
}

0 commit comments

Comments
 (0)