From: Peter Lithammer Date: Thu, 20 Apr 2023 15:13:36 +0000 (+0200) Subject: Sort complete items based on `sortText` X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=c477dd2e0ab4cf9402d83558771f5ee0eeb0dac6;p=vim-lsp.git Sort complete items based on `sortText` With this, complete items should be sorted in the same way as Visual Studio Code (more or less). Unless the fuzzy matcher is enabled. Fixes #281 --- diff --git a/autoload/lsp/completion.vim b/autoload/lsp/completion.vim index 938e55a..93a2ad5 100644 --- a/autoload/lsp/completion.vim +++ b/autoload/lsp/completion.vim @@ -255,10 +255,22 @@ export def CompletionReply(lspserver: dict, cItems: any) endif endif + # Score is used for sorting. + d.score = item->get('sortText') + if d.score->empty() + d.score = item->get('label', '') + endif + d.user_data = item completeItems->add(d) endfor + if opt.lspOptions.completionMatcher != 'fuzzy' + # Lexographical sort (case-insensitive). + completeItems->sort((a, b) => + a.score ==# b.score ? 0 : a.score >? b.score ? 1 : -1) + endif + if opt.lspOptions.autoComplete && !lspserver.omniCompletePending if completeItems->empty() # no matches