@@ -20,7 +20,7 @@ import (
20
20
21
21
// clientDispatch implements jsonrpc2.Conn.
22
22
//nolint:funlen,gocognit
23
- func clientDispatch (ctx context.Context , client Client , reply jsonrpc2.Replier , req jsonrpc2.Request ) (bool , error ) {
23
+ func clientDispatch (ctx context.Context , client Client , reply jsonrpc2.Replier , req jsonrpc2.Request ) (handled bool , err error ) {
24
24
if ctx .Err () != nil {
25
25
return true , reply (ctx , nil , ErrRequestCancelled )
26
26
}
@@ -30,163 +30,103 @@ func clientDispatch(ctx context.Context, client Client, reply jsonrpc2.Replier,
30
30
logger := LoggerFromContext (ctx )
31
31
32
32
switch req .Method () {
33
- case MethodClientRegisterCapability : // request
34
- var params RegistrationParams
35
- if err := dec .DecodeObject (& params ); err != nil {
36
- return true , replyParseError (ctx , reply , err )
37
- }
38
-
39
- err := client .RegisterCapability (ctx , & params )
40
- reply = func (ctx context.Context , result interface {}, err error ) error {
41
- replyErr := reply (ctx , nil , err )
42
- if replyErr != nil {
43
- logger .Error (MethodClientRegisterCapability , zap .Error (replyErr ))
44
- }
45
- return replyErr
46
- }
47
- return true , reply (ctx , nil , err )
33
+ case MethodWindowLogMessage : // notification
34
+ defer logger .Debug (MethodWindowLogMessage , zap .Error (err ))
48
35
49
- case MethodClientUnregisterCapability : // request
50
- var params UnregistrationParams
36
+ var params LogMessageParams
51
37
if err := dec .DecodeObject (& params ); err != nil {
52
38
return true , replyParseError (ctx , reply , err )
53
39
}
54
-
55
- err := client .UnregisterCapability (ctx , & params )
56
- reply = func (ctx context.Context , result interface {}, err error ) error {
57
- replyErr := reply (ctx , nil , err )
58
- if replyErr != nil {
59
- logger .Error (MethodClientUnregisterCapability , zap .Error (replyErr ))
60
- }
61
- return replyErr
62
- }
63
- return true , reply (ctx , nil , err )
64
-
65
- case MethodTelemetryEvent : // notification
66
- var params interface {}
67
- if err := dec .Decode (& params ); err != nil {
68
- return true , replyParseError (ctx , reply , err )
69
- }
70
-
71
- err := client .Telemetry (ctx , & params )
72
- reply = func (ctx context.Context , result interface {}, err error ) error {
73
- replyErr := reply (ctx , nil , err )
74
- if replyErr != nil {
75
- logger .Error (MethodTelemetryEvent , zap .Error (replyErr ))
76
- }
77
- return replyErr
78
- }
40
+ err := client .LogMessage (ctx , & params )
79
41
return true , reply (ctx , nil , err )
80
42
81
43
case MethodTextDocumentPublishDiagnostics : // notification
44
+ defer logger .Debug (MethodTextDocumentPublishDiagnostics , zap .Error (err ))
45
+
82
46
var params PublishDiagnosticsParams
83
47
if err := dec .DecodeObject (& params ); err != nil {
84
48
return true , replyParseError (ctx , reply , err )
85
49
}
86
-
87
50
err := client .PublishDiagnostics (ctx , & params )
88
- reply = func (ctx context.Context , result interface {}, err error ) error {
89
- replyErr := reply (ctx , nil , err )
90
- if replyErr != nil {
91
- logger .Error (MethodTextDocumentPublishDiagnostics , zap .Error (replyErr ))
92
- }
93
- return replyErr
94
- }
95
51
return true , reply (ctx , nil , err )
96
52
97
- case MethodWindowLogMessage : // notification
98
- var params LogMessageParams
53
+ case MethodWindowShowMessage : // notification
54
+ defer logger .Debug (MethodWindowShowMessage , zap .Error (err ))
55
+
56
+ var params ShowMessageParams
99
57
if err := dec .DecodeObject (& params ); err != nil {
100
58
return true , replyParseError (ctx , reply , err )
101
59
}
102
-
103
- err := client .LogMessage (ctx , & params )
104
- reply = func (ctx context.Context , result interface {}, err error ) error {
105
- replyErr := reply (ctx , nil , err )
106
- if replyErr != nil {
107
- logger .Error (MethodWindowLogMessage , zap .Error (replyErr ))
108
- }
109
- return replyErr
110
- }
60
+ err := client .ShowMessage (ctx , & params )
111
61
return true , reply (ctx , nil , err )
112
62
113
- case MethodWindowShowMessage : // notification
114
- var params ShowMessageParams
63
+ case MethodWindowShowMessageRequest : // request
64
+ defer logger .Debug (MethodWindowShowMessageRequest , zap .Error (err ))
65
+
66
+ var params ShowMessageRequestParams
115
67
if err := dec .DecodeObject (& params ); err != nil {
116
68
return true , replyParseError (ctx , reply , err )
117
69
}
70
+ resp , err := client .ShowMessageRequest (ctx , & params )
71
+ return true , reply (ctx , resp , err )
118
72
119
- err := client .ShowMessage (ctx , & params )
120
- reply = func (ctx context.Context , result interface {}, err error ) error {
121
- replyErr := reply (ctx , nil , err )
122
- if replyErr != nil {
123
- logger .Error (MethodWindowShowMessage , zap .Error (replyErr ))
124
- }
125
- return replyErr
73
+ case MethodTelemetryEvent : // notification
74
+ defer logger .Debug (MethodTelemetryEvent , zap .Error (err ))
75
+
76
+ var params interface {}
77
+ if err := dec .Decode (& params ); err != nil {
78
+ return true , replyParseError (ctx , reply , err )
126
79
}
80
+ err := client .Telemetry (ctx , & params )
127
81
return true , reply (ctx , nil , err )
128
82
129
- case MethodWindowShowMessageRequest : // request
130
- var params ShowMessageRequestParams
83
+ case MethodClientRegisterCapability : // request
84
+ defer logger .Debug (MethodClientRegisterCapability , zap .Error (err ))
85
+
86
+ var params RegistrationParams
131
87
if err := dec .DecodeObject (& params ); err != nil {
132
88
return true , replyParseError (ctx , reply , err )
133
89
}
90
+ err := client .RegisterCapability (ctx , & params )
91
+ return true , reply (ctx , nil , err )
134
92
135
- resp , err := client .ShowMessageRequest (ctx , & params )
136
- reply = func (ctx context.Context , result interface {}, err error ) error {
137
- replyErr := reply (ctx , result , err )
138
- if replyErr != nil {
139
- logger .Error (MethodWindowShowMessageRequest , zap .Error (replyErr ))
140
- }
141
- return replyErr
93
+ case MethodClientUnregisterCapability : // request
94
+ defer logger .Debug (MethodClientUnregisterCapability , zap .Error (err ))
95
+
96
+ var params UnregistrationParams
97
+ if err := dec .DecodeObject (& params ); err != nil {
98
+ return true , replyParseError (ctx , reply , err )
142
99
}
143
- return true , reply (ctx , resp , err )
100
+ err := client .UnregisterCapability (ctx , & params )
101
+ return true , reply (ctx , nil , err )
144
102
145
103
case MethodWorkspaceApplyEdit : // request
104
+ defer logger .Debug (MethodWorkspaceApplyEdit , zap .Error (err ))
105
+
146
106
var params ApplyWorkspaceEditParams
147
107
if err := dec .DecodeObject (& params ); err != nil {
148
108
return true , replyParseError (ctx , reply , err )
149
109
}
150
-
151
110
resp , err := client .WorkspaceApplyEdit (ctx , & params )
152
- reply = func (ctx context.Context , result interface {}, err error ) error {
153
- replyErr := reply (ctx , result , err )
154
- if replyErr != nil {
155
- logger .Error (MethodWorkspaceApplyEdit , zap .Error (replyErr ))
156
- }
157
- return replyErr
158
- }
159
111
return true , reply (ctx , resp , err )
160
112
161
113
case MethodWorkspaceConfiguration : // request
114
+ defer logger .Debug (MethodWorkspaceConfiguration , zap .Error (err ))
115
+
162
116
var params ConfigurationParams
163
117
if err := dec .DecodeObject (& params ); err != nil {
164
118
return true , replyParseError (ctx , reply , err )
165
119
}
166
-
167
120
resp , err := client .WorkspaceConfiguration (ctx , & params )
168
- reply = func (ctx context.Context , result interface {}, err error ) error {
169
- replyErr := reply (ctx , result , err )
170
- if replyErr != nil {
171
- logger .Error (MethodWorkspaceConfiguration , zap .Error (replyErr ))
172
- }
173
- return replyErr
174
- }
175
121
return true , reply (ctx , resp , err )
176
122
177
123
case MethodWorkspaceWorkspaceFolders : // request
124
+ defer logger .Debug (MethodWorkspaceWorkspaceFolders , zap .Error (err ))
125
+
178
126
if len (req .Params ()) > 0 {
179
- return true , reply (ctx , nil , fmt .Errorf ("%w: expected no params" , jsonrpc2 .ErrInvalidParams ))
127
+ return true , reply (ctx , nil , fmt .Errorf ("expected no params: %w " , jsonrpc2 .ErrInvalidParams ))
180
128
}
181
-
182
129
resp , err := client .WorkspaceFolders (ctx )
183
- reply = func (ctx context.Context , result interface {}, err error ) error {
184
- replyErr := reply (ctx , result , err )
185
- if replyErr != nil {
186
- logger .Error (MethodWorkspaceWorkspaceFolders , zap .Error (replyErr ))
187
- }
188
- return replyErr
189
- }
190
130
return true , reply (ctx , resp , err )
191
131
192
132
default :
0 commit comments