@@ -46,9 +46,7 @@ type streamServer struct {
46
46
serverForTest protocol.Server
47
47
}
48
48
49
- // NewStreamServer creates a StreamServer using the shared cache. If
50
- // withTelemetry is true, each session is instrumented with telemetry that
51
- // records RPC statistics.
49
+ // NewStreamServer creates a StreamServer using the shared cache.
52
50
func NewStreamServer (cache * cache.Cache , daemon bool , optionsFunc func (* settings.Options )) jsonrpc2.StreamServer {
53
51
return & streamServer {cache : cache , daemon : daemon , optionsOverrides : optionsFunc }
54
52
}
@@ -70,17 +68,11 @@ func (s *streamServer) ServeStream(ctx context.Context, conn jsonrpc2.Conn) erro
70
68
event .Error (ctx , "error shutting down" , err )
71
69
}
72
70
}()
73
- executable , err := os .Executable ()
74
- if err != nil {
75
- log .Printf ("error getting gopls path: %v" , err )
76
- executable = ""
77
- }
78
71
ctx = protocol .WithClient (ctx , client )
79
72
conn .Go (ctx ,
80
73
protocol .Handlers (
81
- handshaker ("unknown" , executable , s .daemon ,
82
- protocol .ServerHandler (svr ,
83
- jsonrpc2 .MethodNotFound ))))
74
+ handshaker ("unknown" , s .daemon ,
75
+ protocol .ServerHandler (svr , jsonrpc2 .MethodNotFound ))))
84
76
if s .daemon {
85
77
log .Printf ("Session %s: connected" , "unknown" )
86
78
defer log .Printf ("Session %s: exited" , "unknown" )
@@ -89,12 +81,12 @@ func (s *streamServer) ServeStream(ctx context.Context, conn jsonrpc2.Conn) erro
89
81
return conn .Err ()
90
82
}
91
83
92
- // A forwarder is a jsonrpc2.StreamServer that handles an LSP stream by
93
- // forwarding it to a remote. This is used when the gopls process started by
94
- // the editor is in the `-remote` mode, which means it finds and connects to a
95
- // separate gopls daemon. In these cases, we still want the forwarder gopls to
96
- // be instrumented with telemetry, and want to be able to in some cases hijack
97
- // the jsonrpc2 connection with the daemon.
84
+ // A forwarder is a jsonrpc2.StreamServer that handles an LSP stream
85
+ // by forwarding it to a remote. This is used when the cuelsp process
86
+ // started by the editor is in the `-remote` mode, which means it
87
+ // finds and connects to a separate cuelsp daemon. In these cases, we
88
+ // still want the forwarder cuelsp to in some cases hijack the
89
+ // jsonrpc2 connection with the daemon.
98
90
type forwarder struct {
99
91
dialer * autoDialer
100
92
@@ -128,23 +120,23 @@ func QueryServerState(ctx context.Context, addr string) (any, error) {
128
120
return nil , err
129
121
}
130
122
var state serverState
131
- if err := protocol .Call (ctx , serverConn , sessionsMethod , nil , & state ); err != nil {
123
+ if err := protocol .Call (ctx , serverConn , serversMethod , nil , & state ); err != nil {
132
124
return nil , fmt .Errorf ("querying server state: %w" , err )
133
125
}
134
126
return & state , nil
135
127
}
136
128
137
- // dialRemote is used for making calls into the gopls daemon. addr should be a
129
+ // dialRemote is used for making calls into the cuelsp daemon. addr should be a
138
130
// URL, possibly on the synthetic 'auto' network (e.g. tcp://..., unix://...,
139
131
// or auto://...).
140
132
func dialRemote (ctx context.Context , addr string ) (jsonrpc2.Conn , error ) {
141
133
network , address := ParseAddr (addr )
142
134
if network == autoNetwork {
143
- gp , err := os .Executable ()
135
+ cuePath , err := os .Executable ()
144
136
if err != nil {
145
- return nil , fmt .Errorf ("getting gopls path: %w" , err )
137
+ return nil , fmt .Errorf ("getting cue path: %w" , err )
146
138
}
147
- network , address = autoNetworkAddress (gp , address )
139
+ network , address = autoNetworkAddress (cuePath , address )
148
140
}
149
141
netConn , err := net .DialTimeout (network , address , 5 * time .Second )
150
142
if err != nil {
@@ -227,32 +219,16 @@ func (f *forwarder) ServeStream(ctx context.Context, clientConn jsonrpc2.Conn) e
227
219
func (f * forwarder ) handshake (ctx context.Context ) {
228
220
// This call to os.Executable is redundant, and will be eliminated by the
229
221
// transition to the V2 API.
230
- goplsPath , err := os .Executable ()
231
- if err != nil {
232
- event .Error (ctx , "getting executable for handshake" , err )
233
- goplsPath = ""
234
- }
235
- var (
236
- hreq = handshakeRequest {
237
- ServerID : f .serverID ,
238
- GoplsPath : goplsPath ,
239
- }
240
- hresp handshakeResponse
241
- )
222
+ hreq := handshakeRequest {ServerID : f .serverID }
223
+ var hresp handshakeResponse
242
224
if err := protocol .Call (ctx , f .serverConn , handshakeMethod , hreq , & hresp ); err != nil {
243
225
// TODO(rfindley): at some point in the future we should return an error
244
226
// here. Handshakes have become functional in nature.
245
- event .Error (ctx , "forwarder: gopls handshake failed" , err )
246
- }
247
- if hresp .GoplsPath != goplsPath {
248
- event .Error (ctx , "" , fmt .Errorf ("forwarder: gopls path mismatch: forwarder is %q, remote is %q" , goplsPath , hresp .GoplsPath ))
227
+ event .Error (ctx , "forwarder: cuelsp handshake failed" , err )
249
228
}
250
229
event .Log (ctx , "New server" ,
251
230
tag .NewServer .Of (f .serverID ),
252
- tag .Logfile .Of (hresp .Logfile ),
253
- tag .DebugAddress .Of (hresp .DebugAddr ),
254
- tag .GoplsPath .Of (hresp .GoplsPath ),
255
- tag .ClientID .Of (hresp .SessionID ),
231
+ tag .ServerID .Of (hresp .ServerID ),
256
232
)
257
233
}
258
234
@@ -266,57 +242,35 @@ func ConnectToRemote(ctx context.Context, addr string) (net.Conn, error) {
266
242
267
243
// A handshakeRequest identifies a client to the LSP server.
268
244
type handshakeRequest struct {
269
- // ServerID is the ID of the server on the client. This should usually be 0.
245
+ // ServerID is the ID of the server on the client. This should
246
+ // usually be 0.
270
247
ServerID string `json:"serverID"`
271
- // Logfile is the location of the clients log file.
272
- Logfile string `json:"logfile"`
273
- // DebugAddr is the client debug address.
274
- DebugAddr string `json:"debugAddr"`
275
- // GoplsPath is the path to the Gopls binary running the current client
276
- // process.
277
- GoplsPath string `json:"goplsPath"`
278
248
}
279
249
280
- // A handshakeResponse is returned by the LSP server to tell the LSP client
281
- // information about its session .
250
+ // A handshakeResponse is returned by the LSP server to tell the LSP
251
+ // client information about its server .
282
252
type handshakeResponse struct {
283
- // SessionID is the server session associated with the client.
284
- SessionID string `json:"sessionID"`
285
- // Logfile is the location of the server logs.
286
- Logfile string `json:"logfile"`
287
- // DebugAddr is the server debug address.
288
- DebugAddr string `json:"debugAddr"`
289
- // GoplsPath is the path to the Gopls binary running the current server
290
- // process.
291
- GoplsPath string `json:"goplsPath"`
253
+ // ServerID is the server server associated with the client.
254
+ ServerID string `json:"serverID"`
292
255
}
293
256
294
- // clientSession identifies a current client LSP session on the server. Note
295
- // that it looks similar to handshakeResposne, but in fact 'Logfile' and
296
- // 'DebugAddr' now refer to the client.
297
- type clientSession struct {
298
- SessionID string `json:"sessionID"`
299
- Logfile string `json:"logfile"`
300
- DebugAddr string `json:"debugAddr"`
257
+ // clientServer identifies a current client LSP server on the
258
+ // server.
259
+ type clientServer struct {
260
+ ServerID string `json:"serverID"`
301
261
}
302
262
303
- // serverState holds information about the gopls daemon process, including its
304
- // debug information and debug information of all of its current connected
305
- // clients.
263
+ // serverState holds information about the cuelsp daemon process.
306
264
type serverState struct {
307
- Logfile string `json:"logfile"`
308
- DebugAddr string `json:"debugAddr"`
309
- GoplsPath string `json:"goplsPath"`
310
- CurrentClientID string `json:"currentClientID"`
311
- Clients []clientSession `json:"clients"`
265
+ CurrentServerID string `json:"currentServerID"`
312
266
}
313
267
314
268
const (
315
- handshakeMethod = "gopls /handshake"
316
- sessionsMethod = "gopls/sessions "
269
+ handshakeMethod = "cuelsp /handshake"
270
+ serversMethod = "cuelsp/servers "
317
271
)
318
272
319
- func handshaker (svrID string , goplsPath string , logHandshakes bool , handler jsonrpc2.Handler ) jsonrpc2.Handler {
273
+ func handshaker (svrID string , logHandshakes bool , handler jsonrpc2.Handler ) jsonrpc2.Handler {
320
274
return func (ctx context.Context , reply jsonrpc2.Replier , r jsonrpc2.Request ) error {
321
275
switch r .Method () {
322
276
case handshakeMethod :
@@ -326,30 +280,25 @@ func handshaker(svrID string, goplsPath string, logHandshakes bool, handler json
326
280
var req handshakeRequest
327
281
if err := json .Unmarshal (r .Params (), & req ); err != nil {
328
282
if logHandshakes {
329
- log .Printf ("Error processing handshake for session %s: %v" , svrID , err )
283
+ log .Printf ("Error processing handshake for server %s: %v" , svrID , err )
330
284
}
331
285
sendError (ctx , reply , err )
332
286
return nil
333
287
}
334
288
if logHandshakes {
335
- log .Printf ("Session %s: got handshake. Logfile: %q, Debug addr: %q " , svrID , req . Logfile , req . DebugAddr )
289
+ log .Printf ("Server %s: got handshake." , svrID )
336
290
}
337
- event .Log (ctx , "Handshake session update" ,
338
- tag .DebugAddress .Of (req .DebugAddr ),
339
- tag .Logfile .Of (req .Logfile ),
291
+ event .Log (ctx , "Handshake server update" ,
340
292
tag .ServerID .Of (req .ServerID ),
341
- tag .GoplsPath .Of (req .GoplsPath ),
342
293
)
343
294
resp := handshakeResponse {
344
- SessionID : svrID ,
345
- GoplsPath : goplsPath ,
295
+ ServerID : svrID ,
346
296
}
347
297
return reply (ctx , resp , nil )
348
298
349
- case sessionsMethod :
299
+ case serversMethod :
350
300
resp := serverState {
351
- GoplsPath : goplsPath ,
352
- CurrentClientID : svrID ,
301
+ CurrentServerID : svrID ,
353
302
}
354
303
return reply (ctx , resp , nil )
355
304
}
@@ -364,7 +313,7 @@ func sendError(ctx context.Context, reply jsonrpc2.Replier, err error) {
364
313
}
365
314
}
366
315
367
- // ParseAddr parses the address of a gopls remote.
316
+ // ParseAddr parses the address of a cuelsp remote.
368
317
// TODO(rFindley): further document this syntax, and allow URI-style remote
369
318
// addresses such as "auto://...".
370
319
func ParseAddr (listen string ) (network string , address string ) {
0 commit comments