From 45f704017ceb6240e6e2d8520bf75288ed03b62a Mon Sep 17 00:00:00 2001
From: "shane.xb.qian" <shane.qian@foxmail.com>
Date: Mon, 7 Nov 2022 15:18:54 +0800
Subject: [PATCH] feat: make code action popup can be selected by item num, and
 'h/l' to close popup as well.

---
 autoload/lsp/codeaction.vim | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/autoload/lsp/codeaction.vim b/autoload/lsp/codeaction.vim
index 862c4ac..d739064 100644
--- a/autoload/lsp/codeaction.vim
+++ b/autoload/lsp/codeaction.vim
@@ -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)
-- 
2.51.0