forked from github-mirrors/ale
Implement textDocument/didSave includeText optional argument (#3925)
This commit is contained in:
parent
34a972f85d
commit
42a6e039cb
|
@ -45,6 +45,7 @@ function! ale#lsp#Register(executable_or_address, project, init_options) abort
|
|||
\ 'typeDefinition': 0,
|
||||
\ 'symbol_search': 0,
|
||||
\ 'code_actions': 0,
|
||||
\ 'includeText': 0,
|
||||
\ },
|
||||
\}
|
||||
endif
|
||||
|
@ -263,6 +264,20 @@ function! s:UpdateCapabilities(conn, capabilities) abort
|
|||
if type(get(a:capabilities, 'workspaceSymbolProvider')) is v:t_dict
|
||||
let a:conn.capabilities.symbol_search = 1
|
||||
endif
|
||||
|
||||
if has_key(a:capabilities, 'textDocumentSync')
|
||||
if type(a:capabilities.textDocumentSync) is v:t_dict
|
||||
let l:save = get(a:capabilities.textDocumentSync, 'save', v:false)
|
||||
|
||||
if type(l:save) is v:true
|
||||
let a:conn.capabilities.includeText = 1
|
||||
endif
|
||||
|
||||
if type(l:save) is v:t_dict && get(a:capabilities.textDocumentSync.save, 'includeText', v:false) is v:true
|
||||
let a:conn.capabilities.includeText = 1
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Update a connection's configuration dictionary and notify LSP servers
|
||||
|
|
|
@ -77,12 +77,19 @@ function! ale#lsp#message#DidChange(buffer) abort
|
|||
\}]
|
||||
endfunction
|
||||
|
||||
function! ale#lsp#message#DidSave(buffer) abort
|
||||
return [1, 'textDocument/didSave', {
|
||||
function! ale#lsp#message#DidSave(buffer, includeText) abort
|
||||
let l:response = [1, 'textDocument/didSave', {
|
||||
\ 'textDocument': {
|
||||
\ 'uri': ale#path#ToURI(expand('#' . a:buffer . ':p')),
|
||||
\ },
|
||||
\}]
|
||||
|
||||
if a:includeText
|
||||
let l:response[2].textDocument.version = ale#lsp#message#GetNextVersionID()
|
||||
let l:response[2].text = ale#util#GetBufferContents(a:buffer)
|
||||
endif
|
||||
|
||||
return l:response
|
||||
endfunction
|
||||
|
||||
function! ale#lsp#message#DidClose(buffer) abort
|
||||
|
|
|
@ -466,7 +466,8 @@ function! s:CheckWithLSP(linter, details) abort
|
|||
" If this was a file save event, also notify the server of that.
|
||||
if a:linter.lsp isnot# 'tsserver'
|
||||
\&& getbufvar(l:buffer, 'ale_save_event_fired', 0)
|
||||
let l:save_message = ale#lsp#message#DidSave(l:buffer)
|
||||
let l:include_text = ale#lsp#HasCapability(l:buffer, 'includeText')
|
||||
let l:save_message = ale#lsp#message#DidSave(l:buffer, l:include_text)
|
||||
let l:notified = ale#lsp#Send(l:id, l:save_message) != 0
|
||||
endif
|
||||
endfunction
|
||||
|
|
|
@ -535,3 +535,7 @@ function! ale#util#SetBufferContents(buffer, lines) abort
|
|||
|
||||
return l:new_lines
|
||||
endfunction
|
||||
|
||||
function! ale#util#GetBufferContents(buffer) abort
|
||||
return join(getbufline(a:buffer, 1, '$'), '\n') . '\n'
|
||||
endfunction
|
||||
|
|
|
@ -88,7 +88,22 @@ Execute(ale#lsp#message#DidSave() should return correct messages):
|
|||
\ },
|
||||
\ }
|
||||
\ ],
|
||||
\ ale#lsp#message#DidSave(bufnr(''))
|
||||
\ ale#lsp#message#DidSave(bufnr(''), v:false)
|
||||
|
||||
Execute(ale#lsp#message#DidSave() should return correct message with includeText capability):
|
||||
AssertEqual
|
||||
\ [
|
||||
\ 1,
|
||||
\ 'textDocument/didSave',
|
||||
\ {
|
||||
\ 'textDocument': {
|
||||
\ 'uri': ale#path#ToURI(g:dir . '/foo/bar.ts'),
|
||||
\ 'version': 1,
|
||||
\ },
|
||||
\ 'text': ale#util#GetBufferContents(bufnr('')),
|
||||
\ }
|
||||
\ ],
|
||||
\ ale#lsp#message#DidSave(bufnr(''), v:true)
|
||||
|
||||
Execute(ale#lsp#message#DidClose() should return correct messages):
|
||||
AssertEqual
|
||||
|
|
Loading…
Reference in New Issue