Skip to content
This repository has been archived by the owner on Mar 25, 2020. It is now read-only.

Commit

Permalink
Some work for preconfigured servers
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdevries committed Jan 18, 2017
1 parent 0db17a8 commit c05ad5c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
12 changes: 11 additions & 1 deletion autoload/langserver/client.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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)
\ ))
Expand Down
28 changes: 21 additions & 7 deletions preconfigured/freebroccolo/ocaml-language-server/callbacks.vim
Original file line number Diff line number Diff line change
@@ -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('<cword>'),
\ 'response': {
\ 'result': expand('<cword>'),
\ },
\ })
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

0 comments on commit c05ad5c

Please sign in to comment.