@@ -11,6 +11,41 @@ import (
11
11
"go.uber.org/zap"
12
12
)
13
13
14
+ // clientHandler represents a client handler.
15
+ type clientHandler struct {
16
+ client ClientInterface
17
+ }
18
+
19
+ // compile time check whether the clientHandler implements jsonrpc2.Handler interface.
20
+ var _ jsonrpc2.Handler = & clientHandler {}
21
+
22
+ // Cancel implements Handler interface.
23
+ func (clientHandler ) Cancel (ctx context.Context , conn * jsonrpc2.Conn , id jsonrpc2.ID , canceled bool ) bool {
24
+ return false
25
+ }
26
+
27
+ // Request implements Handler interface.
28
+ func (clientHandler ) Request (ctx context.Context , conn * jsonrpc2.Conn , direction jsonrpc2.Direction , r * jsonrpc2.WireRequest ) context.Context {
29
+ return ctx
30
+ }
31
+
32
+ // Response implements Handler interface.
33
+ func (clientHandler ) Response (ctx context.Context , conn * jsonrpc2.Conn , direction jsonrpc2.Direction , r * jsonrpc2.WireResponse ) context.Context {
34
+ return ctx
35
+ }
36
+
37
+ // Done implements Handler interface.
38
+ func (clientHandler ) Done (ctx context.Context , err error ) {}
39
+
40
+ // Read implements Handler interface.
41
+ func (clientHandler ) Read (ctx context.Context , bytes int64 ) context.Context { return ctx }
42
+
43
+ // Write implements Handler interface.
44
+ func (clientHandler ) Write (ctx context.Context , bytes int64 ) context.Context { return ctx }
45
+
46
+ // Error implements Handler interface.
47
+ func (clientHandler ) Error (ctx context.Context , err error ) {}
48
+
14
49
// ClientInterface represents a Language Server Protocol client.
15
50
type ClientInterface interface {
16
51
Run (ctx context.Context ) (err error )
@@ -58,23 +93,23 @@ const (
58
93
MethodWorkspaceWorkspaceFolders = "workspace/workspaceFolders"
59
94
)
60
95
61
- // Client implements a Language Server Protocol client.
62
- type Client struct {
96
+ // client implements a Language Server Protocol client.
97
+ type client struct {
63
98
* jsonrpc2.Conn
64
99
logger * zap.Logger
65
100
}
66
101
67
102
// compiler time check whether the Client implements ClientInterface interface.
68
- var _ ClientInterface = (* Client )(nil )
103
+ var _ ClientInterface = (* client )(nil )
69
104
70
105
// Run runs the Language Server Protocol client.
71
- func (c * Client ) Run (ctx context.Context ) (err error ) {
106
+ func (c * client ) Run (ctx context.Context ) (err error ) {
72
107
err = c .Conn .Run (ctx )
73
108
return
74
109
}
75
110
76
111
// LogMessage sends the notification from the server to the client to ask the client to log a particular message.
77
- func (c * Client ) LogMessage (ctx context.Context , params * LogMessageParams ) (err error ) {
112
+ func (c * client ) LogMessage (ctx context.Context , params * LogMessageParams ) (err error ) {
78
113
err = c .Conn .Notify (ctx , MethodWindowLogMessage , params )
79
114
return
80
115
}
@@ -89,30 +124,30 @@ func (c *Client) LogMessage(ctx context.Context, params *LogMessageParams) (err
89
124
// When a file changes it is the server’s responsibility to re-compute diagnostics and push them to the client.
90
125
// If the computed set is empty it has to push the empty array to clear former diagnostics.
91
126
// Newly pushed diagnostics always replace previously pushed diagnostics. There is no merging that happens on the client side.
92
- func (c * Client ) PublishDiagnostics (ctx context.Context , params * PublishDiagnosticsParams ) (err error ) {
127
+ func (c * client ) PublishDiagnostics (ctx context.Context , params * PublishDiagnosticsParams ) (err error ) {
93
128
err = c .Conn .Notify (ctx , MethodTextDocumentPublishDiagnostics , params )
94
129
return
95
130
}
96
131
97
132
// ShowMessage sends the notification from a server to a client to ask the
98
133
// client to display a particular message in the user interface.
99
- func (c * Client ) ShowMessage (ctx context.Context , params * ShowMessageParams ) (err error ) {
134
+ func (c * client ) ShowMessage (ctx context.Context , params * ShowMessageParams ) (err error ) {
100
135
err = c .Conn .Notify (ctx , MethodWindowShowMessage , params )
101
136
return
102
137
}
103
138
104
139
// ShowMessageRequest sends the request from a server to a client to ask the client to display a particular message in the user interface.
105
140
//
106
141
// In addition to the show message notification the request allows to pass actions and to wait for an answer from the client.
107
- func (c * Client ) ShowMessageRequest (ctx context.Context , params * ShowMessageRequestParams ) (result * MessageActionItem , err error ) {
142
+ func (c * client ) ShowMessageRequest (ctx context.Context , params * ShowMessageRequestParams ) (result * MessageActionItem , err error ) {
108
143
result = new (MessageActionItem )
109
144
err = c .Conn .Call (ctx , MethodWindowShowMessageRequest , params , result )
110
145
111
146
return result , err
112
147
}
113
148
114
149
// Telemetry sends the notification from the server to the client to ask the client to log a telemetry event.
115
- func (c * Client ) Telemetry (ctx context.Context , params interface {}) (err error ) {
150
+ func (c * client ) Telemetry (ctx context.Context , params interface {}) (err error ) {
116
151
err = c .Conn .Notify (ctx , MethodTelemetryEvent , params )
117
152
return
118
153
}
@@ -123,19 +158,19 @@ func (c *Client) Telemetry(ctx context.Context, params interface{}) (err error)
123
158
//
124
159
// A client opts in via the dynamicRegistration property on the specific client capabilities.
125
160
// A client can even provide dynamic registration for capability A but not for capability B (see TextDocumentClientCapabilities as an example).
126
- func (c * Client ) RegisterCapability (ctx context.Context , params * RegistrationParams ) (err error ) {
161
+ func (c * client ) RegisterCapability (ctx context.Context , params * RegistrationParams ) (err error ) {
127
162
err = c .Conn .Call (ctx , MethodClientRegisterCapability , params , nil )
128
163
return
129
164
}
130
165
131
166
// UnregisterCapability sends the request from the server to the client to unregister a previously registered capability.
132
- func (c * Client ) UnregisterCapability (ctx context.Context , params * UnregistrationParams ) (err error ) {
167
+ func (c * client ) UnregisterCapability (ctx context.Context , params * UnregistrationParams ) (err error ) {
133
168
err = c .Conn .Call (ctx , MethodClientUnregisterCapability , params , nil )
134
169
return
135
170
}
136
171
137
172
// WorkspaceApplyEdit sends the request from the server to the client to modify resource on the client side.
138
- func (c * Client ) WorkspaceApplyEdit (ctx context.Context , params * ApplyWorkspaceEditParams ) (result bool , err error ) {
173
+ func (c * client ) WorkspaceApplyEdit (ctx context.Context , params * ApplyWorkspaceEditParams ) (result bool , err error ) {
139
174
err = c .Conn .Call (ctx , MethodWorkspaceApplyEdit , params , & result )
140
175
141
176
return result , err
@@ -146,7 +181,7 @@ func (c *Client) WorkspaceApplyEdit(ctx context.Context, params *ApplyWorkspaceE
146
181
// The request can fetch several configuration settings in one roundtrip.
147
182
// The order of the returned configuration settings correspond to the order of the
148
183
// passed ConfigurationItems (e.g. the first item in the response is the result for the first configuration item in the params).
149
- func (c * Client ) WorkspaceConfiguration (ctx context.Context , params * ConfigurationParams ) ([]interface {}, error ) {
184
+ func (c * client ) WorkspaceConfiguration (ctx context.Context , params * ConfigurationParams ) ([]interface {}, error ) {
150
185
var result []interface {}
151
186
err := c .Conn .Call (ctx , MethodWorkspaceConfiguration , params , & result )
152
187
@@ -158,7 +193,7 @@ func (c *Client) WorkspaceConfiguration(ctx context.Context, params *Configurati
158
193
// Returns null in the response if only a single file is open in the tool. Returns an empty array if a workspace is open but no folders are configured.
159
194
//
160
195
// Since version 3.6.0.
161
- func (c * Client ) WorkspaceFolders (ctx context.Context ) (result []WorkspaceFolder , err error ) {
196
+ func (c * client ) WorkspaceFolders (ctx context.Context ) (result []WorkspaceFolder , err error ) {
162
197
err = c .Conn .Call (ctx , MethodWorkspaceWorkspaceFolders , nil , & result )
163
198
164
199
return result , err
0 commit comments