From ef1ec5341f9360085bede74bba25cf8bc5190a5f Mon Sep 17 00:00:00 2001 From: w0rp Date: Mon, 28 May 2018 14:45:07 +0100 Subject: [PATCH] Fix #1568 - Filter LSP completion results with the prefixes --- autoload/ale/completion.vim | 4 ++ .../test_lsp_completion_parsing.vader | 39 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim index c15a486..c3139da 100644 --- a/autoload/ale/completion.vim +++ b/autoload/ale/completion.vim @@ -296,6 +296,10 @@ function! ale#completion#ParseLSPCompletions(response) abort \}) endfor + if has_key(l:info, 'prefix') + return ale#completion#Filter(l:buffer, l:results, l:info.prefix) + endif + return l:results endfunction diff --git a/test/completion/test_lsp_completion_parsing.vader b/test/completion/test_lsp_completion_parsing.vader index c9c51a6..23bbd14 100644 --- a/test/completion/test_lsp_completion_parsing.vader +++ b/test/completion/test_lsp_completion_parsing.vader @@ -390,3 +390,42 @@ Execute(Should handle Python completion results correctly): \ ] \ } \ }) + +Execute(Should handle Python completion results correctly): + let b:ale_completion_info = { + \ 'completion_filter': 'ale#completion#python#CompletionItemFilter', + \ 'prefix': 'mig', + \} + + AssertEqual + \ [ + \ {'word': 'migrations', 'menu': 'xxx', 'info': 'migrations', 'kind': 'f', 'icase': 1}, + \ {'word': 'MigEngine', 'menu': 'xxx', 'info': 'mig engine', 'kind': 'f', 'icase': 1}, + \ ], + \ ale#completion#ParseLSPCompletions({ + \ 'jsonrpc': '2.0', + \ 'id': 6, + \ 'result': { + \ 'isIncomplete': v:false, + \ 'items': [ + \ { + \ 'label': 'migrations', + \ 'kind': 3, + \ 'detail': 'xxx', + \ 'documentation': 'migrations', + \ }, + \ { + \ 'label': 'MigEngine', + \ 'kind': 3, + \ 'detail': 'xxx', + \ 'documentation': 'mig engine', + \ }, + \ { + \ 'label': 'ignore me', + \ 'kind': 3, + \ 'detail': 'nope', + \ 'documentation': 'nope', + \ }, + \ ] + \ } + \ })