@@ -13,13 +13,23 @@ import (
13
13
"go.lsp.dev/pkg/xcontext"
14
14
)
15
15
16
+ // ClientDispatcher returns a Client that dispatches LSP requests across the
17
+ // given jsonrpc2 connection.
18
+ func ClientDispatcher (conn jsonrpc2.Conn , logger * zap.Logger ) Client {
19
+ return & client {
20
+ Conn : conn ,
21
+ logger : logger ,
22
+ }
23
+ }
24
+
16
25
// ClientHandler handler of LSP client.
17
26
func ClientHandler (client Client , handler jsonrpc2.Handler ) jsonrpc2.Handler {
18
27
h := func (ctx context.Context , reply jsonrpc2.Replier , req jsonrpc2.Request ) error {
19
28
if ctx .Err () != nil {
20
29
xctx := xcontext .Detach (ctx )
21
30
return reply (xctx , nil , ErrRequestCancelled )
22
31
}
32
+
23
33
handled , err := clientDispatch (ctx , client , reply , req )
24
34
if handled || err != nil {
25
35
return err
@@ -88,6 +98,9 @@ var _ Client = (*client)(nil)
88
98
89
99
// LogMessage sends the notification from the server to the client to ask the client to log a particular message.
90
100
func (c * client ) LogMessage (ctx context.Context , params * LogMessageParams ) (err error ) {
101
+ c .logger .Debug ("call " + MethodWindowLogMessage )
102
+ defer c .logger .Debug ("end " + MethodWindowLogMessage , zap .Error (err ))
103
+
91
104
return c .Conn .Notify (ctx , MethodWindowLogMessage , params )
92
105
}
93
106
@@ -102,6 +115,9 @@ func (c *client) LogMessage(ctx context.Context, params *LogMessageParams) (err
102
115
// If the computed set is empty it has to push the empty array to clear former diagnostics.
103
116
// Newly pushed diagnostics always replace previously pushed diagnostics. There is no merging that happens on the client side.
104
117
func (c * client ) PublishDiagnostics (ctx context.Context , params * PublishDiagnosticsParams ) (err error ) {
118
+ c .logger .Debug ("call " + MethodTextDocumentPublishDiagnostics )
119
+ defer c .logger .Debug ("end " + MethodTextDocumentPublishDiagnostics , zap .Error (err ))
120
+
105
121
return c .Conn .Notify (ctx , MethodTextDocumentPublishDiagnostics , params )
106
122
}
107
123
@@ -114,15 +130,22 @@ func (c *client) ShowMessage(ctx context.Context, params *ShowMessageParams) (er
114
130
// ShowMessageRequest sends the request from a server to a client to ask the client to display a particular message in the user interface.
115
131
//
116
132
// In addition to the show message notification the request allows to pass actions and to wait for an answer from the client.
117
- func (c * client ) ShowMessageRequest (ctx context.Context , params * ShowMessageRequestParams ) (result * MessageActionItem , err error ) {
118
- result = new ( MessageActionItem )
119
- _ , err = c . Conn . Call ( ctx , MethodWindowShowMessageRequest , params , result )
133
+ func (c * client ) ShowMessageRequest (ctx context.Context , params * ShowMessageRequestParams ) (_ * MessageActionItem , err error ) {
134
+ c . logger . Debug ( "call " + MethodWindowShowMessageRequest )
135
+ defer c . logger . Debug ( "end " + MethodWindowShowMessageRequest , zap . Error ( err ) )
120
136
121
- return result , err
137
+ var result * MessageActionItem
138
+ if err := Call (ctx , c .Conn , MethodWindowShowMessageRequest , params , & result ); err != nil {
139
+ return nil , err
140
+ }
141
+ return result , nil
122
142
}
123
143
124
144
// Telemetry sends the notification from the server to the client to ask the client to log a telemetry event.
125
145
func (c * client ) Telemetry (ctx context.Context , params interface {}) (err error ) {
146
+ c .logger .Debug ("call " + MethodTelemetryEvent )
147
+ defer c .logger .Debug ("end " + MethodTelemetryEvent , zap .Error (err ))
148
+
126
149
return c .Conn .Notify (ctx , MethodTelemetryEvent , params )
127
150
}
128
151
@@ -133,33 +156,45 @@ func (c *client) Telemetry(ctx context.Context, params interface{}) (err error)
133
156
// A client opts in via the dynamicRegistration property on the specific client capabilities.
134
157
// A client can even provide dynamic registration for capability A but not for capability B (see TextDocumentClientCapabilities as an example).
135
158
func (c * client ) RegisterCapability (ctx context.Context , params * RegistrationParams ) (err error ) {
136
- _ , err = c .Conn .Call (ctx , MethodClientRegisterCapability , params , nil )
137
- return
159
+ c .logger .Debug ("call " + MethodClientRegisterCapability )
160
+ defer c .logger .Debug ("end " + MethodClientRegisterCapability , zap .Error (err ))
161
+
162
+ return Call (ctx , c .Conn , MethodClientRegisterCapability , params , nil )
138
163
}
139
164
140
165
// UnregisterCapability sends the request from the server to the client to unregister a previously registered capability.
141
166
func (c * client ) UnregisterCapability (ctx context.Context , params * UnregistrationParams ) (err error ) {
142
- _ , err = c .Conn .Call (ctx , MethodClientUnregisterCapability , params , nil )
143
- return
167
+ c .logger .Debug ("call " + MethodClientUnregisterCapability )
168
+ defer c .logger .Debug ("end " + MethodClientUnregisterCapability , zap .Error (err ))
169
+
170
+ return Call (ctx , c .Conn , MethodClientUnregisterCapability , params , nil )
144
171
}
145
172
146
173
// WorkspaceApplyEdit sends the request from the server to the client to modify resource on the client side.
147
174
func (c * client ) WorkspaceApplyEdit (ctx context.Context , params * ApplyWorkspaceEditParams ) (result bool , err error ) {
148
- _ , err = c .Conn .Call (ctx , MethodWorkspaceApplyEdit , params , & result )
175
+ c .logger .Debug ("call " + MethodWorkspaceApplyEdit )
176
+ defer c .logger .Debug ("end " + MethodWorkspaceApplyEdit , zap .Error (err ))
149
177
150
- return result , err
178
+ if err := Call (ctx , c .Conn , MethodWorkspaceApplyEdit , params , & result ); err != nil {
179
+ return false , err
180
+ }
181
+ return result , nil
151
182
}
152
183
153
184
// WorkspaceConfiguration sends the request from the server to the client to fetch configuration settings from the client.
154
185
//
155
186
// The request can fetch several configuration settings in one roundtrip.
156
187
// The order of the returned configuration settings correspond to the order of the
157
188
// passed ConfigurationItems (e.g. the first item in the response is the result for the first configuration item in the params).
158
- func (c * client ) WorkspaceConfiguration (ctx context.Context , params * ConfigurationParams ) ([]interface {}, error ) {
159
- var result [] interface {}
160
- _ , err := c . Conn . Call ( ctx , MethodWorkspaceConfiguration , params , & result )
189
+ func (c * client ) WorkspaceConfiguration (ctx context.Context , params * ConfigurationParams ) (_ []interface {}, err error ) {
190
+ c . logger . Debug ( "call " + MethodWorkspaceConfiguration )
191
+ defer c . logger . Debug ( "end " + MethodWorkspaceConfiguration , zap . Error ( err ) )
161
192
162
- return result , err
193
+ var result []interface {}
194
+ if err := Call (ctx , c .Conn , MethodWorkspaceConfiguration , params , & result ); err != nil {
195
+ return nil , err
196
+ }
197
+ return result , nil
163
198
}
164
199
165
200
// WorkspaceFolders sends the request from the server to the client to fetch the current open list of workspace folders.
@@ -168,7 +203,11 @@ func (c *client) WorkspaceConfiguration(ctx context.Context, params *Configurati
168
203
//
169
204
// Since version 3.6.0.
170
205
func (c * client ) WorkspaceFolders (ctx context.Context ) (result []WorkspaceFolder , err error ) {
171
- _ , err = c .Conn .Call (ctx , MethodWorkspaceWorkspaceFolders , nil , & result )
206
+ c .logger .Debug ("call " + MethodWorkspaceWorkspaceFolders )
207
+ defer c .logger .Debug ("end " + MethodWorkspaceWorkspaceFolders , zap .Error (err ))
172
208
173
- return result , err
209
+ if err := Call (ctx , c .Conn , MethodWorkspaceWorkspaceFolders , nil , & result ); err != nil {
210
+ return nil , err
211
+ }
212
+ return result , nil
174
213
}
0 commit comments