Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion autoload/ale/codefix.vim
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function! ale#codefix#HandleLSPResponse(conn_id, response) abort
let l:changes_map = ale#code_action#GetChanges(l:params.edit)

if empty(l:changes_map)
return
return v:true
endif

let l:changes = ale#code_action#BuildChangesList(l:changes_map)
Expand All @@ -256,6 +256,8 @@ function! ale#codefix#HandleLSPResponse(conn_id, response) abort
\ },
\ {}
\)

return v:true
elseif has_key(a:response, 'id')
\&& has_key(s:codefix_map, a:response.id)
let l:data = remove(s:codefix_map, a:response.id)
Expand Down
36 changes: 35 additions & 1 deletion autoload/ale/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,21 @@ function! ale#lsp#HandleMessage(conn_id, message) abort
" responses.
if l:conn.initialized
for l:response in l:response_list
let l:handled = 0

" Call all of the registered handlers with the response.
for l:Callback in l:conn.callback_list
call ale#util#GetFunction(l:Callback)(a:conn_id, l:response)
let l:result = ale#util#GetFunction(l:Callback)(a:conn_id, l:response)

if l:result is v:true
let l:handled = 1
endif
Comment on lines -400 to +406
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplify: if ale#util…

endfor

" If this was a request that no handler processed, send Method Not Found error
if !l:handled && has_key(l:response, 'method') && has_key(l:response, 'id')
call s:SendMethodNotFoundResponse(a:conn_id, l:response.id, l:response.method)
endif
endfor
endif
endfunction
Expand Down Expand Up @@ -676,6 +687,29 @@ function! ale#lsp#StopAll() abort
endfor
endfunction

function! s:SendMethodNotFoundResponse(conn_id, request_id, method) abort
let l:conn = get(s:connections, a:conn_id, {})

if empty(l:conn)
return
endif

let l:error_response = {
\ 'jsonrpc': '2.0',
\ 'id': a:request_id,
\ 'error': {
\ 'code': -32601,
\ 'message': 'Method not found',
\ 'data': 'Unknown method: ' . a:method
\ }
\}

let l:body = json_encode(l:error_response)
let l:data = 'Content-Length: ' . strlen(l:body) . "\r\n\r\n" . l:body

call s:SendMessageData(l:conn, l:data)
endfunction

function! s:SendMessageData(conn, data) abort
if has_key(a:conn, 'job_id')
call ale#job#SendRaw(a:conn.job_id, a:data)
Expand Down
10 changes: 10 additions & 0 deletions autoload/ale/lsp_linter.vim
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ function! ale#lsp_linter#HandleLSPResponse(conn_id, response) abort
let l:diagnostics = a:response.params.diagnostics

call ale#lsp_linter#HandleLSPDiagnostics(a:conn_id, l:uri, l:diagnostics)

return v:true
elseif has_key(s:diagnostic_uri_map, get(a:response, 'id'))
let l:uri = remove(s:diagnostic_uri_map, a:response.id)
let l:diagnostics = a:response.result.kind is# 'unchanged'
Expand All @@ -247,16 +249,24 @@ function! ale#lsp_linter#HandleLSPResponse(conn_id, response) abort
\ g:ale_lsp_show_message_format,
\ a:response.params
\)

return v:true
elseif get(a:response, 'type', '') is# 'event'
\&& get(a:response, 'event', '') is# 'semanticDiag'
call s:HandleTSServerDiagnostics(a:response, 'semantic')

return v:true
elseif get(a:response, 'type', '') is# 'event'
\&& get(a:response, 'event', '') is# 'syntaxDiag'
call s:HandleTSServerDiagnostics(a:response, 'syntax')

return v:true
elseif get(a:response, 'type', '') is# 'event'
\&& get(a:response, 'event', '') is# 'suggestionDiag'
\&& get(g:, 'ale_lsp_suggestions')
call s:HandleTSServerDiagnostics(a:response, 'suggestion')

return v:true
endif
endfunction

Expand Down