diff --git a/autoload/ale/codefix.vim b/autoload/ale/codefix.vim index 6eaadb2372..9cce5efc04 100644 --- a/autoload/ale/codefix.vim +++ b/autoload/ale/codefix.vim @@ -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) @@ -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) diff --git a/autoload/ale/lsp.vim b/autoload/ale/lsp.vim index 07b073f891..4be4d28e05 100644 --- a/autoload/ale/lsp.vim +++ b/autoload/ale/lsp.vim @@ -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 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 @@ -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) diff --git a/autoload/ale/lsp_linter.vim b/autoload/ale/lsp_linter.vim index 3b3c403c66..55ee99a43f 100644 --- a/autoload/ale/lsp_linter.vim +++ b/autoload/ale/lsp_linter.vim @@ -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' @@ -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