From 443ba4fad162c51d374b8c0cbb7f7ed27a1d4277 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Mon, 21 Nov 2016 20:34:30 -0500 Subject: [PATCH] Add support for fs/readFile command 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. --- autoload/langserver/callbacks.vim | 10 +++------- autoload/langserver/client.vim | 4 ++++ autoload/langserver/extension/command.vim | 7 +++---- autoload/langserver/extension/fs.vim | 9 ++++++++- autoload/langserver/goto.vim | 10 ++++++++-- autoload/langserver/initialize.vim | 8 +++++++- autoload/langserver/log.vim | 4 +++- 7 files changed, 36 insertions(+), 16 deletions(-) diff --git a/autoload/langserver/callbacks.vim b/autoload/langserver/callbacks.vim index 61911bc..05ccde7 100644 --- a/autoload/langserver/callbacks.vim +++ b/autoload/langserver/callbacks.vim @@ -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 @@ -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...' diff --git a/autoload/langserver/client.vim b/autoload/langserver/client.vim index a6e3371..4ebd774 100644 --- a/autoload/langserver/client.vim +++ b/autoload/langserver/client.vim @@ -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 diff --git a/autoload/langserver/extension/command.vim b/autoload/langserver/extension/command.vim index bed1fe1..6963205 100644 --- a/autoload/langserver/extension/command.vim +++ b/autoload/langserver/extension/command.vim @@ -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 diff --git a/autoload/langserver/extension/fs.vim b/autoload/langserver/extension/fs.vim index adf4ae6..fec21f9 100644 --- a/autoload/langserver/extension/fs.vim +++ b/autoload/langserver/extension/fs.vim @@ -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 diff --git a/autoload/langserver/goto.vim b/autoload/langserver/goto.vim index 78ac311..27dde86 100644 --- a/autoload/langserver/goto.vim +++ b/autoload/langserver/goto.vim @@ -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 diff --git a/autoload/langserver/initialize.vim b/autoload/langserver/initialize.vim index 7e7702b..6104dd4 100644 --- a/autoload/langserver/initialize.vim +++ b/autoload/langserver/initialize.vim @@ -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. @@ -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 diff --git a/autoload/langserver/log.vim b/autoload/langserver/log.vim index 26186e3..a0d0823 100644 --- a/autoload/langserver/log.vim +++ b/autoload/langserver/log.vim @@ -112,7 +112,9 @@ function! langserver#log#callback(id, data, event) abort \ a:id, \ a:event, \ string(a:data) - \)) + \ ), + \ v:false + \ ) endfunction ""