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

Commit

Permalink
Start adding symbol requests
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdevries committed Nov 17, 2016
1 parent f090ac2 commit ceb48c6
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 14 deletions.
19 changes: 19 additions & 0 deletions autoload/langserver/callbacks.vim
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ 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 ==? 'workspace/symbol'
call langserver#symbol#workspace#callback(a:id, a:data, a:event)
else
call langserver#log#log('warning', 'LAST REQUEST: ' . l:last_topic, v:true)
endif
Expand All @@ -58,3 +60,20 @@ function! langserver#callbacks#on_notification(id, data, event) abort
endif
endif
endfunction

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

if type(a:data) != type({})
return ''
endif

if has_key(a:data, 'response')
let l:parsed_data = a:data['response']['result']
else
return ''
endif

let g:last_response = l:parsed_data
return l:parsed_data
endfunction
18 changes: 4 additions & 14 deletions autoload/langserver/hover.vim
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
function! langserver#hover#callback(id, data, event) abort
call langserver#log#callback(a:id, a:data, a:event)

if type(a:data) != type({})
return
endif

if has_key(a:data, 'response')
let l:parsed_data = a:data['response']['result']
else
let l:parsed_data = langserver#callbacks#data(a:id, a:data, a:event)
if l:parsed_data == {}
return
endif

let g:last_response = l:parsed_data


" {'data': {'textDocument/hover': {'range': {'end': {'character': 20, 'line': 44}, 'start': {'character': 9, 'line': 44}}, 'contents': [{'language': 'go', 'value': 'type LangHandler struct'}, {'language': 'markdown', 'value': 'LangHandler is a Go language server LSP/JSON-RPC handler.'}]}}, 'type': 'result'}
let l:range = a:data['response']['result']['range']
let l:data = a:data['response']['result']['contents']
let l:range = l:parsed_data['range']
let l:data = l:parsed_data['contents']

call langserver#hover#display(l:range, l:data)
endfunction
Expand Down
44 changes: 44 additions & 0 deletions autoload/langserver/symbol/util.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
let s:symbol_kind: {
\ 'name': {
\ 'File': 1,
\ 'Module': 2,
\ 'Namespace': 3,
\ 'Package': 4,
\ 'Class': 5,
\ 'Method': 6,
\ 'Property': 7,
\ 'Field': 8,
\ 'Constructor': 9,
\ 'Enum': 10,
\ 'Interface': 11,
\ 'Function': 12,
\ 'Variable': 13,
\ 'Constant': 14,
\ 'String': 15,
\ 'Number': 16,
\ 'Boolean': 17,
\ 'Array': 18,
\ }
\ 'number': {
\ 1: 'File',
\ 2: 'Module',
\ 3: 'Namespace',
\ 4: 'Package',
\ 5: 'Class',
\ 6: 'Method',
\ 7: 'Property',
\ 8: 'Field',
\ 9: 'Constructor',
\ 10: 'Enum',
\ 11: 'Interface',
\ 12: 'Function',
\ 13: 'Variable',
\ 14: 'Constant',
\ 15: 'String',
\ 16: 'Number',
\ 17: 'Boolean',
\ 18: 'Array',
\ }
\}


23 changes: 23 additions & 0 deletions autoload/langserver/symbol/workspace.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
let s:method = 'workspace/symbol'

function! langserver#symbol#workspace#callback(id, data, event) abort
let l:parsed_data = langserver#callbacks#data(a:id, a:data, a:event)
if type(l:parsed_data) == type('') && l:parsed_data ==? ''
return
endif

call langserver#log#log('info', a:data, v:true)
endfunction

function!langserver#symbol#workspace#request(...) abort
if a:0 > 0
let l:query = a:1
else
let l:query = expand('<cword>')
endif

return langserver#client#send(langserver#util#get_lsp_id(), {
\ 'method': s:method,
\ 'params': {'query': l:query}
\ })
endfunction

0 comments on commit ceb48c6

Please sign in to comment.