Fix 3207 - do not send didSave notification if not supported (#3930)

This commit is contained in:
Horacio Sanson 2021-10-15 08:42:07 +09:00 committed by GitHub
parent 7413dfd3fc
commit c7e3f1a0dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 7 deletions

View File

@ -45,6 +45,7 @@ function! ale#lsp#Register(executable_or_address, project, init_options) abort
\ 'typeDefinition': 0,
\ 'symbol_search': 0,
\ 'code_actions': 0,
\ 'did_save': 0,
\ 'includeText': 0,
\ },
\}
@ -265,15 +266,19 @@ function! s:UpdateCapabilities(conn, capabilities) abort
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(get(a:capabilities, 'textDocumentSync')) is v:t_dict
let l:syncOptions = get(a:capabilities, 'textDocumentSync')
if type(l:save) is v:true
let a:conn.capabilities.includeText = 1
endif
if get(l:syncOptions, 'save') is v:true
let a:conn.capabilities.did_save = 1
endif
if type(l:save) is v:t_dict && get(a:capabilities.textDocumentSync.save, 'includeText', v:false) is v:true
if type(get(l:syncOptions, 'save')) is v:t_dict
let a:conn.capabilities.did_save = 1
let l:saveOptions = get(l:syncOptions, 'save')
if get(l:saveOptions, 'includeText') is v:true
let a:conn.capabilities.includeText = 1
endif
endif

View File

@ -466,6 +466,7 @@ 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)
\&& ale#lsp#HasCapability(l:buffer, 'did_save')
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

View File

@ -90,6 +90,30 @@ Given foobar (Some imaginary filetype):
Execute(Server should be notified on save):
call ale#events#SaveEvent(bufnr(''))
AssertEqual
\ [
\ [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"}],
\ }],
\ ],
\ g:message_list
Execute(Server should be notified on save with didSave is supported by server):
" Replace has capability function to simulate didSave server capability
function! ale#lsp#HasCapability(conn_id, capability) abort
if a:capability == 'did_save'
return 1
endif
return 0
endfunction
call ale#events#SaveEvent(bufnr(''))
AssertEqual
\ [
\ [1, 'textDocument/didChange', {