mirror of
https://github.com/dense-analysis/ale.git
synced 2026-01-03 10:03:47 +08:00
#1162 Get LSP completions working reasonably well
This commit is contained in:
@@ -15,7 +15,7 @@ Before:
|
||||
|
||||
runtime autoload/ale/lsp.vim
|
||||
|
||||
let g:message = []
|
||||
let g:message_list = []
|
||||
let g:Callback = ''
|
||||
|
||||
function! ale#linter#StartLSP(buffer, linter, callback) abort
|
||||
@@ -29,13 +29,13 @@ Before:
|
||||
|
||||
" Replace the Send function for LSP, so we can monitor calls to it.
|
||||
function! ale#lsp#Send(conn_id, message, ...) abort
|
||||
let g:message = a:message
|
||||
call add(g:message_list, a:message)
|
||||
endfunction
|
||||
|
||||
After:
|
||||
Restore
|
||||
|
||||
unlet! g:message
|
||||
unlet! g:message_list
|
||||
unlet! g:Callback
|
||||
unlet! b:ale_old_omnifunc
|
||||
unlet! b:ale_old_completopt
|
||||
@@ -75,8 +75,8 @@ 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'}],
|
||||
\ g:message
|
||||
\ [[0, 'ts@completions', {'file': expand('%:p'), 'line': 1, 'offset': 3, 'prefix': 'fo'}]],
|
||||
\ g:message_list
|
||||
" We should set up the completion info correctly.
|
||||
AssertEqual
|
||||
\ {
|
||||
@@ -118,7 +118,7 @@ Execute(The right message sent to the tsserver LSP when the first completion mes
|
||||
|
||||
" The entry details messages should have been sent.
|
||||
AssertEqual
|
||||
\ [
|
||||
\ [[
|
||||
\ 0,
|
||||
\ 'ts@completionEntryDetails',
|
||||
\ {
|
||||
@@ -127,8 +127,8 @@ Execute(The right message sent to the tsserver LSP when the first completion mes
|
||||
\ 'offset': 1,
|
||||
\ 'line': 1,
|
||||
\ },
|
||||
\ ],
|
||||
\ g:message
|
||||
\ ]],
|
||||
\ g:message_list
|
||||
|
||||
Given python(Some Python file):
|
||||
foo
|
||||
@@ -152,12 +152,23 @@ Execute(The right message should be sent for the initial LSP request):
|
||||
" We should send the right message.
|
||||
" The character index needs to be at most the index of the last character on
|
||||
" the line, or integration with pyls will be broken.
|
||||
"
|
||||
" We need to send the message for changing the document first.
|
||||
AssertEqual
|
||||
\ [0, 'textDocument/completion', {
|
||||
\ [
|
||||
\ [1, 'textDocument/didChange', {
|
||||
\ 'textDocument': {
|
||||
\ 'uri': ale#path#ToURI(expand('%:p')),
|
||||
\ 'version': g:ale_lsp_next_version_id - 1,
|
||||
\ },
|
||||
\ 'contentChanges': [{'text': join(getline(1, '$'), "\n") . "\n"}]
|
||||
\ }],
|
||||
\ [0, 'textDocument/completion', {
|
||||
\ 'textDocument': {'uri': ale#path#ToURI(expand('%:p'))},
|
||||
\ 'position': {'line': 0, 'character': 2},
|
||||
\ }],
|
||||
\ g:message
|
||||
\ 'position': {'line': 0, 'character': 3},
|
||||
\ }],
|
||||
\ ],
|
||||
\ g:message_list
|
||||
" We should set up the completion info correctly.
|
||||
AssertEqual
|
||||
\ {
|
||||
|
||||
@@ -110,7 +110,7 @@ Execute(ale#lsp#message#Completion() should return correct messages):
|
||||
\ 'textDocument': {
|
||||
\ 'uri': ale#path#ToURI(g:dir . '/foo/bar.ts'),
|
||||
\ },
|
||||
\ 'position': {'line': 11, 'character': 33},
|
||||
\ 'position': {'line': 11, 'character': 34},
|
||||
\ }
|
||||
\ ],
|
||||
\ ale#lsp#message#Completion(bufnr(''), 12, 34, '')
|
||||
@@ -124,7 +124,7 @@ Execute(ale#lsp#message#Completion() should return correct messages with a trigg
|
||||
\ 'textDocument': {
|
||||
\ 'uri': ale#path#ToURI(g:dir . '/foo/bar.ts'),
|
||||
\ },
|
||||
\ 'position': {'line': 11, 'character': 33},
|
||||
\ 'position': {'line': 11, 'character': 34},
|
||||
\ 'context': {'triggerKind': 2, 'triggerCharacter': '.'},
|
||||
\ }
|
||||
\ ],
|
||||
|
||||
Reference in New Issue
Block a user