mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-16 01:07:06 +08:00
Add ALERename (tsserver & LSP), ALEOrganizeImports (tsserver) and auto import support (tsserver) (#2709)
This commit adds support for renaming symbols in tsserver and with LSP tools, and for organising imports with tsserver. Completion results for symbols that can be imported are now suggested if enabled for tsserver completion done via ALE.
This commit is contained in:
@@ -47,6 +47,14 @@ Before:
|
||||
AssertEqual a:expect_success, g:get_completions_called
|
||||
endfunction
|
||||
|
||||
let g:handle_code_action_called = 0
|
||||
function! MockHandleCodeAction() abort
|
||||
" delfunction! ale#code_action#HandleCodeAction
|
||||
function! ale#code_action#HandleCodeAction(action) abort
|
||||
let g:handle_code_action_called += 1
|
||||
endfunction
|
||||
endfunction
|
||||
|
||||
After:
|
||||
Restore
|
||||
|
||||
@@ -54,6 +62,7 @@ After:
|
||||
unlet! g:output
|
||||
unlet! g:fake_mode
|
||||
unlet! g:get_completions_called
|
||||
unlet! g:handle_code_action_called
|
||||
unlet! b:ale_old_omnifunc
|
||||
unlet! b:ale_old_completeopt
|
||||
unlet! b:ale_completion_info
|
||||
@@ -61,6 +70,8 @@ After:
|
||||
unlet! b:ale_complete_done_time
|
||||
|
||||
delfunction CheckCompletionCalled
|
||||
delfunction ale#code_action#HandleCodeAction
|
||||
delfunction MockHandleCodeAction
|
||||
|
||||
if exists('*CompleteCallback')
|
||||
delfunction CompleteCallback
|
||||
@@ -77,6 +88,7 @@ After:
|
||||
endfunction
|
||||
|
||||
runtime autoload/ale/completion.vim
|
||||
runtime autoload/ale/code_action.vim
|
||||
runtime autoload/ale/util.vim
|
||||
|
||||
Execute(ale#completion#GetCompletions should be called when the cursor position stays the same):
|
||||
@@ -385,3 +397,44 @@ Execute(Running the normal mode <Plug> keybind should reset the settings):
|
||||
AssertEqual 'menu', &l:completeopt
|
||||
Assert !has_key(b:, 'ale_old_omnifunc')
|
||||
Assert !has_key(b:, 'ale_old_completeopt')
|
||||
|
||||
Execute(HandleUserData should call ale#code_action#HandleCodeAction):
|
||||
let b:ale_completion_info = {'source': 'ale-manual'}
|
||||
call MockHandleCodeAction()
|
||||
|
||||
call ale#completion#HandleUserData({})
|
||||
AssertEqual g:handle_code_action_called, 0
|
||||
|
||||
call ale#completion#HandleUserData({
|
||||
\ 'user_data': ''
|
||||
\})
|
||||
AssertEqual g:handle_code_action_called, 0
|
||||
|
||||
call ale#completion#HandleUserData({
|
||||
\ 'user_data': '{}'
|
||||
\})
|
||||
AssertEqual g:handle_code_action_called, 0
|
||||
|
||||
call ale#completion#HandleUserData({
|
||||
\ 'user_data': '{"codeActions": []}'
|
||||
\})
|
||||
AssertEqual g:handle_code_action_called, 0
|
||||
|
||||
call ale#completion#HandleUserData({
|
||||
\ 'user_data': '{"codeActions": [{"description":"", "changes": []}]}'
|
||||
\})
|
||||
AssertEqual g:handle_code_action_called, 1
|
||||
|
||||
let b:ale_completion_info = {'source': 'ale-automatic'}
|
||||
call ale#completion#HandleUserData({
|
||||
\ 'user_data': '{"codeActions": [{"description":"", "changes": []}]}'
|
||||
\})
|
||||
AssertEqual g:handle_code_action_called, 2
|
||||
|
||||
Execute(ale#code_action#HandleCodeAction should not be called when when source is not ALE):
|
||||
call MockHandleCodeAction()
|
||||
let b:ale_completion_info = {'source': 'syntastic'}
|
||||
call ale#completion#HandleUserData({
|
||||
\ 'user_data': '{"codeActions": [{"description":"", "changes": []}]}'
|
||||
\})
|
||||
AssertEqual g:handle_code_action_called, 0
|
||||
|
||||
@@ -116,7 +116,13 @@ Execute(The right message should be sent for the initial tsserver request):
|
||||
\ string(g:Callback)
|
||||
" We should send the right message.
|
||||
AssertEqual
|
||||
\ [[0, 'ts@completions', {'file': expand('%:p'), 'line': 1, 'offset': 3, 'prefix': 'fo'}]],
|
||||
\ [[0, 'ts@completions', {
|
||||
\ 'file': expand('%:p'),
|
||||
\ 'line': 1,
|
||||
\ 'offset': 3,
|
||||
\ 'prefix': 'fo',
|
||||
\ 'includeExternalModuleExports': g:ale_completion_tsserver_autoimport,
|
||||
\ }]],
|
||||
\ g:message_list
|
||||
" We should set up the completion info correctly.
|
||||
AssertEqual
|
||||
@@ -151,7 +157,7 @@ Execute(The right message sent to the tsserver LSP when the first completion mes
|
||||
\ 'body': [
|
||||
\ {'name': 'Baz'},
|
||||
\ {'name': 'dingDong'},
|
||||
\ {'name': 'Foo'},
|
||||
\ {'name': 'Foo', 'source': '/path/to/foo.ts'},
|
||||
\ {'name': 'FooBar'},
|
||||
\ {'name': 'frazzle'},
|
||||
\ {'name': 'FFS'},
|
||||
@@ -160,8 +166,16 @@ Execute(The right message sent to the tsserver LSP when the first completion mes
|
||||
|
||||
" We should save the names we got in the buffer, as TSServer doesn't return
|
||||
" details for every name.
|
||||
AssertEqual
|
||||
\ ['Foo', 'FooBar', 'frazzle'],
|
||||
AssertEqual [{
|
||||
\ 'word': 'Foo',
|
||||
\ 'source': '/path/to/foo.ts',
|
||||
\ }, {
|
||||
\ 'word': 'FooBar',
|
||||
\ 'source': '',
|
||||
\ }, {
|
||||
\ 'word': 'frazzle',
|
||||
\ 'source': '',
|
||||
\}],
|
||||
\ get(b:, 'ale_tsserver_completion_names', [])
|
||||
|
||||
" The entry details messages should have been sent.
|
||||
@@ -171,7 +185,16 @@ Execute(The right message sent to the tsserver LSP when the first completion mes
|
||||
\ 'ts@completionEntryDetails',
|
||||
\ {
|
||||
\ 'file': expand('%:p'),
|
||||
\ 'entryNames': ['Foo', 'FooBar', 'frazzle'],
|
||||
\ 'entryNames': [{
|
||||
\ 'name': 'Foo',
|
||||
\ 'source': '/path/to/foo.ts',
|
||||
\ }, {
|
||||
\ 'name': 'FooBar',
|
||||
\ 'source': '',
|
||||
\ }, {
|
||||
\ 'name': 'frazzle',
|
||||
\ 'source': '',
|
||||
\ }],
|
||||
\ 'offset': 1,
|
||||
\ 'line': 1,
|
||||
\ },
|
||||
|
||||
@@ -6,10 +6,24 @@ Execute(TypeScript completions responses should be parsed correctly):
|
||||
\ ale#completion#ParseTSServerCompletions({
|
||||
\ 'body': [],
|
||||
\})
|
||||
AssertEqual ['foo', 'bar', 'baz'],
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {
|
||||
\ 'word': 'foo',
|
||||
\ 'source': '/path/to/foo.ts',
|
||||
\ },
|
||||
\ {
|
||||
\ 'word': 'bar',
|
||||
\ 'source': '',
|
||||
\ },
|
||||
\ {
|
||||
\ 'word': 'baz',
|
||||
\ 'source': '',
|
||||
\ }
|
||||
\ ],
|
||||
\ ale#completion#ParseTSServerCompletions({
|
||||
\ 'body': [
|
||||
\ {'name': 'foo'},
|
||||
\ {'name': 'foo', 'source': '/path/to/foo.ts'},
|
||||
\ {'name': 'bar'},
|
||||
\ {'name': 'baz'},
|
||||
\ ],
|
||||
@@ -24,6 +38,7 @@ Execute(TypeScript completion details responses should be parsed correctly):
|
||||
\ 'info': '',
|
||||
\ 'kind': 'f',
|
||||
\ 'icase': 1,
|
||||
\ 'dup': g:ale_completion_tsserver_autoimport,
|
||||
\ },
|
||||
\ {
|
||||
\ 'word': 'def',
|
||||
@@ -31,6 +46,7 @@ Execute(TypeScript completion details responses should be parsed correctly):
|
||||
\ 'info': 'foo bar baz',
|
||||
\ 'kind': 'f',
|
||||
\ 'icase': 1,
|
||||
\ 'dup': g:ale_completion_tsserver_autoimport,
|
||||
\ },
|
||||
\ {
|
||||
\ 'word': 'ghi',
|
||||
@@ -38,6 +54,7 @@ Execute(TypeScript completion details responses should be parsed correctly):
|
||||
\ 'info': '',
|
||||
\ 'kind': 'f',
|
||||
\ 'icase': 1,
|
||||
\ 'dup': g:ale_completion_tsserver_autoimport,
|
||||
\ },
|
||||
\ ],
|
||||
\ ale#completion#ParseTSServerCompletionEntryDetails({
|
||||
@@ -96,7 +113,10 @@ Execute(TypeScript completion details responses should be parsed correctly):
|
||||
\})
|
||||
|
||||
Execute(Entries without details should be included in the responses):
|
||||
let b:ale_tsserver_completion_names = ['xyz']
|
||||
let b:ale_tsserver_completion_names = [{
|
||||
\ 'word': 'xyz',
|
||||
\ 'source': '/path/to/xyz.ts',
|
||||
\ }]
|
||||
|
||||
AssertEqual
|
||||
\ [
|
||||
@@ -106,6 +126,13 @@ Execute(Entries without details should be included in the responses):
|
||||
\ 'info': '',
|
||||
\ 'kind': 'f',
|
||||
\ 'icase': 1,
|
||||
\ 'user_data': json_encode({
|
||||
\ 'codeActions': [{
|
||||
\ 'description': 'abc action',
|
||||
\ 'changes': [],
|
||||
\ }],
|
||||
\ }),
|
||||
\ 'dup': g:ale_completion_tsserver_autoimport,
|
||||
\ },
|
||||
\ {
|
||||
\ 'word': 'def',
|
||||
@@ -113,6 +140,7 @@ Execute(Entries without details should be included in the responses):
|
||||
\ 'info': 'foo bar baz',
|
||||
\ 'kind': 'f',
|
||||
\ 'icase': 1,
|
||||
\ 'dup': g:ale_completion_tsserver_autoimport,
|
||||
\ },
|
||||
\ {
|
||||
\ 'word': 'xyz',
|
||||
@@ -139,6 +167,10 @@ Execute(Entries without details should be included in the responses):
|
||||
\ {'text': ' '},
|
||||
\ {'text': 'number'},
|
||||
\ ],
|
||||
\ 'codeActions': [{
|
||||
\ 'description': 'abc action',
|
||||
\ 'changes': [],
|
||||
\ }],
|
||||
\ },
|
||||
\ {
|
||||
\ 'name': 'def',
|
||||
|
||||
Reference in New Issue
Block a user