mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-06 20:54:26 +08:00
Implement textDocument/didSave includeText optional argument (#3925)
This commit is contained in:
committed by
GitHub
parent
34a972f85d
commit
42a6e039cb
@@ -45,6 +45,7 @@ function! ale#lsp#Register(executable_or_address, project, init_options) abort
|
|||||||
\ 'typeDefinition': 0,
|
\ 'typeDefinition': 0,
|
||||||
\ 'symbol_search': 0,
|
\ 'symbol_search': 0,
|
||||||
\ 'code_actions': 0,
|
\ 'code_actions': 0,
|
||||||
|
\ 'includeText': 0,
|
||||||
\ },
|
\ },
|
||||||
\}
|
\}
|
||||||
endif
|
endif
|
||||||
@@ -263,6 +264,20 @@ function! s:UpdateCapabilities(conn, capabilities) abort
|
|||||||
if type(get(a:capabilities, 'workspaceSymbolProvider')) is v:t_dict
|
if type(get(a:capabilities, 'workspaceSymbolProvider')) is v:t_dict
|
||||||
let a:conn.capabilities.symbol_search = 1
|
let a:conn.capabilities.symbol_search = 1
|
||||||
endif
|
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
|
endfunction
|
||||||
|
|
||||||
" Update a connection's configuration dictionary and notify LSP servers
|
" Update a connection's configuration dictionary and notify LSP servers
|
||||||
|
|||||||
@@ -77,12 +77,19 @@ function! ale#lsp#message#DidChange(buffer) abort
|
|||||||
\}]
|
\}]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#lsp#message#DidSave(buffer) abort
|
function! ale#lsp#message#DidSave(buffer, includeText) abort
|
||||||
return [1, 'textDocument/didSave', {
|
let l:response = [1, 'textDocument/didSave', {
|
||||||
\ 'textDocument': {
|
\ 'textDocument': {
|
||||||
\ 'uri': ale#path#ToURI(expand('#' . a:buffer . ':p')),
|
\ '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
|
endfunction
|
||||||
|
|
||||||
function! ale#lsp#message#DidClose(buffer) abort
|
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 this was a file save event, also notify the server of that.
|
||||||
if a:linter.lsp isnot# 'tsserver'
|
if a:linter.lsp isnot# 'tsserver'
|
||||||
\&& getbufvar(l:buffer, 'ale_save_event_fired', 0)
|
\&& 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
|
let l:notified = ale#lsp#Send(l:id, l:save_message) != 0
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
@@ -535,3 +535,7 @@ function! ale#util#SetBufferContents(buffer, lines) abort
|
|||||||
|
|
||||||
return l:new_lines
|
return l:new_lines
|
||||||
endfunction
|
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):
|
Execute(ale#lsp#message#DidClose() should return correct messages):
|
||||||
AssertEqual
|
AssertEqual
|
||||||
|
|||||||
Reference in New Issue
Block a user