Close #3267 - Add a general autoimport setting

This commit is contained in:
w0rp 2020-08-09 02:28:47 +01:00
parent 8bfb5c6407
commit 6d502233d8
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
6 changed files with 79 additions and 20 deletions

View File

@ -193,12 +193,11 @@ completion manually with `<C-x><C-o>`.
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.

View File

@ -16,7 +16,7 @@ onoremap <silent> <Plug>(ale_show_completion_menu) <Nop>
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

View File

@ -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`

View File

@ -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.

View File

@ -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',
\ },
\ ],
\ },
\ ],
\ },
\ })

View File

@ -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',