diff --git a/README.md b/README.md index dcc4ed38..3ace66e2 100644 --- a/README.md +++ b/README.md @@ -193,12 +193,11 @@ completion manually with ``. set omnifunc=ale#completion#OmniFunc ``` -When working with TypeScript files, ALE supports automatic imports from -external modules. This behavior is disabled by default and can be enabled by -setting: +ALE supports automatic imports from external modules. This behavior is disabled +by default and can be enabled by setting: ```vim -let g:ale_completion_tsserver_autoimport = 1 +let g:ale_completion_autoimport = 1 ``` See `:help ale-completion` for more information. diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim index f5e25cd0..bffcdc8a 100644 --- a/autoload/ale/completion.vim +++ b/autoload/ale/completion.vim @@ -16,7 +16,7 @@ onoremap (ale_show_completion_menu) let g:ale_completion_delay = get(g:, 'ale_completion_delay', 100) let g:ale_completion_excluded_words = get(g:, 'ale_completion_excluded_words', []) let g:ale_completion_max_suggestions = get(g:, 'ale_completion_max_suggestions', 50) -let g:ale_completion_tsserver_autoimport = get(g:, 'ale_completion_tsserver_autoimport', 0) +let g:ale_completion_autoimport = get(g:, 'ale_completion_autoimport', 0) let g:ale_completion_tsserver_remove_warnings = get(g:, 'ale_completion_tsserver_remove_warnings', 0) let s:timer_id = -1 @@ -440,7 +440,7 @@ function! ale#completion#ParseTSServerCompletionEntryDetails(response) abort \ 'kind': ale#completion#GetCompletionSymbols(l:suggestion.kind), \ 'icase': 1, \ 'menu': join(l:displayParts, ''), - \ 'dup': g:ale_completion_tsserver_autoimport, + \ 'dup': g:ale_completion_autoimport, \ 'info': join(l:documentationParts, ''), \} @@ -522,6 +522,12 @@ function! ale#completion#ParseLSPCompletions(response) abort continue endif + " Don't use LSP items with additional text edits when autoimport for + " completions is turned off. + if has_key(l:item, 'additionalTextEdits') && !g:ale_completion_autoimport + continue + endif + let l:doc = get(l:item, 'documentation', '') if type(l:doc) is v:t_dict && has_key(l:doc, 'value') @@ -666,12 +672,16 @@ function! s:OnReady(linter, lsp_details) abort call ale#lsp#RegisterCallback(l:id, l:Callback) if a:linter.lsp is# 'tsserver' + if get(g:, 'ale_completion_tsserver_autoimport') is 1 + execute 'echom `g:ale_completion_tsserver_autoimport` is deprecated. Use `g:ale_completion_autoimport` instead.''' + endif + let l:message = ale#lsp#tsserver_message#Completions( \ l:buffer, \ b:ale_completion_info.line, \ b:ale_completion_info.column, \ b:ale_completion_info.prefix, - \ g:ale_completion_tsserver_autoimport, + \ g:ale_completion_autoimport, \) else " Send a message saying the buffer has changed first, otherwise diff --git a/doc/ale.txt b/doc/ale.txt index 3b90e7e0..ef256752 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -418,11 +418,12 @@ The |ALEComplete| command can be used to show completion suggestions manually, even when |g:ale_completion_enabled| is set to `0`. For manually requesting completion information with Deoplete, consult Deoplete's documentation. -When working with TypeScript files, ALE by can support automatic imports -from external modules. This behavior can be enabled by setting the -|g:ale_completion_tsserver_autoimport| variable to `1`. ALE can also remove -warnings from your completions by setting the -|g:ale_completion_tsserver_remove_warnings| variable to 1. +ALE by can support automatic imports from external modules. This behavior can +be enabled by setting the |g:ale_completion_autoimport| variable to `1`. + +When working with TypeScript files, ALE can remove warnings from your +completions by setting the |g:ale_completion_tsserver_remove_warnings| +variable to 1. *ale-completion-completeopt-bug* @@ -692,7 +693,7 @@ g:ale_completion_tsserver_remove_warnings *g:ale_completion_tsserver_remove_warn including those that are a warning. Warnings can be excluded from completed items by setting it to `1`. -g:ale_completion_tsserver_autoimport *g:ale_completion_tsserver_autoimport* +g:ale_completion_autoimport *g:ale_completion_autoimport* Type: Number Default: `0` diff --git a/test/completion/test_lsp_completion_messages.vader b/test/completion/test_lsp_completion_messages.vader index 4b7392f5..ee810113 100644 --- a/test/completion/test_lsp_completion_messages.vader +++ b/test/completion/test_lsp_completion_messages.vader @@ -121,7 +121,7 @@ Execute(The right message should be sent for the initial tsserver request): \ 'line': 1, \ 'offset': 3, \ 'prefix': 'fo', - \ 'includeExternalModuleExports': g:ale_completion_tsserver_autoimport, + \ 'includeExternalModuleExports': g:ale_completion_autoimport, \ }]], \ g:message_list " We should set up the completion info correctly. diff --git a/test/completion/test_lsp_completion_parsing.vader b/test/completion/test_lsp_completion_parsing.vader index e233c955..8b8b41c7 100644 --- a/test/completion/test_lsp_completion_parsing.vader +++ b/test/completion/test_lsp_completion_parsing.vader @@ -1,4 +1,12 @@ +Before: + Save g:ale_completion_autoimport + Save g:ale_completion_max_suggestions + + let g:ale_completion_max_suggestions = 50 + After: + Restore + unlet! b:ale_completion_info Execute(Should handle Rust completion results correctly): @@ -527,7 +535,9 @@ Execute(Should handle completion messages with the deprecated insertText attribu \ }, \ }) -Execute(Should handle completion messages with additionalTextEdits): +Execute(Should handle completion messages with additionalTextEdits when ale_completion_autoimport is turned on): + let g:ale_completion_autoimport = 1 + AssertEqual \ [ \ { @@ -596,3 +606,42 @@ Execute(Should handle completion messages with additionalTextEdits): \ ], \ }, \ }) + +Execute(Should not handle completion messages with additionalTextEdits when ale_completion_autoimport is turned off): + let g:ale_completion_autoimport = 0 + + AssertEqual + \ [], + \ ale#completion#ParseLSPCompletions({ + \ 'id': 226, + \ 'jsonrpc': '2.0', + \ 'result': { + \ 'isIncomplete': v:false, + \ 'items': [ + \ { + \ 'detail': 'PlayTimeCallback', + \ 'filterText': 'next_callback', + \ 'insertText': 'next_callback', + \ 'insertTextFormat': 1, + \ 'kind': 6, + \ 'label': ' next_callback', + \ 'sortText': '3ee19999next_callback', + \ 'additionalTextEdits': [ + \ { + \ 'range': { + \ 'start': { + \ 'line': 10, + \ 'character': 1, + \ }, + \ 'end': { + \ 'line': 12, + \ 'character': 3, + \ }, + \ }, + \ 'newText': 'from "module" import next_callback', + \ }, + \ ], + \ }, + \ ], + \ }, + \ }) diff --git a/test/completion/test_tsserver_completion_parsing.vader b/test/completion/test_tsserver_completion_parsing.vader index 58b56ce6..4515afd1 100644 --- a/test/completion/test_tsserver_completion_parsing.vader +++ b/test/completion/test_tsserver_completion_parsing.vader @@ -83,7 +83,7 @@ Execute(TypeScript completion details responses should be parsed correctly): \ 'info': '', \ 'kind': 'v', \ 'icase': 1, - \ 'dup': g:ale_completion_tsserver_autoimport, + \ 'dup': g:ale_completion_autoimport, \ }, \ { \ 'word': 'def', @@ -91,7 +91,7 @@ Execute(TypeScript completion details responses should be parsed correctly): \ 'info': 'foo bar baz', \ 'kind': 'v', \ 'icase': 1, - \ 'dup': g:ale_completion_tsserver_autoimport, + \ 'dup': g:ale_completion_autoimport, \ }, \ { \ 'word': 'ghi', @@ -99,7 +99,7 @@ Execute(TypeScript completion details responses should be parsed correctly): \ 'info': '', \ 'kind': 'v', \ 'icase': 1, - \ 'dup': g:ale_completion_tsserver_autoimport, + \ 'dup': g:ale_completion_autoimport, \ }, \ ], \ ale#completion#ParseTSServerCompletionEntryDetails({ @@ -177,7 +177,7 @@ Execute(Entries without details should be included in the responses): \ 'changes': [], \ }], \ }), - \ 'dup': g:ale_completion_tsserver_autoimport, + \ 'dup': g:ale_completion_autoimport, \ }, \ { \ 'word': 'def', @@ -185,7 +185,7 @@ Execute(Entries without details should be included in the responses): \ 'info': 'foo bar baz', \ 'kind': 'v', \ 'icase': 1, - \ 'dup': g:ale_completion_tsserver_autoimport, + \ 'dup': g:ale_completion_autoimport, \ }, \ { \ 'word': 'xyz',