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

Commit

Permalink
Add support for fs/readFile command
Browse files Browse the repository at this point in the history
It seems to be working. I'm able to get readings for hover. I'm still
having some difficulty with some of the Goto definition items, but at
least it seems that I can read things and send the base64 encoding to
the server.
  • Loading branch information
tjdevries committed Nov 22, 2016
1 parent 4852108 commit 443ba4f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 16 deletions.
10 changes: 3 additions & 7 deletions autoload/langserver/callbacks.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ endfunction

function! langserver#callbacks#on_stderr(id, data, event) abort
call langserver#log#response(a:id, a:data, a:event)

echom string(a:data)
endfunction

function! langserver#callbacks#on_exit(id, status, event) abort
Expand All @@ -29,14 +27,12 @@ function! langserver#callbacks#on_notification(id, data, event) abort
call langserver#hover#callback(a:id, a:data, a:event)
elseif l:last_topic ==? 'textDocument/didOpen'
call langserver#documents#callback_did_open(a:id, a:data, a:event)
elseif l:last_topic ==? 'initialize'
call langserver#initialize#callback(a:id, a:data, a:event)
elseif l:last_topic ==? 'workspace/symbol'
call langserver#symbol#workspace#callback(a:id, a:data, a:event)
else
" if langserver#extension#command#callback(a:id, a:data, a:event)
" call langserver#log#log('debug', 'Handled: ' . l:last_topic)
" else
call langserver#log#log('warning', 'LAST REQUEST: ' . l:last_topic, v:true)
" endif
call langserver#log#log('warning', 'No callback registered for: ' . l:last_topic, v:true)
endif
elseif has_key(a:data, 'request')
echom 'notification...'
Expand Down
4 changes: 4 additions & 0 deletions autoload/langserver/client.vim
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ function! s:lsp_send_request(id, opts) abort " opts = { method, params?, on_noti
let l:msg.params = a:opts.params
endif

if has_key(a:opts, 'result')
let l:msg.result = a:opts.result
endif

let l:json = json_encode(l:msg)
let l:req_data = 'Content-Length: ' . len(l:json) . "\r\n\r\n" . l:json

Expand Down
7 changes: 3 additions & 4 deletions autoload/langserver/extension/command.vim
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ function! langserver#extension#command#callback(id, data, event) abort

call langserver#client#send(a:id, {
\ 'req_id': a:data.request.id,
\ 'method': 'fs/readFile',
\ 'params': {
\ 'result': l:response,
\ },
\ 'method': l:method,
\ 'params': a:data.request.params,
\ 'result': l:response,
\ })
return v:true
endfunction
9 changes: 8 additions & 1 deletion autoload/langserver/extension/fs.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,12 @@
function! langserver#extension#fs#readFille(filename) abort
echom a:filename

return join(readfile(a:filename), "\n")
" let l:text = join(readfile(a:filename), "\n")
" echo system(['base64', join(readfile('/home/tj/test/lsp.py'), "\n")])
if filereadable(a:filename)
return system(['base64', a:filename])
else
call langserver#log#log('error', 'Unable to read file: ' . a:filename)
return ''
endif
endfunction
10 changes: 8 additions & 2 deletions autoload/langserver/goto.vim
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ function! langserver#goto#callback(id, data, event) abort
if has_key(a:data, 'response')
if type(a:data['response']['result']) == type([])
let l:parsed_data = a:data['response']['result'][0]
else
let l:parsed_data = a:data['response']['result']
elseif type(a:data['response']['result']) == type({})
" Check if we have an empty dictionary
if empty(a:data['response']['result'])
call langserver#log#log('warning', 'No definition found for: ' . string(a:data['request']), v:true)
return
else
let l:parsed_data = a:data['response']['result']
endif
endif
else
return
Expand Down
8 changes: 7 additions & 1 deletion autoload/langserver/initialize.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ function! langserver#initialize#get_client_capabilities() abort
return {}
endfunction

function! langserver#initialize#callback(id, data, event) abort
call langserver#initialize#response(a:id, a:data.response.result)

call langserver#log#log('info', 'Succesfully connected to: ' . string(a:id), v:true)
endfunction

""
" Handle the response of the server.
" This message details the capabilities of the language server.
Expand All @@ -47,7 +53,7 @@ function! langserver#initialize#response(name, response) abort

if has_key(a:response, 'completionProvider')
let l:complete_opt_resolve = get(a:response['completionProvider'], 'resolveProvider', v:false)
let l:complete_opt_trigger = get(a:resposne['completionProvider'], 'triggerCharacters', [])
let l:complete_opt_trigger = get(a:response['completionProvider'], 'triggerCharacters', [])
call langserver#capabilities#set_completion_provider(a:name, l:complete_opt_resolve, l:complete_opt_trigger)
endif

Expand Down
4 changes: 3 additions & 1 deletion autoload/langserver/log.vim
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ function! langserver#log#callback(id, data, event) abort
\ a:id,
\ a:event,
\ string(a:data)
\))
\ ),
\ v:false
\ )
endfunction

""
Expand Down

0 comments on commit 443ba4f

Please sign in to comment.