1
- let s: last_req_id = 0
2
-
3
1
function ! s: not_supported (what) abort
4
2
return lsp#utils#error (a: what .' not supported for ' .&filetype )
5
3
endfunction
6
4
7
5
function ! lsp#ui#vim#implementation (in_preview) abort
8
6
let l: servers = filter (lsp#get_whitelisted_servers (), ' lsp#capabilities#has_implementation_provider(v:val)' )
9
- let s: last_req_id = s: last_req_id + 1
7
+ let l: command_id = lsp#_new_command ()
10
8
call setqflist ([])
11
9
12
10
if len (l: servers ) == 0
13
11
call s: not_supported (' Retrieving implementation' )
14
12
return
15
13
endif
16
- let l: ctx = { ' counter' : len (l: servers ), ' list' :[], ' last_req_id ' : s: last_req_id , ' jump_if_one' : 1 , ' in_preview' : a: in_preview }
14
+ let l: ctx = { ' counter' : len (l: servers ), ' list' :[], ' last_command_id ' : l: command_id , ' jump_if_one' : 1 , ' in_preview' : a: in_preview }
17
15
for l: server in l: servers
18
16
call lsp#send_request (l: server , {
19
17
\ ' method' : ' textDocument/implementation' ,
@@ -30,14 +28,14 @@ endfunction
30
28
31
29
function ! lsp#ui#vim#type_definition (in_preview) abort
32
30
let l: servers = filter (lsp#get_whitelisted_servers (), ' lsp#capabilities#has_type_definition_provider(v:val)' )
33
- let s: last_req_id = s: last_req_id + 1
31
+ let l: command_id = lsp#_new_command ()
34
32
call setqflist ([])
35
33
36
34
if len (l: servers ) == 0
37
35
call s: not_supported (' Retrieving type definition' )
38
36
return
39
37
endif
40
- let l: ctx = { ' counter' : len (l: servers ), ' list' :[], ' last_req_id ' : s: last_req_id , ' jump_if_one' : 1 , ' in_preview' : a: in_preview }
38
+ let l: ctx = { ' counter' : len (l: servers ), ' list' :[], ' last_command_id ' : l: command_id , ' jump_if_one' : 1 , ' in_preview' : a: in_preview }
41
39
for l: server in l: servers
42
40
call lsp#send_request (l: server , {
43
41
\ ' method' : ' textDocument/typeDefinition' ,
@@ -54,13 +52,13 @@ endfunction
54
52
55
53
function ! lsp#ui#vim#type_hierarchy () abort
56
54
let l: servers = filter (lsp#get_whitelisted_servers (), ' lsp#capabilities#has_type_hierarchy_provider(v:val)' )
57
- let s: last_req_id = s: last_req_id + 1
55
+ let l: command_id = lsp#_new_command ()
58
56
59
57
if len (l: servers ) == 0
60
58
call s: not_supported (' Retrieving type hierarchy' )
61
59
return
62
60
endif
63
- let l: ctx = { ' counter' : len (l: servers ), ' list' :[], ' last_req_id ' : s: last_req_id }
61
+ let l: ctx = { ' counter' : len (l: servers ), ' list' :[], ' last_command_id ' : l: command_id }
64
62
" direction 0 children, 1 parent, 2 both
65
63
for l: server in l: servers
66
64
call lsp#send_request (l: server , {
@@ -80,15 +78,15 @@ endfunction
80
78
81
79
function ! lsp#ui#vim#declaration (in_preview) abort
82
80
let l: servers = filter (lsp#get_whitelisted_servers (), ' lsp#capabilities#has_declaration_provider(v:val)' )
83
- let s: last_req_id = s: last_req_id + 1
81
+ let l: command_id = lsp#_new_command ()
84
82
call setqflist ([])
85
83
86
84
if len (l: servers ) == 0
87
85
call s: not_supported (' Retrieving declaration' )
88
86
return
89
87
endif
90
88
91
- let l: ctx = { ' counter' : len (l: servers ), ' list' :[], ' last_req_id ' : s: last_req_id , ' jump_if_one' : 1 , ' in_preview' : a: in_preview }
89
+ let l: ctx = { ' counter' : len (l: servers ), ' list' :[], ' last_command_id ' : l: command_id , ' jump_if_one' : 1 , ' in_preview' : a: in_preview }
92
90
for l: server in l: servers
93
91
call lsp#send_request (l: server , {
94
92
\ ' method' : ' textDocument/declaration' ,
@@ -105,15 +103,15 @@ endfunction
105
103
106
104
function ! lsp#ui#vim#definition (in_preview) abort
107
105
let l: servers = filter (lsp#get_whitelisted_servers (), ' lsp#capabilities#has_definition_provider(v:val)' )
108
- let s: last_req_id = s: last_req_id + 1
106
+ let l: command_id = lsp#_new_command ()
109
107
call setqflist ([])
110
108
111
109
if len (l: servers ) == 0
112
110
call s: not_supported (' Retrieving definition' )
113
111
return
114
112
endif
115
113
116
- let l: ctx = { ' counter' : len (l: servers ), ' list' :[], ' last_req_id ' : s: last_req_id , ' jump_if_one' : 1 , ' in_preview' : a: in_preview }
114
+ let l: ctx = { ' counter' : len (l: servers ), ' list' :[], ' last_command_id ' : l: command_id , ' jump_if_one' : 1 , ' in_preview' : a: in_preview }
117
115
for l: server in l: servers
118
116
call lsp#send_request (l: server , {
119
117
\ ' method' : ' textDocument/definition' ,
@@ -130,11 +128,11 @@ endfunction
130
128
131
129
function ! lsp#ui#vim#references () abort
132
130
let l: servers = filter (lsp#get_whitelisted_servers (), ' lsp#capabilities#has_references_provider(v:val)' )
133
- let s: last_req_id = s: last_req_id + 1
131
+ let l: command_id = lsp#_new_command ()
134
132
135
133
call setqflist ([])
136
134
137
- let l: ctx = { ' counter' : len (l: servers ), ' list' :[], ' last_req_id ' : s: last_req_id , ' jump_if_one' : 0 , ' in_preview' : 0 }
135
+ let l: ctx = { ' counter' : len (l: servers ), ' list' :[], ' last_command_id ' : l: command_id , ' jump_if_one' : 0 , ' in_preview' : 0 }
138
136
if len (l: servers ) == 0
139
137
call s: not_supported (' Retrieving references' )
140
138
return
@@ -169,7 +167,7 @@ function! s:rename(server, new_name, pos) abort
169
167
\ ' position' : a: pos ,
170
168
\ ' newName' : a: new_name ,
171
169
\ },
172
- \ ' on_notification' : function (' s:handle_workspace_edit' , [a: server , s: last_req_id , ' rename' ]),
170
+ \ ' on_notification' : function (' s:handle_workspace_edit' , [a: server , lsp#_last_command () , ' rename' ]),
173
171
\ })
174
172
175
173
echo ' ... Renaming ...'
@@ -183,7 +181,7 @@ function! lsp#ui#vim#rename() abort
183
181
let l: prepare_support = 0
184
182
endif
185
183
186
- let s: last_req_id = s: last_req_id + 1
184
+ let l: command_id = lsp#_new_command ()
187
185
188
186
if len (l: servers ) == 0
189
187
call s: not_supported (' Renaming' )
@@ -200,7 +198,7 @@ function! lsp#ui#vim#rename() abort
200
198
\ ' textDocument' : lsp#get_text_document_identifier (),
201
199
\ ' position' : lsp#get_position (),
202
200
\ },
203
- \ ' on_notification' : function (' s:handle_rename_prepare' , [l: server , s: last_req_id , ' rename_prepare' ]),
201
+ \ ' on_notification' : function (' s:handle_rename_prepare' , [l: server , l: command_id , ' rename_prepare' ]),
204
202
\ })
205
203
return
206
204
endif
@@ -210,7 +208,7 @@ endfunction
210
208
211
209
function ! s: document_format (sync ) abort
212
210
let l: servers = filter (lsp#get_whitelisted_servers (), ' lsp#capabilities#has_document_formatting_provider(v:val)' )
213
- let s: last_req_id = s: last_req_id + 1
211
+ let l: command_id = lsp#_new_command ()
214
212
215
213
if len (l: servers ) == 0
216
214
call s: not_supported (' Document formatting' )
@@ -230,7 +228,7 @@ function! s:document_format(sync) abort
230
228
\ },
231
229
\ },
232
230
\ ' sync' : a: sync ,
233
- \ ' on_notification' : function (' s:handle_text_edit' , [l: server , s: last_req_id , ' document format' ]),
231
+ \ ' on_notification' : function (' s:handle_text_edit' , [l: server , l: command_id , ' document format' ]),
234
232
\ })
235
233
endfunction
236
234
@@ -290,7 +288,7 @@ endfunction
290
288
291
289
function ! s: document_format_range (sync , type ) abort
292
290
let l: servers = filter (lsp#get_whitelisted_servers (), ' lsp#capabilities#has_document_range_formatting_provider(v:val)' )
293
- let s: last_req_id = s: last_req_id + 1
291
+ let l: command_id = lsp#_new_command ()
294
292
295
293
if len (l: servers ) == 0
296
294
call s: not_supported (' Document range formatting' )
@@ -318,7 +316,7 @@ function! s:document_format_range(sync, type) abort
318
316
\ },
319
317
\ },
320
318
\ ' sync' : a: sync ,
321
- \ ' on_notification' : function (' s:handle_text_edit' , [l: server , s: last_req_id , ' range format' ]),
319
+ \ ' on_notification' : function (' s:handle_text_edit' , [l: server , l: command_id , ' range format' ]),
322
320
\ })
323
321
endfunction
324
322
@@ -336,7 +334,7 @@ endfunction
336
334
337
335
function ! lsp#ui#vim#workspace_symbol () abort
338
336
let l: servers = filter (lsp#get_whitelisted_servers (), ' lsp#capabilities#has_workspace_symbol_provider(v:val)' )
339
- let s: last_req_id = s: last_req_id + 1
337
+ let l: command_id = lsp#_new_command ()
340
338
341
339
call setqflist ([])
342
340
@@ -353,7 +351,7 @@ function! lsp#ui#vim#workspace_symbol() abort
353
351
\ ' params' : {
354
352
\ ' query' : l: query ,
355
353
\ },
356
- \ ' on_notification' : function (' s:handle_symbol' , [l: server , s: last_req_id , ' workspaceSymbol' ]),
354
+ \ ' on_notification' : function (' s:handle_symbol' , [l: server , l: command_id , ' workspaceSymbol' ]),
357
355
\ })
358
356
endfor
359
357
@@ -362,7 +360,7 @@ endfunction
362
360
363
361
function ! lsp#ui#vim#document_symbol () abort
364
362
let l: servers = filter (lsp#get_whitelisted_servers (), ' lsp#capabilities#has_document_symbol_provider(v:val)' )
365
- let s: last_req_id = s: last_req_id + 1
363
+ let l: command_id = lsp#_new_command ()
366
364
367
365
call setqflist ([])
368
366
@@ -377,7 +375,7 @@ function! lsp#ui#vim#document_symbol() abort
377
375
\ ' params' : {
378
376
\ ' textDocument' : lsp#get_text_document_identifier (),
379
377
\ },
380
- \ ' on_notification' : function (' s:handle_symbol' , [l: server , s: last_req_id , ' documentSymbol' ]),
378
+ \ ' on_notification' : function (' s:handle_symbol' , [l: server , l: command_id , ' documentSymbol' ]),
381
379
\ })
382
380
endfor
383
381
@@ -413,7 +411,7 @@ endfunction
413
411
" https://microsoft.github.io/language-server-protocol/specification#textDocument_codeAction
414
412
function ! lsp#ui#vim#code_action () abort
415
413
let l: servers = filter (lsp#get_whitelisted_servers (), ' lsp#capabilities#has_code_action_provider(v:val)' )
416
- let s: last_req_id = s: last_req_id + 1
414
+ let l: command_id = lsp#_new_command ()
417
415
let l: diagnostic = lsp#ui#vim#diagnostics#get_diagnostics_under_cursor ()
418
416
419
417
if len (l: servers ) == 0
@@ -445,15 +443,15 @@ function! lsp#ui#vim#code_action() abort
445
443
\ ' only' : [' ' , ' quickfix' , ' refactor' , ' refactor.extract' , ' refactor.inline' , ' refactor.rewrite' , ' source' , ' source.organizeImports' ],
446
444
\ },
447
445
\ },
448
- \ ' on_notification' : function (' s:handle_code_action' , [l: server , s: last_req_id , ' codeAction' ]),
446
+ \ ' on_notification' : function (' s:handle_code_action' , [l: server , l: command_id , ' codeAction' ]),
449
447
\ })
450
448
endfor
451
449
452
450
echo ' Retrieving code actions ...'
453
451
endfunction
454
452
455
- function ! s: handle_symbol (server, last_req_id , type , data) abort
456
- if a: last_req_id != s: last_req_id
453
+ function ! s: handle_symbol (server, last_command_id , type , data) abort
454
+ if a: last_command_id != lsp#_last_command ()
457
455
return
458
456
endif
459
457
@@ -474,8 +472,8 @@ function! s:handle_symbol(server, last_req_id, type, data) abort
474
472
endif
475
473
endfunction
476
474
477
- function ! s: handle_location (ctx, server, type , data) abort " ctx = {counter, list, jump_if_one, last_req_id , in_preview}
478
- if a: ctx [' last_req_id ' ] != s: last_req_id
475
+ function ! s: handle_location (ctx, server, type , data) abort " ctx = {counter, list, jump_if_one, last_command_id , in_preview}
476
+ if a: ctx [' last_command_id ' ] != lsp#_last_command ()
479
477
return
480
478
endif
481
479
@@ -523,8 +521,8 @@ function! s:handle_location(ctx, server, type, data) abort "ctx = {counter, list
523
521
endif
524
522
endfunction
525
523
526
- function ! s: handle_rename_prepare (server, last_req_id , type , data) abort
527
- if a: last_req_id != s: last_req_id
524
+ function ! s: handle_rename_prepare (server, last_command_id , type , data) abort
525
+ if a: last_command_id != lsp#_last_command ()
528
526
return
529
527
endif
530
528
@@ -554,8 +552,8 @@ function! s:handle_rename_prepare(server, last_req_id, type, data) abort
554
552
call timer_start (1 , {x - >s: rename (a: server , input (' new name: ' , l: name ), l: range [' start' ])})
555
553
endfunction
556
554
557
- function ! s: handle_workspace_edit (server, last_req_id , type , data) abort
558
- if a: last_req_id != s: last_req_id
555
+ function ! s: handle_workspace_edit (server, last_command_id , type , data) abort
556
+ if a: last_command_id != lsp#_last_command ()
559
557
return
560
558
endif
561
559
@@ -569,8 +567,8 @@ function! s:handle_workspace_edit(server, last_req_id, type, data) abort
569
567
echo ' Renamed'
570
568
endfunction
571
569
572
- function ! s: handle_text_edit (server, last_req_id , type , data) abort
573
- if a: last_req_id != s: last_req_id
570
+ function ! s: handle_text_edit (server, last_command_id , type , data) abort
571
+ if a: last_command_id != lsp#_last_command ()
574
572
return
575
573
endif
576
574
@@ -584,7 +582,7 @@ function! s:handle_text_edit(server, last_req_id, type, data) abort
584
582
redraw | echo ' Document formatted'
585
583
endfunction
586
584
587
- function ! s: handle_code_action (server, last_req_id , type , data) abort
585
+ function ! s: handle_code_action (server, last_command_id , type , data) abort
588
586
if lsp#client#is_error (a: data [' response' ])
589
587
call lsp#utils#error (' Failed to ' . a: type . ' for ' . a: server . ' : ' . lsp#client#error_message (a: data [' response' ]))
590
588
return
@@ -615,8 +613,8 @@ function! s:handle_code_action(server, last_req_id, type, data) abort
615
613
endif
616
614
endfunction
617
615
618
- function ! s: handle_type_hierarchy (ctx, server, type , data) abort " ctx = {counter, list, last_req_id }
619
- if a: ctx [' last_req_id ' ] != s: last_req_id
616
+ function ! s: handle_type_hierarchy (ctx, server, type , data) abort " ctx = {counter, list, last_command_id }
617
+ if a: ctx [' last_command_id ' ] != lsp#_last_command ()
620
618
return
621
619
endif
622
620
0 commit comments