diff --git a/autoload/langserver/client.vim b/autoload/langserver/client.vim index 2e64e54..020401d 100644 --- a/autoload/langserver/client.vim +++ b/autoload/langserver/client.vim @@ -144,6 +144,7 @@ endfunction function! s:lsp_send_request(id, opts) abort " opts = { method, params?, on_notification } if has_key(s:lsp_clients, a:id) let l:client = s:lsp_clients[a:id] + let l:type_of_msg = 'Request' if has_key(a:opts, 'req_id') let l:req_seq = a:opts.req_id @@ -157,10 +158,18 @@ function! s:lsp_send_request(id, opts) abort " opts = { method, params?, on_noti let l:msg.params = a:opts.params endif + " I don't think you should be able to do these at the same time... + " Not going to do anything about that yet though if has_key(a:opts, 'result') + let l:type_of_msg = 'Response (result)' let l:msg.result = a:opts.result endif + if has_key (a:opts, 'response') + let l:type_of_msg = 'Reponse (response)' + let l:msg.response = a:opts.response + endif + let l:json = json_encode(l:msg) let l:req_data = 'Content-Length: ' . len(l:json) . "\r\n\r\n" . l:json @@ -173,7 +182,8 @@ function! s:lsp_send_request(id, opts) abort " opts = { method, params?, on_noti let l:client.opts.on_stderr = a:opts.on_stderr endif - call langserver#log#log('debug', printf('Sending request: %s, %s', + call langserver#log#log('debug', printf('Sending %s: %s, %s', + \ l:type_of_msg, \ a:id, \ string(l:msg) \ )) diff --git a/preconfigured/freebroccolo/ocaml-language-server/callbacks.vim b/preconfigured/freebroccolo/ocaml-language-server/callbacks.vim index 4ff7196..9507903 100644 --- a/preconfigured/freebroccolo/ocaml-language-server/callbacks.vim +++ b/preconfigured/freebroccolo/ocaml-language-server/callbacks.vim @@ -1,20 +1,34 @@ -function! s:give_word_at_position(context) abort +function! s:give_word_at_position(id, data, event) abort + call langserver#log#server_request(a:id, a:data, a:event) " 'params': " {'uri': 'file:///home/tj/Downloads/example-ocaml-merlin/src/main.ml', " 'position': {'character': 9, 'line': 6} " } - if !has_key(a:context, 'uri') || !has_key(a:context, 'position') - " TODO: Log an error? + if !has_key(a:data.request.params, 'uri') || !has_key(a:data.request.params, 'position') + call langserver#log#log('error', 'Unable to handle callback for: ' . string(a:data), v:true) return endif - let l:loc_bufnr = bufnr(langserver#util#get_filename(langserver#util#get_lsp_id(), a:context.uri)) - let l:loc_line = langserver#util#get_line(l:loc_bufnr, a:context.uri, a.position.line - 1) + if v:false + let l:loc_bufnr = bufnr(langserver#util#get_filename(langserver#util#get_lsp_id(), a:data.request.params.uri)) + let l:loc_line = langserver#util#get_line(l:loc_bufnr, a:data.request.params.uri, a:data.request.params.position.line - 1) + endif - call langserver#log#log('error', 'LOC LINE: ' . l:loc_line, v:true) + call langserver#client#send(a:id, { + \ 'req_id': a:data.request.id, + \ 'method': a:data.request.method, + \ 'request': a:data.request, + \ 'result': expand(''), + \ 'response': { + \ 'result': expand(''), + \ }, + \ }) + return v:true endfunction -let s:register_callbacks = { +function! Preconfigured_freebroccolo_ocaml_language_server() abort + return { \ 'reason.client.giveWordAtPosition': function('s:give_word_at_position'), \ } +endfunction