Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion lspgenerator/go/base_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def generate_base_types(
),
)
result.append(
"\n".join(
join(
[
"type ResponseError struct {",
'\tCode int32 `json:"code"`',
Expand All @@ -120,5 +120,23 @@ def generate_base_types(
],
),
)
result.append(
join(
[
"type Message interface {",
" isMessage()",
"}",
"type Request interface {",
" isRequest()",
"}",
"type Notification interface {",
" isNotification()",
"}",
"type Response interface {",
" isResponse()",
"}",
],
),
)
result.append("\n")
return result
4 changes: 4 additions & 0 deletions lspgenerator/go/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def generate_notifications(
f'\tParams {param_type} `json:"params"`',
]
struct.append("}")
struct.append(f"func (t *{notification.typeName}) isMessage() {{}}")
struct.append(
f"func (t *{notification.typeName}) isNotification() {{}}"
)
struct += [
f"func (t *{notification.typeName}) UnmarshalJSON(x []byte) error {{",
" var m map[string]any",
Expand Down
4 changes: 4 additions & 0 deletions lspgenerator/go/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def generate_requests(
]

struct.append("}")
struct.append(f"func (t *{request.typeName}) isMessage() {{}}")
struct.append(f"func (t *{request.typeName}) isRequest() {{}}")
struct += [
f"func (t *{request.typeName}) UnmarshalJSON(x []byte) error {{",
" var m map[string]any",
Expand Down Expand Up @@ -117,5 +119,7 @@ def generate_requests(
" return nil",
"}",
]
struct.append(f"func (t *{response_name}) isMessage() {{}}")
struct.append(f"func (t *{response_name}) isResponse() {{}}")
result.append(join(struct))
return result
11 changes: 11 additions & 0 deletions protocol/interfaces_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package protocol

// Compile-time interface compliance checks
var (
_ Message = (*InitializeRequest)(nil)
_ Message = (*InitializedNotification)(nil)
_ Message = (*InitializeResponse)(nil)
_ Request = (*InitializeRequest)(nil)
_ Notification = (*InitializedNotification)(nil)
_ Response = (*InitializeResponse)(nil)
)
Loading
Loading