@@ -7,7 +7,7 @@ scriptencoding utf-8
7
7
let s: lspfactory = {}
8
8
9
9
function ! s: lspfactory .get () dict abort
10
- if ! has_key ( self , ' current' ) || empty (self .current) || ! has_key (self .current, ' job' ) || empty ( self .current.job )
10
+ if empty ( get ( self , ' current' , {})) || empty (get (self .current, ' job' , {}) )
11
11
let self .current = s: newlsp ()
12
12
endif
13
13
@@ -138,6 +138,10 @@ function! s:newlsp() abort
138
138
return
139
139
endif
140
140
141
+ if get (self , ' exited' , 0 )
142
+ return
143
+ endif
144
+
141
145
let l: msg = self .newResponse (a: req .id, l: resp )
142
146
call self .write (l: msg )
143
147
endfunction
@@ -305,13 +309,31 @@ function! s:newlsp() abort
305
309
call ch_sendraw (self .job, l: data )
306
310
endfunction
307
311
308
- function ! l: lsp .exit_cb (job, exit_status) dict abort
312
+ function ! l: lsp .exit_cb (job, exit_status) dict
313
+ let self .exited = 1
314
+ if ! get (self , ' restarting' , 0 )
315
+ return
316
+ endif
317
+
318
+ let l: queue = self .queue
319
+
320
+ let l: workspaces = self .workspaceDirectories
321
+
309
322
call s: lspfactory .reset ()
323
+ let l: lsp = s: lspfactory .get ()
324
+
325
+ " restore workspaces
326
+ call call (' go#lsp#AddWorkspaceDirectory' , l: workspaces )
327
+ " * send DidOpen messages for all buffers that have b:did_lsp_open set
328
+ " TODO(bc): check modifiable and filetype, too?
329
+ bufdo if get (b: , ' go_lsp_did_open' , 0 ) | if &modified | call go#lsp#DidOpen (expand (' %:p' )) | else | call go#lsp#DidChange (expand (' %:p' )) | endif | endif
330
+ let l: lsp .queue = extend (l: lsp .queue, l: queue )
331
+ return
310
332
endfunction
311
- " explicitly bind close_cb to state so that within it, self will always refer
312
333
313
334
function ! l: lsp .close_cb (ch ) dict abort
314
- " TODO(bc): does anything need to be done here?
335
+ " TODO(bc): remove the buffer variables that indicate that gopls has been
336
+ " informed that the file is open
315
337
endfunction
316
338
317
339
function ! l: lsp .err_cb (ch , msg) dict abort
@@ -767,6 +789,27 @@ function! go#lsp#DebugBrowser() abort
767
789
call go#util#OpenBrowser (printf (' http://localhost:%d' , l: port ))
768
790
endfunction
769
791
792
+ function ! go#lsp#Restart () abort
793
+ if ! go#util#has_job () || len (s: lspfactory ) == 0 || ! has_key (s: lspfactory , ' current' )
794
+ return
795
+ endif
796
+
797
+ let l: lsp = s: lspfactory .get ()
798
+
799
+ let l: lsp .restarting = 1
800
+
801
+ let l: state = s: newHandlerState (' exit' )
802
+
803
+ let l: msg = go#lsp#message#Shutdown ()
804
+ let l: state .handleResult = funcref (' s:noop' )
805
+ let l: retval = l: lsp .sendMessage (l: msg , l: state )
806
+
807
+ let l: msg = go#lsp#message#Exit ()
808
+ let l: retval = l: lsp .sendMessage (l: msg , l: state )
809
+
810
+ return l: retval
811
+ endfunction
812
+
770
813
function ! s: debug (event , data) abort
771
814
if ! go#util#HasDebug (' lsp' )
772
815
return
0 commit comments