]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Added option for removing duplicate completion items
authorDaniel Viberg <daniel_viberg@outlook.com>
Tue, 2 Jan 2024 20:24:15 +0000 (21:24 +0100)
committerDaniel Viberg <daniel_viberg@outlook.com>
Tue, 2 Jan 2024 20:24:15 +0000 (21:24 +0100)
autoload/lsp/completion.vim
autoload/lsp/options.vim

index 4ab65dd1d954b146fdbddb0ac441774240296983..a1458299a74c812fb30a63837d9e523434f75b8e 100644 (file)
@@ -188,6 +188,7 @@ export def CompletionReply(lspserver: dict<any>, cItems: any)
   endif
 
   var completeItems: list<dict<any>> = []
+  var itemsUsed: list<string> = []
   for item in items
     var d: dict<any> = {}
 
@@ -295,6 +296,20 @@ export def CompletionReply(lspserver: dict<any>, cItems: any)
       d.score = item->get('label', '')
     endif
 
+    # Dont include duplicate items
+    if lspOpts.filterCompletionDuplicates       
+      var key = d->get('word', '') ..
+                d->get('info', '') ..
+                d->get('kind', '') ..
+                d->get('score', '') ..
+                d->get('abbr', '') ..
+                d->get('dup', '')
+      if index(itemsUsed, key) != -1            
+        continue                                                                          
+      endif                                                                      
+      add(itemsUsed, key)                       
+    endif  
+
     d.user_data = item
     completeItems->add(d)
   endfor
index dbe23dc17965790c3faaffcaf5c245dee7266a27..18e23dd1b29071e0b73a549e03b01d2ef3a87fab 100644 (file)
@@ -135,7 +135,10 @@ export var lspOptions: dict<any> = {
   customCompletionKinds: false,
 
   # A dictionary with all completion kinds that you want to customize
-  completionKinds: {}
+  completionKinds: {},
+
+  # Filter duplicate completion items
+  filterCompletionDuplicates: false,
 }
 
 # set the LSP plugin options from the user provided option values