#1162 Get LSP completions working reasonably well
This commit is contained in:
parent
b1a6abdda6
commit
8254e507d6
@ -326,6 +326,14 @@ function! s:GetLSPCompletions(linter) abort
|
||||
\ b:ale_completion_info.prefix,
|
||||
\)
|
||||
else
|
||||
" Send a message saying the buffer has changed first, otherwise
|
||||
" completions won't know what text is nearby.
|
||||
call ale#lsp#Send(
|
||||
\ l:id,
|
||||
\ ale#lsp#message#DidChange(l:buffer),
|
||||
\ l:root
|
||||
\)
|
||||
|
||||
" For LSP completions, we need to clamp the column to the length of
|
||||
" the line. python-language-server and perhaps others do not implement
|
||||
" this correctly.
|
||||
@ -334,9 +342,9 @@ function! s:GetLSPCompletions(linter) abort
|
||||
\ b:ale_completion_info.line,
|
||||
\ min([
|
||||
\ b:ale_completion_info.line_length,
|
||||
\ b:ale_completion_info.column
|
||||
\ b:ale_completion_info.column,
|
||||
\ ]),
|
||||
\ '',
|
||||
\ ale#completion#GetTriggerCharacter(&filetype, b:ale_completion_info.prefix),
|
||||
\)
|
||||
endif
|
||||
|
||||
|
@ -95,7 +95,7 @@ function! ale#lsp#message#Completion(buffer, line, column, trigger_character) ab
|
||||
\ 'textDocument': {
|
||||
\ 'uri': ale#path#ToURI(expand('#' . a:buffer . ':p')),
|
||||
\ },
|
||||
\ 'position': {'line': a:line - 1, 'character': a:column - 1},
|
||||
\ 'position': {'line': a:line - 1, 'character': a:column},
|
||||
\}]
|
||||
|
||||
if !empty(a:trigger_character)
|
||||
|
@ -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': '.'},
|
||||
\ }
|
||||
\ ],
|
||||
|
Loading…
Reference in New Issue
Block a user