From c477dd2e0ab4cf9402d83558771f5ee0eeb0dac6 Mon Sep 17 00:00:00 2001 From: Peter Lithammer Date: Thu, 20 Apr 2023 17:13:36 +0200 Subject: [PATCH] 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 --- autoload/lsp/completion.vim | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 -- 2.50.0