]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
none: refine code action regex a bit
authorshane.xb.qian <shane.qian@foxmail.com>
Sun, 31 Dec 2023 06:18:58 +0000 (14:18 +0800)
committershane.xb.qian <shane.qian@foxmail.com>
Sun, 31 Dec 2023 06:18:58 +0000 (14:18 +0800)
Signed-off-by: shane.xb.qian <shane.qian@foxmail.com>
autoload/lsp/codeaction.vim

index 9aa9c9a01b388ba2124067bc26566249e4b92f15..fb2a91a5d4f5fb411dd6bfdafca79a22b4c5a5d6 100644 (file)
@@ -82,12 +82,13 @@ export def ApplyCodeAction(lspserver: dict<any>, actionlist: list<dict<any>>, qu
 
   var choice: number
 
-  if query =~ '^\d\+'  # digit
-    choice = query->str2nr()
-  elseif query =~ '^/' # regex
-    choice = 1 + util.Indexof(actions, (i, a) => a.title =~ query[1 : ])
-  elseif query != ''   # literal string
-    choice = 1 + util.Indexof(actions, (i, a) => a.title[0 : query->len() - 1] == query)
+  var query_ = query->trim()
+  if query_ =~ '^\d\+$'        # digit
+    choice = query_->str2nr()
+  elseif query_ =~ '^/'        # regex
+    choice = 1 + util.Indexof(actions, (i, a) => a.title =~ query_[1 : ])
+  elseif query_ != ''  # literal string
+    choice = 1 + util.Indexof(actions, (i, a) => a.title[0 : query_->len() - 1] == query_)
   elseif opt.lspOptions.usePopupInCodeAction
     # Use a popup menu to show the code action
     popup_create(text, {