2
2
"
3
3
let s: context = {}
4
4
5
+ function ! s: run_complete_done_after_in_normal_mode () abort
6
+ " Only run if we are in regular normal mode (and not visual or operator-pending mode)
7
+ if mode (1 ) == # ' n'
8
+ return printf (" :\<C-U> call \<SNR> %d_on_complete_done_after()\<CR> " , s: SID ())
9
+ else
10
+ return ' '
11
+ endif
12
+ endfunction
13
+
14
+ function ! s: run_complete_done_after_in_insert_mode () abort
15
+ if mode (1 )[0 ] == # ' i'
16
+ return printf (" \<C-R> =\<SNR> %d_on_complete_done_after()\<CR> " , s: SID ())
17
+ else
18
+ return ' '
19
+ endif
20
+ endfunction
21
+
5
22
function ! lsp#ui#vim#completion#_setup () abort
6
23
augroup lsp_ui_vim_completion
7
24
autocmd !
8
25
autocmd CompleteDone * call s: on_complete_done ()
9
26
augroup END
27
+
28
+ nnoremap <silent> <expr> <Plug> (__lsp-internal-on-complete-done-after) <SID> run_complete_done_after_in_normal_mode()
29
+ inoremap <silent> <expr> <Plug> (__lsp-internal-on-complete-done-after) <SID> run_complete_done_after_in_insert_mode()
10
30
endfunction
11
31
12
32
function ! lsp#ui#vim#completion#_disable () abort
@@ -56,21 +76,13 @@ function! s:on_complete_done() abort
56
76
let s: context [' server_name' ] = l: managed_user_data [' server_name' ]
57
77
let s: context [' completion_item' ] = l: managed_user_data [' completion_item' ]
58
78
let s: context [' start_character' ] = l: managed_user_data [' start_character' ]
59
- call feedkeys (printf ( " \<C-r> =<SNR>%d_on_complete_done_after() \<CR> " , s: SID ()) , ' n' )
79
+ call feedkeys (" \<Plug> (__lsp-internal-on-complete-done-after) " , ' n' )
60
80
endfunction
61
81
62
82
"
63
83
" Apply textEdit or insertText(snippet) and additionalTextEdits.
64
84
"
65
85
function ! s: on_complete_done_after () abort
66
- " Clear message line. feedkeys above leave garbage on message line.
67
- echo ' '
68
-
69
- " Ignore process if the mode() is not insert-mode after feedkeys.
70
- if mode (1 )[0 ] !=# ' i'
71
- return ' '
72
- endif
73
-
74
86
let l: done_line = s: context [' done_line' ]
75
87
let l: done_line_nr = s: context [' done_line_nr' ]
76
88
let l: completed_item = s: context [' completed_item' ]
@@ -97,6 +109,11 @@ function! s:on_complete_done_after() abort
97
109
" clear completed string if need.
98
110
let l: is_expandable = s: is_expandable (l: done_line , l: done_position , l: complete_position , l: completion_item , l: completed_item )
99
111
if l: is_expandable
112
+ " clear_auto_inserted_text() wants to move the cursor to just after
113
+ " complete_position, which in normal mode may need 'onemore' in
114
+ " 'virtualedit'.
115
+ let l: old_virtualedit = &l: virtualedit
116
+ setlocal virtualedit += onemore
100
117
call s: clear_auto_inserted_text (l: done_line , l: done_position , l: complete_position )
101
118
endif
102
119
@@ -131,6 +148,7 @@ function! s:on_complete_done_after() abort
131
148
\ ' character' : l: position [' character' ] + l: overflow_after ,
132
149
\ }
133
150
\ }
151
+ let &l: virtualedit = l: old_virtualedit
134
152
135
153
if get (l: completion_item , ' insertTextFormat' , 1 ) == 2
136
154
" insert Snippet.
0 commit comments