Merge pull request #2849 from DonnieWest/excludeTsserverWarnings

Allow the user to remove warnings from completions
This commit is contained in:
w0rp
2020-08-09 01:32:27 +01:00
committed by GitHub
3 changed files with 65 additions and 5 deletions

View File

@@ -17,6 +17,7 @@ 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_tsserver_autoimport = get(g:, 'ale_completion_tsserver_autoimport', 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
let s:last_done_pos = [] let s:last_done_pos = []
@@ -397,10 +398,14 @@ function! ale#completion#ParseTSServerCompletions(response) abort
let l:names = [] let l:names = []
for l:suggestion in a:response.body for l:suggestion in a:response.body
let l:kind = get(l:suggestion, 'kind', '')
if g:ale_completion_tsserver_remove_warnings == 0 || l:kind isnot# 'warning'
call add(l:names, { call add(l:names, {
\ 'word': l:suggestion.name, \ 'word': l:suggestion.name,
\ 'source': get(l:suggestion, 'source', ''), \ 'source': get(l:suggestion, 'source', ''),
\}) \})
endif
endfor endfor
return l:names return l:names

View File

@@ -420,7 +420,9 @@ completion information with Deoplete, consult Deoplete's documentation.
When working with TypeScript files, ALE by can support automatic imports When working with TypeScript files, ALE by can support automatic imports
from external modules. This behavior can be enabled by setting the from external modules. This behavior can be enabled by setting the
|g:ale_completion_tsserver_autoimport| variable to `1`. |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-completion-completeopt-bug* *ale-completion-completeopt-bug*
@@ -681,6 +683,14 @@ g:ale_completion_enabled *g:ale_completion_enabled*
See |ale-completion| See |ale-completion|
g:ale_completion_tsserver_remove_warnings *g:ale_completion_tsserver_remove_warnings*
Type: Number
Default: `0`
When this option is set to `0`, ALE will return all completion items,
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_tsserver_autoimport *g:ale_completion_tsserver_autoimport*

View File

@@ -29,6 +29,51 @@ Execute(TypeScript completions responses should be parsed correctly):
\ ], \ ],
\}) \})
Execute(TypeScript completions responses should include warnings):
AssertEqual
\ [
\ {
\ 'word': 'foo',
\ 'source': '/path/to/foo.ts',
\ },
\ {
\ 'word': 'bar',
\ 'source': '',
\ },
\ {
\ 'word': 'baz',
\ 'source': '',
\ }
\ ],
\ ale#completion#ParseTSServerCompletions({
\ 'body': [
\ {'name': 'foo', 'source': '/path/to/foo.ts'},
\ {'name': 'bar', 'kind': 'warning'},
\ {'name': 'baz'},
\ ],
\})
Execute(TypeScript completions responses should not include warnings if excluded):
let g:ale_completion_tsserver_remove_warnings = 1
AssertEqual
\ [
\ {
\ 'word': 'foo',
\ 'source': '/path/to/foo.ts',
\ },
\ {
\ 'word': 'baz',
\ 'source': '',
\ }
\ ],
\ ale#completion#ParseTSServerCompletions({
\ 'body': [
\ {'name': 'foo', 'source': '/path/to/foo.ts'},
\ {'name': 'bar', 'kind': 'warning'},
\ {'name': 'baz'},
\ ],
\})
Execute(TypeScript completion details responses should be parsed correctly): Execute(TypeScript completion details responses should be parsed correctly):
AssertEqual AssertEqual
\ [ \ [