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

Commit

Permalink
Add workspace/symbol and updated references
Browse files Browse the repository at this point in the history
  • Loading branch information
TJ DeVries committed Nov 18, 2016
1 parent 41b95c8 commit 91ba01f
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 56 deletions.
14 changes: 10 additions & 4 deletions autoload/langserver/goto.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@ function! langserver#goto#callback(id, data, event) abort
call langserver#goto#goto_defintion(a:id, l:parsed_data['uri'], l:parsed_data['range'], {})
endfunction

function! langserver#goto#request(name) abort
call langserver#client#send(a:name, {
function! langserver#goto#request(...) abort
if a:0 > 0
let l:sever_name = a:1
else
let l:server_name = langserver#util#get_lsp_id()
endif

call langserver#client#send(l:server_name, {
\ 'method': 'textDocument/definition',
\ 'params': {
\ 'textDocument': langserver#util#get_text_document_identifier(a:name),
\ 'textDocument': langserver#util#get_text_document_identifier(l:server_name),
\ 'position': langserver#util#get_position(),
\ },
\ },
\ })
endfunction

Expand Down
14 changes: 8 additions & 6 deletions autoload/langserver/references.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ function! langserver#references#transform_reply(message) abort
let l:location_list = []
for l:location in a:message
let l:loc_bufnr = bufnr(langserver#util#get_filename(langserver#util#get_lsp_id(), l:location['uri']))
let l:loc_filename = langserver#util#get_filename(langserver#util#get_lsp_id(), l:location['uri'])
let l:loc_line = l:location['range']['start']['line'] + 1
let l:loc_text = bufnr('%') == l:loc_bufnr ? getline(l:loc_line) : ''

let l:location_dict = {
\ 'bufnr': l:loc_bufnr,
\ 'filename': l:loc_filename,
\ 'lnum': l:loc_line,
\ 'col': l:location['range']['start']['character'] + 1,
\ 'text': l:loc_text,
Expand Down Expand Up @@ -53,15 +54,16 @@ function! langserver#references#request() abort
endfunction

function! langserver#references#display(loc_list) abort
if langserver#util#debug()
echo 'Displaying references'
echo string(a:loc_list)
endif
call langserver#log#log('debug', "Displaying references...\n" . string(a:loc_list))

" TODO: Highlight the references, and turn them off somehow
call setloclist(0,
\ a:loc_list,
\ 'r',
\ '[Location References]',
\ '[References]',
\ )

if !empty(a:loc_list)
lwindow
endif
endfunction
112 changes: 70 additions & 42 deletions autoload/langserver/symbol/util.vim
Original file line number Diff line number Diff line change
@@ -1,44 +1,72 @@
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',
\ }
\}
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',
\ },
\ }


function! langserver#symbol#util#transform_reply(message) abort
let l:server_name = langserver#util#get_lsp_id()
let l:qf_list = []

for l:msg in a:message
let l:loc_filename = langserver#util#get_filename(l:server_name, l:msg['location']['uri'])
let l:loc_line = l:msg['location']['range']['start']['line'] + 1
let l:loc_col = l:msg['location']['range']['start']['character'] + 1

let l:loc_kind = s:symbol_kind['number'][l:msg['kind']]

let l:msg_dict = {
\ 'filename': l:loc_filename,
\ 'lnum': l:loc_line,
\ 'col': l:loc_col,
\ 'pattern': l:msg['name'],
\ 'text': printf('%10s: %s',
\ l:loc_kind,
\ l:msg['name'],
\ ),
\ }

call add(l:qf_list, l:msg_dict)
endfor

return l:qf_list
endfunction

9 changes: 8 additions & 1 deletion autoload/langserver/symbol/workspace.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ function! langserver#symbol#workspace#callback(id, data, event) abort
return
endif

call langserver#log#log('info', a:data, v:true)
let l:transformed = langserver#symbol#util#transform_reply(l:parsed_data)
call langserver#symbol#workspace#display(l:transformed)
endfunction

function!langserver#symbol#workspace#request(...) abort
Expand All @@ -21,3 +22,9 @@ function!langserver#symbol#workspace#request(...) abort
\ 'params': {'query': l:query}
\ })
endfunction

function! langserver#symbol#workspace#display(loc_list) abort
call langserver#log#log('debug', string(a:loc_list))

call setqflist(a:loc_list)
endfunction
13 changes: 11 additions & 2 deletions plugin/langserver.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


let g:langserver_configuration = {
\ 'json_rpc_version': "2.0",
\ 'json_rpc_version': '2.0',
\ }


Expand All @@ -11,4 +11,13 @@ command! LSPStart call langserver#start({})
" Open a text document, and alert the language server
command! LSPOpen call langserver#didOpenTextDocument()

nnoremap <leader>gd :call langserver#goto#request(langserver#util#get_lsp_id())<CR>
" Request a goto
command! LSPGoto call langserver#goto#request()

" Request a hover
command! LSPHover call langserver#hover#request()



nnoremap <leader>gd :call langserver#goto#request()<CR>
nnoremap <leader>gh :call langserver#hovoer#request()<CR>
8 changes: 7 additions & 1 deletion tests/test_message_parse.vader
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,11 @@ Execute (Test parse of references):
let test_message = '<-- result #25: textDocument/references: [{"uri":"file:///home/tj/go/src/github.com/sourcegraph/go-langserver/langserver/util.go","range":{"start":{"line":7,"character":22},"end":{"line":7,"character":28}}},{"uri":"file:///home/tj/go/src/github.com/sourcegraph/go-langserver/langserver/util.go","range":{"start":{"line":9,"character":4},"end":{"line":9,"character":10}}},{"uri":"file:///home/tj/go/src/github.com/sourcegraph/go-langserver/langserver/util.go","range":{"start":{"line":9,"character":39},"end":{"line":9,"character":45}}},{"uri":"file:///home/tj/go/src/github.com/sourcegraph/go-langserver/langserver/util.go","range":{"start":{"line":10,"character":16},"end":{"line":10,"character":22}}},{"uri":"file:///home/tj/go/src/github.com/sourcegraph/go-langserver/langserver/util.go","range":{"start":{"line":12,"character":13},"end":{"line":12,"character":19}}}]'

let parsed = langserver#util#parse_message(test_message)
let transformed = langserver#references#transform_reply(parsed)
" let transformed = langserver#references#transform_reply(parsed)
" Log transformed

Execute (Test parse of symbols):
let test_message = {'response': {'id': 6, 'result': [{'location': {'uri': 'file:///usr/local/go/src/os/path_plan9.go', 'range': {'end': {'character': 4, 'line': 7}, 'start': {'character': 0, 'line': 6}}}, 'name': 'PathSeparator', 'kind': 14, 'containerName': 'os'}, {'location': {'uri': 'file:///usr/local/go/src/os/path_unix.go', 'range': {'end': {'character': 4, 'line': 9}, 'start': {'character': 0, 'line': 8}}}, 'name': 'PathSeparator', 'kind': 14, 'containerName': 'os'}, {'location': {'uri': 'file:///usr/local/go/src/os/path_windows.go', 'range': {'end': {'character': 4, 'line': 7}, 'start': {'character': 0, 'line': 6}}}, 'name': 'PathSeparator', 'kind': 14, 'containerName': 'os'}], 'jsonrpc': '2.0'}, 'request': {'id': 6, 'jsonrpc': '2.0', 'method': 'workspace/symbol', 'params': {'query': 'PathSeparator'}}}

let transformed = langserver#symbol#util#transform_reply(test_message['response']['result'])
Log transformed

0 comments on commit 91ba01f

Please sign in to comment.