mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	lsp: respect the sort order if there is sortText
This commit is contained in:
		| @@ -129,6 +129,15 @@ function M.extract_completion_items(result) | |||||||
|   end |   end | ||||||
| end | end | ||||||
|  |  | ||||||
|  | -- Sort by CompletionItem.sortText | ||||||
|  | -- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion | ||||||
|  | function M.sort_completion_items(items) | ||||||
|  |   if items[1] and items[1].sortText then | ||||||
|  |     table.sort(items, function(a, b) return a.sortText < b.sortText | ||||||
|  |     end) | ||||||
|  |   end | ||||||
|  | end | ||||||
|  |  | ||||||
| -- Some lanuguage servers return complementary candidates whose prefixes do not match are also returned. | -- Some lanuguage servers return complementary candidates whose prefixes do not match are also returned. | ||||||
| -- So we exclude completion candidates whose prefix does not match. | -- So we exclude completion candidates whose prefix does not match. | ||||||
| function M.remove_unmatch_completion_items(items, prefix) | function M.remove_unmatch_completion_items(items, prefix) | ||||||
| @@ -171,6 +180,7 @@ function M.text_document_completion_list_to_complete_items(result, prefix) | |||||||
|   end |   end | ||||||
|  |  | ||||||
|   items = M.remove_unmatch_completion_items(items, prefix) |   items = M.remove_unmatch_completion_items(items, prefix) | ||||||
|  |   M.sort_completion_items(items) | ||||||
|  |  | ||||||
|   local matches = {} |   local matches = {} | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Hirokazu Hata
					Hirokazu Hata