]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
feat: make code action popup can be selected by item num, and 'h/l' to close popup...
authorshane.xb.qian <shane.qian@foxmail.com>
Mon, 7 Nov 2022 07:18:54 +0000 (15:18 +0800)
committershane.xb.qian <shane.qian@foxmail.com>
Mon, 7 Nov 2022 07:18:54 +0000 (15:18 +0800)
autoload/lsp/codeaction.vim

index 862c4ac23005832a3149d550cf32281a0c4884b1..d739064f09a0ad6b60bea888bb0074ac565fffb0 100644 (file)
@@ -77,16 +77,26 @@ export def ApplyCodeAction(lspserver: dict<any>, actions: list<dict<any>>): void
         mapping: 0,
         wrap: 0,
         title: 'Code action',
-        callback: (_, id) => {
+        callback: (_, result) => {
           # Invalid item selected or closed the popup
-          if id <= 0 || id > text->len()
+          if result <= 0 || result > text->len()
             return
           endif
 
           # Do the code action
-          HandleCodeAction(lspserver, actions[id - 1])
+          HandleCodeAction(lspserver, actions[result - 1])
         },
-        filter: 'popup_filter_menu'
+       filter: (winid, key) => {
+         if key == 'h' || key == 'l'
+           popup_close(winid, -1)
+         elseif str2nr(key) > 0
+           # supposed would not over 9 items
+           popup_close(winid, str2nr(key))
+         else
+           return popup_filter_menu(winid, key)
+         endif
+         return 1
+       },
       })
     else
       choice = inputlist(["Code action:"] + text)