File tree Expand file tree Collapse file tree 5 files changed +401
-24
lines changed Expand file tree Collapse file tree 5 files changed +401
-24
lines changed Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ def generate_base_types(
110
110
),
111
111
)
112
112
result.append(
113
- "\n". join(
113
+ join(
114
114
[
115
115
"type ResponseError struct {",
116
116
'\tCode int32 `json:"code"`',
@@ -120,5 +120,23 @@ def generate_base_types(
120
120
],
121
121
),
122
122
)
123
+ result.append(
124
+ join(
125
+ [
126
+ "type Message interface {",
127
+ " isMessage()",
128
+ "}",
129
+ "type Request interface {",
130
+ " isRequest()",
131
+ "}",
132
+ "type Notification interface {",
133
+ " isNotification()",
134
+ "}",
135
+ "type Response interface {",
136
+ " isResponse()",
137
+ "}",
138
+ ],
139
+ ),
140
+ )
123
141
result.append("\n")
124
142
return result
Original file line number Diff line number Diff line change @@ -46,6 +46,10 @@ def generate_notifications(
46
46
f'\tParams {param_type} `json:"params"`',
47
47
]
48
48
struct.append("}")
49
+ struct.append(f"func (t *{notification.typeName}) isMessage() {{}}")
50
+ struct.append(
51
+ f"func (t *{notification.typeName}) isNotification() {{}}"
52
+ )
49
53
struct += [
50
54
f"func (t *{notification.typeName}) UnmarshalJSON(x []byte) error {{",
51
55
" var m map[string]any",
Original file line number Diff line number Diff line change @@ -50,6 +50,8 @@ def generate_requests(
50
50
]
51
51
52
52
struct.append("}")
53
+ struct.append(f"func (t *{request.typeName}) isMessage() {{}}")
54
+ struct.append(f"func (t *{request.typeName}) isRequest() {{}}")
53
55
struct += [
54
56
f"func (t *{request.typeName}) UnmarshalJSON(x []byte) error {{",
55
57
" var m map[string]any",
@@ -117,5 +119,7 @@ def generate_requests(
117
119
" return nil",
118
120
"}",
119
121
]
122
+ struct.append(f"func (t *{response_name}) isMessage() {{}}")
123
+ struct.append(f"func (t *{response_name}) isResponse() {{}}")
120
124
result.append(join(struct))
121
125
return result
Original file line number Diff line number Diff line change
1
+ package protocol
2
+
3
+ // Compile-time interface compliance checks
4
+ var (
5
+ _ Message = (*InitializeRequest)(nil)
6
+ _ Message = (*InitializedNotification)(nil)
7
+ _ Message = (*InitializeResponse)(nil)
8
+ _ Request = (*InitializeRequest)(nil)
9
+ _ Notification = (*InitializedNotification)(nil)
10
+ _ Response = (*InitializeResponse)(nil)
11
+ )
You can’t perform that action at this time.
0 commit comments