Close #3267 - Add a general autoimport setting
This commit is contained in:
parent
8bfb5c6407
commit
6d502233d8
6 changed files with 79 additions and 20 deletions
|
@ -193,12 +193,11 @@ completion manually with `<C-x><C-o>`.
|
||||||
set omnifunc=ale#completion#OmniFunc
|
set omnifunc=ale#completion#OmniFunc
|
||||||
```
|
```
|
||||||
|
|
||||||
When working with TypeScript files, ALE supports automatic imports from
|
ALE supports automatic imports from external modules. This behavior is disabled
|
||||||
external modules. This behavior is disabled by default and can be enabled by
|
by default and can be enabled by setting:
|
||||||
setting:
|
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
let g:ale_completion_tsserver_autoimport = 1
|
let g:ale_completion_autoimport = 1
|
||||||
```
|
```
|
||||||
|
|
||||||
See `:help ale-completion` for more information.
|
See `:help ale-completion` for more information.
|
||||||
|
|
|
@ -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_delay = get(g:, 'ale_completion_delay', 100)
|
||||||
let g:ale_completion_excluded_words = get(g:, 'ale_completion_excluded_words', [])
|
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_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 g:ale_completion_tsserver_remove_warnings = get(g:, 'ale_completion_tsserver_remove_warnings', 0)
|
||||||
|
|
||||||
let s:timer_id = -1
|
let s:timer_id = -1
|
||||||
|
@ -440,7 +440,7 @@ function! ale#completion#ParseTSServerCompletionEntryDetails(response) abort
|
||||||
\ 'kind': ale#completion#GetCompletionSymbols(l:suggestion.kind),
|
\ 'kind': ale#completion#GetCompletionSymbols(l:suggestion.kind),
|
||||||
\ 'icase': 1,
|
\ 'icase': 1,
|
||||||
\ 'menu': join(l:displayParts, ''),
|
\ 'menu': join(l:displayParts, ''),
|
||||||
\ 'dup': g:ale_completion_tsserver_autoimport,
|
\ 'dup': g:ale_completion_autoimport,
|
||||||
\ 'info': join(l:documentationParts, ''),
|
\ 'info': join(l:documentationParts, ''),
|
||||||
\}
|
\}
|
||||||
|
|
||||||
|
@ -522,6 +522,12 @@ function! ale#completion#ParseLSPCompletions(response) abort
|
||||||
continue
|
continue
|
||||||
endif
|
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', '')
|
let l:doc = get(l:item, 'documentation', '')
|
||||||
|
|
||||||
if type(l:doc) is v:t_dict && has_key(l:doc, 'value')
|
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)
|
call ale#lsp#RegisterCallback(l:id, l:Callback)
|
||||||
|
|
||||||
if a:linter.lsp is# 'tsserver'
|
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(
|
let l:message = ale#lsp#tsserver_message#Completions(
|
||||||
\ l:buffer,
|
\ l:buffer,
|
||||||
\ b:ale_completion_info.line,
|
\ b:ale_completion_info.line,
|
||||||
\ b:ale_completion_info.column,
|
\ b:ale_completion_info.column,
|
||||||
\ b:ale_completion_info.prefix,
|
\ b:ale_completion_info.prefix,
|
||||||
\ g:ale_completion_tsserver_autoimport,
|
\ g:ale_completion_autoimport,
|
||||||
\)
|
\)
|
||||||
else
|
else
|
||||||
" Send a message saying the buffer has changed first, otherwise
|
" Send a message saying the buffer has changed first, otherwise
|
||||||
|
|
13
doc/ale.txt
13
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
|
even when |g:ale_completion_enabled| is set to `0`. For manually requesting
|
||||||
completion information with Deoplete, consult Deoplete's documentation.
|
completion information with Deoplete, consult Deoplete's documentation.
|
||||||
|
|
||||||
When working with TypeScript files, ALE by can support automatic imports
|
ALE by can support automatic imports from external modules. This behavior can
|
||||||
from external modules. This behavior can be enabled by setting the
|
be enabled by setting the |g:ale_completion_autoimport| variable to `1`.
|
||||||
|g:ale_completion_tsserver_autoimport| variable to `1`. ALE can also remove
|
|
||||||
warnings from your completions by setting the
|
When working with TypeScript files, ALE can remove warnings from your
|
||||||
|g:ale_completion_tsserver_remove_warnings| variable to 1.
|
completions by setting the |g:ale_completion_tsserver_remove_warnings|
|
||||||
|
variable to 1.
|
||||||
|
|
||||||
*ale-completion-completeopt-bug*
|
*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
|
including those that are a warning. Warnings can be excluded from completed
|
||||||
items by setting it to `1`.
|
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
|
Type: Number
|
||||||
Default: `0`
|
Default: `0`
|
||||||
|
|
|
@ -121,7 +121,7 @@ Execute(The right message should be sent for the initial tsserver request):
|
||||||
\ 'line': 1,
|
\ 'line': 1,
|
||||||
\ 'offset': 3,
|
\ 'offset': 3,
|
||||||
\ 'prefix': 'fo',
|
\ 'prefix': 'fo',
|
||||||
\ 'includeExternalModuleExports': g:ale_completion_tsserver_autoimport,
|
\ 'includeExternalModuleExports': g:ale_completion_autoimport,
|
||||||
\ }]],
|
\ }]],
|
||||||
\ g:message_list
|
\ g:message_list
|
||||||
" We should set up the completion info correctly.
|
" We should set up the completion info correctly.
|
||||||
|
|
|
@ -1,4 +1,12 @@
|
||||||
|
Before:
|
||||||
|
Save g:ale_completion_autoimport
|
||||||
|
Save g:ale_completion_max_suggestions
|
||||||
|
|
||||||
|
let g:ale_completion_max_suggestions = 50
|
||||||
|
|
||||||
After:
|
After:
|
||||||
|
Restore
|
||||||
|
|
||||||
unlet! b:ale_completion_info
|
unlet! b:ale_completion_info
|
||||||
|
|
||||||
Execute(Should handle Rust completion results correctly):
|
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
|
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',
|
||||||
|
\ },
|
||||||
|
\ ],
|
||||||
|
\ },
|
||||||
|
\ ],
|
||||||
|
\ },
|
||||||
|
\ })
|
||||||
|
|
|
@ -83,7 +83,7 @@ Execute(TypeScript completion details responses should be parsed correctly):
|
||||||
\ 'info': '',
|
\ 'info': '',
|
||||||
\ 'kind': 'v',
|
\ 'kind': 'v',
|
||||||
\ 'icase': 1,
|
\ 'icase': 1,
|
||||||
\ 'dup': g:ale_completion_tsserver_autoimport,
|
\ 'dup': g:ale_completion_autoimport,
|
||||||
\ },
|
\ },
|
||||||
\ {
|
\ {
|
||||||
\ 'word': 'def',
|
\ 'word': 'def',
|
||||||
|
@ -91,7 +91,7 @@ Execute(TypeScript completion details responses should be parsed correctly):
|
||||||
\ 'info': 'foo bar baz',
|
\ 'info': 'foo bar baz',
|
||||||
\ 'kind': 'v',
|
\ 'kind': 'v',
|
||||||
\ 'icase': 1,
|
\ 'icase': 1,
|
||||||
\ 'dup': g:ale_completion_tsserver_autoimport,
|
\ 'dup': g:ale_completion_autoimport,
|
||||||
\ },
|
\ },
|
||||||
\ {
|
\ {
|
||||||
\ 'word': 'ghi',
|
\ 'word': 'ghi',
|
||||||
|
@ -99,7 +99,7 @@ Execute(TypeScript completion details responses should be parsed correctly):
|
||||||
\ 'info': '',
|
\ 'info': '',
|
||||||
\ 'kind': 'v',
|
\ 'kind': 'v',
|
||||||
\ 'icase': 1,
|
\ 'icase': 1,
|
||||||
\ 'dup': g:ale_completion_tsserver_autoimport,
|
\ 'dup': g:ale_completion_autoimport,
|
||||||
\ },
|
\ },
|
||||||
\ ],
|
\ ],
|
||||||
\ ale#completion#ParseTSServerCompletionEntryDetails({
|
\ ale#completion#ParseTSServerCompletionEntryDetails({
|
||||||
|
@ -177,7 +177,7 @@ Execute(Entries without details should be included in the responses):
|
||||||
\ 'changes': [],
|
\ 'changes': [],
|
||||||
\ }],
|
\ }],
|
||||||
\ }),
|
\ }),
|
||||||
\ 'dup': g:ale_completion_tsserver_autoimport,
|
\ 'dup': g:ale_completion_autoimport,
|
||||||
\ },
|
\ },
|
||||||
\ {
|
\ {
|
||||||
\ 'word': 'def',
|
\ 'word': 'def',
|
||||||
|
@ -185,7 +185,7 @@ Execute(Entries without details should be included in the responses):
|
||||||
\ 'info': 'foo bar baz',
|
\ 'info': 'foo bar baz',
|
||||||
\ 'kind': 'v',
|
\ 'kind': 'v',
|
||||||
\ 'icase': 1,
|
\ 'icase': 1,
|
||||||
\ 'dup': g:ale_completion_tsserver_autoimport,
|
\ 'dup': g:ale_completion_autoimport,
|
||||||
\ },
|
\ },
|
||||||
\ {
|
\ {
|
||||||
\ 'word': 'xyz',
|
\ 'word': 'xyz',
|
||||||
|
|
Reference in a new issue