summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/ale/completion.vim18
-rw-r--r--test/completion/test_tsserver_completion_parsing.vader58
2 files changed, 75 insertions, 1 deletions
diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim
index bffcdc8a..a273d4e1 100644
--- a/autoload/ale/completion.vim
+++ b/autoload/ale/completion.vim
@@ -418,12 +418,22 @@ function! ale#completion#ParseTSServerCompletionEntryDetails(response) abort
for l:suggestion in a:response.body
let l:displayParts = []
+ let l:local_name = v:null
for l:action in get(l:suggestion, 'codeActions', [])
call add(l:displayParts, l:action.description . ' ')
endfor
for l:part in l:suggestion.displayParts
+ " Stop on stop on line breaks for the menu.
+ if get(l:part, 'kind') is# 'lineBreak'
+ break
+ endif
+
+ if get(l:part, 'kind') is# 'localName'
+ let l:local_name = l:part.text
+ endif
+
call add(l:displayParts, l:part.text)
endfor
@@ -436,7 +446,13 @@ function! ale#completion#ParseTSServerCompletionEntryDetails(response) abort
" See :help complete-items
let l:result = {
- \ 'word': l:suggestion.name,
+ \ 'word': (
+ \ l:suggestion.name is# 'default'
+ \ && l:suggestion.kind is# 'alias'
+ \ && !empty(l:local_name)
+ \ ? l:local_name
+ \ : l:suggestion.name
+ \ ),
\ 'kind': ale#completion#GetCompletionSymbols(l:suggestion.kind),
\ 'icase': 1,
\ 'menu': join(l:displayParts, ''),
diff --git a/test/completion/test_tsserver_completion_parsing.vader b/test/completion/test_tsserver_completion_parsing.vader
index 4515afd1..aaaaae95 100644
--- a/test/completion/test_tsserver_completion_parsing.vader
+++ b/test/completion/test_tsserver_completion_parsing.vader
@@ -1,4 +1,11 @@
+Before:
+ Save g:ale_completion_tsserver_remove_warnings
+
+ let g:ale_completion_tsserver_remove_warnings = 0
+
After:
+ Restore
+
unlet! b:ale_tsserver_completion_names
Execute(TypeScript completions responses should be parsed correctly):
@@ -242,3 +249,54 @@ Execute(Entries without details should be included in the responses):
\ },
\ ],
\})
+
+Execute(Default imports should be handled correctly):
+ AssertEqual
+ \ [
+ \ {
+ \ 'word': 'abcd',
+ \ 'menu': 'Import default ''abcd'' from module "./foo" (alias) const abcd: 3',
+ \ 'info': '',
+ \ 'kind': 't',
+ \ 'icase': 1,
+ \ 'user_data': json_encode({
+ \ 'codeActions': [{
+ \ 'description': 'Import default ''abcd'' from module "./foo"',
+ \ 'changes': [],
+ \ }],
+ \ }),
+ \ 'dup': g:ale_completion_autoimport,
+ \ },
+ \ ],
+ \ ale#completion#ParseTSServerCompletionEntryDetails({
+ \ 'body': [
+ \ {
+ \ 'name': 'default',
+ \ 'kind': 'alias',
+ \ 'displayParts': [
+ \ {'kind': 'punctuation', 'text': '('},
+ \ {'kind': 'text', 'text': 'alias'},
+ \ {'kind': 'punctuation', 'text': ')'},
+ \ {'kind': 'space', 'text': ' '},
+ \ {'kind': 'keyword', 'text': 'const'},
+ \ {'kind': 'space', 'text': ' '},
+ \ {'kind': 'localName', 'text': 'abcd'},
+ \ {'kind': 'punctuation', 'text': ':'},
+ \ {'kind': 'space', 'text': ' '},
+ \ {'kind': 'stringLiteral', 'text': '3'},
+ \ {'kind': 'lineBreak', 'text': '^@'},
+ \ {'kind': 'keyword', 'text': 'export'},
+ \ {'kind': 'space', 'text': ' '},
+ \ {'kind': 'keyword', 'text': 'default'},
+ \ {'kind': 'space', 'text': ' '},
+ \ {'kind': 'aliasName', 'text': 'abcd'}
+ \ ],
+ \ 'codeActions': [
+ \ {
+ \ 'description': 'Import default ''abcd'' from module "./foo"',
+ \ 'changes': [],
+ \ },
+ \ ],
+ \ },
+ \ ],
+ \ })