From 31f3ec85ae2cd6d52c29bc6307063d2585ff0f34 Mon Sep 17 00:00:00 2001
From: Girish Palya <girishji@gmail.com>
Date: Tue, 6 Feb 2024 13:12:28 +0100
Subject: [PATCH] BUG: omnifuc throws E716

In LspOmniFunc() when cItems is empty (when findstart=1) it does not
set the key 'completeItemsIsIncomplete' in the lspserver dictionary.
When LspOmniFunc is called again with findstart=0, it fails.
line   46:
E716: Key not present in Dictionary: "completeItemsIsIncomplete"

This affects rust, nix, and other lsp servers:
https://github.com/girishji/vimcomplete/issues/14

M  autoload/lsp/completion.vim
---
 autoload/lsp/completion.vim | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/autoload/lsp/completion.vim b/autoload/lsp/completion.vim
index 4ea3577..aa93db1 100644
--- a/autoload/lsp/completion.vim
+++ b/autoload/lsp/completion.vim
@@ -147,6 +147,7 @@ enddef
 # process the 'textDocument/completion' reply from the LSP server
 # Result: CompletionItem[] | CompletionList | null
 export def CompletionReply(lspserver: dict<any>, cItems: any)
+  lspserver.completeItemsIsIncomplete = false
   if cItems->empty()
     if lspserver.omniCompletePending
       lspserver.completeItems = []
@@ -155,8 +156,6 @@ export def CompletionReply(lspserver: dict<any>, cItems: any)
     return
   endif
 
-  lspserver.completeItemsIsIncomplete = false
-
   var items: list<dict<any>>
   if cItems->type() == v:t_list
     items = cItems
@@ -469,6 +468,7 @@ enddef
 
 # omni complete handler
 def g:LspOmniFunc(findstart: number, base: string): any
+
   var lspserver: dict<any> = buf.CurbufGetServerChecked('completion')
   if lspserver->empty()
     return -2
-- 
2.51.0