diff options
-rw-r--r-- | autoload/ale/lsp.vim | 15 | ||||
-rw-r--r-- | autoload/ale/lsp/message.vim | 11 | ||||
-rw-r--r-- | autoload/ale/lsp_linter.vim | 3 | ||||
-rw-r--r-- | autoload/ale/util.vim | 4 | ||||
-rw-r--r-- | test/lsp/test_lsp_client_messages.vader | 17 |
5 files changed, 46 insertions, 4 deletions
diff --git a/autoload/ale/lsp.vim b/autoload/ale/lsp.vim index 1f854bc5..510f3e95 100644 --- a/autoload/ale/lsp.vim +++ b/autoload/ale/lsp.vim @@ -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 diff --git a/autoload/ale/lsp/message.vim b/autoload/ale/lsp/message.vim index 38be4da6..b40c4407 100644 --- a/autoload/ale/lsp/message.vim +++ b/autoload/ale/lsp/message.vim @@ -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 diff --git a/autoload/ale/lsp_linter.vim b/autoload/ale/lsp_linter.vim index ad181912..753fb57b 100644 --- a/autoload/ale/lsp_linter.vim +++ b/autoload/ale/lsp_linter.vim @@ -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 diff --git a/autoload/ale/util.vim b/autoload/ale/util.vim index 5b2bfcd7..ec9383ac 100644 --- a/autoload/ale/util.vim +++ b/autoload/ale/util.vim @@ -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 diff --git a/test/lsp/test_lsp_client_messages.vader b/test/lsp/test_lsp_client_messages.vader index 754073ec..4c6b0ffa 100644 --- a/test/lsp/test_lsp_client_messages.vader +++ b/test/lsp/test_lsp_client_messages.vader @@ -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 |