diff --git a/autoload/langserver/callbacks.vim b/autoload/langserver/callbacks.vim index 0837296..79a4a8e 100644 --- a/autoload/langserver/callbacks.vim +++ b/autoload/langserver/callbacks.vim @@ -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 @@ -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 diff --git a/autoload/langserver/hover.vim b/autoload/langserver/hover.vim index 9fc6aa3..f8027c2 100644 --- a/autoload/langserver/hover.vim +++ b/autoload/langserver/hover.vim @@ -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 diff --git a/autoload/langserver/symbol/util.vim b/autoload/langserver/symbol/util.vim new file mode 100644 index 0000000..c721470 --- /dev/null +++ b/autoload/langserver/symbol/util.vim @@ -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', + \ } + \} + + diff --git a/autoload/langserver/symbol/workspace.vim b/autoload/langserver/symbol/workspace.vim new file mode 100644 index 0000000..ea979da --- /dev/null +++ b/autoload/langserver/symbol/workspace.vim @@ -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('') + endif + + return langserver#client#send(langserver#util#get_lsp_id(), { + \ 'method': s:method, + \ 'params': {'query': l:query} + \ }) +endfunction