]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
none: compl item sel
authorshane.xb.qian <shane.qian@foxmail.com>
Tue, 26 Dec 2023 06:02:56 +0000 (14:02 +0800)
committershane.xb.qian <shane.qian@foxmail.com>
Tue, 26 Dec 2023 06:02:56 +0000 (14:02 +0800)
Signed-off-by: shane.xb.qian <shane.qian@foxmail.com>
autoload/lsp/completion.vim

index 4ab65dd1d954b146fdbddb0ac441774240296983..26dc24a982d7a38cffd852e4a0c8e844401252d7 100644 (file)
@@ -330,23 +330,30 @@ export def CompletionReply(lspserver: dict<any>, cItems: any)
   endif
 enddef
 
-# process the completion documentation
-def ShowCompletionDocumentation(cItem: any)
-  if cItem->empty() || cItem->type() != v:t_dict
-    return
-  endif
-
-  # check if completion item is still selected
+# Check if completion item is selected
+def CheckCompletionItemSel(label: string): bool
   var cInfo = complete_info()
   if cInfo->empty() || !cInfo.pum_visible || cInfo.selected == -1
-    return
+    return false
   endif
-
   var selItem = cInfo.items->get(cInfo.selected, {})
   if selItem->empty()
       || selItem->type() != v:t_dict
       || selItem.user_data->type() != v:t_dict
-      || selItem.user_data.label != cItem.label
+      || selItem.user_data.label != label
+    return false
+  endif
+  return true
+enddef
+
+# Process the completion documentation
+def ShowCompletionDocumentation(cItem: any)
+  if cItem->empty() || cItem->type() != v:t_dict
+    return
+  endif
+
+  # check if completion item is still selected
+  if !CheckCompletionItemSel(cItem.label)
     return
   endif
 
@@ -390,13 +397,7 @@ def ShowCompletionDocumentation(cItem: any)
   endif
 
   # check if completion item is changed in meantime
-  cInfo = complete_info()
-  if cInfo->empty()
-      || !cInfo.pum_visible
-      || cInfo.selected == -1
-      || cInfo.items[cInfo.selected]->type() != v:t_dict
-      || cInfo.items[cInfo.selected].user_data->type() != v:t_dict
-      || cInfo.items[cInfo.selected].user_data.label != cItem.label
+  if !CheckCompletionItemSel(cItem.label)
     return
   endif