@@ -107,24 +107,44 @@ function! s:handle_code_action(ctx, server_name, command_id, sync, query, bufnr,
107
107
endif
108
108
call lsp#log (' s:handle_code_action' , l: total_code_actions )
109
109
110
- " Prompt to choose code actions when empty query provided.
111
- let l: index = 1
112
- if len (l: total_code_actions ) > 1 || empty (a: query )
113
- let l: index = inputlist (map (copy (l: total_code_actions ), funcref (' s:get_action_list_item_text' )))
110
+ if len (l: total_code_actions ) == 1 && ! empty (a: query )
111
+ let l: action = l: total_code_actions [0 ]
112
+ if s: handle_disabled_action (l: action ) | return | endif
113
+ " Clear 'Retrieving code actions ...' message
114
+ echo ' '
115
+ call s: handle_one_code_action (l: action [' server_name' ], a: sync , a: bufnr , l: action [' code_action' ])
116
+ return
114
117
endif
115
118
116
- " Execute code action.
117
- if 0 < l: index && l: index <= len (l: total_code_actions )
118
- let l: selected = l: total_code_actions [l: index - 1 ]
119
- if has_key (l: selected , ' disabled' )
120
- let l: reason = l: selected [' disabled' ][' reason' ]
121
- " Avoid the message is overwritten by inputlist() call
122
- redraw
123
- echo ' This action is disabled: ' . l: reason
124
- return
119
+ " Prompt to choose code actions when empty query provided.
120
+ let l: items = []
121
+ for l: action in l: total_code_actions
122
+ let l: title = printf (' [%s] %s' , l: action [' server_name' ], l: action [' code_action' ][' title' ])
123
+ if has_key (l: action [' code_action' ], ' kind' ) && l: action [' code_action' ][' kind' ] !=# ' '
124
+ let l: title .= ' (' . l: action [' code_action' ][' kind' ] . ' )'
125
125
endif
126
- call s: handle_one_code_action (l: selected [' server_name' ], a: sync , a: bufnr , l: selected [' code_action' ])
126
+ call add (l: items , { ' title' : l: title , ' item' : l: action })
127
+ endfor
128
+ call lsp#internal#ui#quickpick#open ({
129
+ \ ' items' : l: items ,
130
+ \ ' key' : ' title' ,
131
+ \ ' on_accept' : funcref (' s:accept_code_action' , [a: sync , a: bufnr ]),
132
+ \ })
133
+ endfunction
134
+
135
+ function ! s: accept_code_action (sync , bufnr , data, ... ) abort
136
+ call lsp#internal#ui#quickpick#close ()
137
+ let l: selected = a: data [' items' ][0 ][' item' ]
138
+ if s: handle_disabled_action (l: selected ) | return | endif
139
+ call s: handle_one_code_action (l: selected [' server_name' ], a: sync , a: bufnr , l: selected [' code_action' ])
140
+ endfunction
141
+
142
+ function ! s: handle_disabled_action (code_action) abort
143
+ if has_key (a: code_action , ' disabled' )
144
+ echo ' This action is disabled: ' . a: code_action [' disabled' ][' reason' ]
145
+ return v: true
127
146
endif
147
+ return v: false
128
148
endfunction
129
149
130
150
function ! s: handle_one_code_action (server_name, sync , bufnr , command_or_code_action) abort
@@ -154,11 +174,3 @@ function! s:handle_one_code_action(server_name, sync, bufnr, command_or_code_act
154
174
\ })
155
175
endif
156
176
endfunction
157
-
158
- function ! s: get_action_list_item_text (index , action) abort
159
- let l: text = printf (' %s - [%s] %s' , a: index + 1 , a: action [' server_name' ], a: action [' code_action' ][' title' ])
160
- if has_key (a: action [' code_action' ], ' kind' ) && a: action [' code_action' ][' kind' ] !=# ' '
161
- let l: text .= ' (' . a: action [' code_action' ][' kind' ] . ' )'
162
- endif
163
- return l: text
164
- endfunction
0 commit comments