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

Commit

Permalink
Start using a more generic mapping
Browse files Browse the repository at this point in the history
Should allow for comma separated lists for a server.

Still need to deal with getting the right value of the
id to each process.
  • Loading branch information
tjdevries committed Nov 20, 2016
1 parent f05dd6d commit 8fe8643
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 24 deletions.
70 changes: 46 additions & 24 deletions autoload/langserver/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,24 @@ endfunction
" @key code TODO
" @key source TODO
function! langserver#util#get_diagnostic(start, end, message, options) abort
let return_dict = {
let l:return_dict = {
\ 'range': langserver#util#get_range(a:start, a:end),
\ 'messsage': a:message
\ }

if has_key(a:options, 'severity')
let return_dict['severity'] = a:options['severity']
let l:return_dict['severity'] = a:options['severity']
endif

if has_key(a:options, 'code')
let return_dict['code'] = a:options['code']
let l:return_dict['code'] = a:options['code']
endif

if has_key(a:options, 'source')
let return_dict['source'] = a:options['source']
let l:return_dict['source'] = a:options['source']
endif

return return_dict
return l:return_dict
endfunction

""
Expand All @@ -103,13 +103,13 @@ endfunction
" @param command (str): The identifier of the actual command handler
" @param arguments (Optional[list]): Optional list of arguments passed to the command
function! langserver#util#get_command(title, command, ...) abort
let return_dict = {
let l:return_dict = {
\ 'title': a:title,
\ 'command': a:command,
\ }

if a:0 > 1
let return_dict['arguments'] = a:1
let l:return_dict['arguments'] = a:1
endif
endfunction

Expand Down Expand Up @@ -137,7 +137,7 @@ endfunction
" TODO: Figure out a better way to do this.
" @param
function! langserver#util#get_workspace_edit(uri, edit) abort
let my_dict = {
let l:my_dict = {
\ 'uri': 'edit',
\ }
endfunction
Expand Down Expand Up @@ -209,38 +209,60 @@ endfunction
" Parse the stdin of a server
function! langserver#util#parse_message(message) abort
if type(a:message) ==# type([])
let data = join(a:message, '')
let l:data = join(a:message, '')
elseif type(a:message) ==# type('')
let data = a:message
let l:data = a:message
else
endif

let parsed = {}
if data =~? '--> request'
let parsed['type'] = 'request'
elseif data =~? '<-- result'
let parsed['type'] = 'result'
let l:parsed = {}
if l:data =~? '--> request'
let l:parsed['type'] = 'request'
elseif l:data =~? '<-- result'
let l:parsed['type'] = 'result'
else
let parsed['type'] = 'info'
let l:parsed['type'] = 'info'
endif

let data = substitute(data, '--> request #\w*: ', '', 'g')
let data = substitute(data, '<-- result #\w*: ', '', 'g')
let l:data = substitute(l:data, '--> request #\w*: ', '', 'g')
let l:data = substitute(l:data, '<-- result #\w*: ', '', 'g')

if parsed['type'] ==# 'request' || parsed['type'] ==# 'result'
let data = substitute(data, '^\(\S*\):', '"\1":', 'g')
let data = '{' . data . '}'
let data = json_decode(data)
if l:parsed['type'] ==# 'request' || l:parsed['type'] ==# 'result'
let l:data = substitute(l:data, '^\(\S*\):', '"\1":', 'g')
let l:data = '{' . l:data . '}'
let l:data = json_decode(l:data)
endif

let parsed['data'] = data
return parsed
let l:parsed['data'] = l:data
return l:parsed
endfunction

function! langserver#util#debug() abort
return v:false
endfunction

function! langserver#util#get_executable_key(...) abort
if a:0 > 0
let l:file_type = a:1
else
let l:file_type = &filetype
endif

if !exists('g:langserver_executables')
echoerr '`g:langserver_executables` was not defined'
return ''
endif

for l:k in keys(g:langserver_executables)
if index(split(l:k, ','), l:file_type) >= 0
return l:k
endif
endfor

echoerr 'Unsupported filetype: ' . l:file_type
return ''
endfunction

function! langserver#util#get_lsp_id() abort
let g:lsp_id_map = get(g:, 'lsp_id_map', {})

Expand Down
20 changes: 20 additions & 0 deletions tests/test_defaults.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Execute (Testing executable configuration):
let g:__temp_exec = get(g:, 'langserver_executables', {})
let g:langserver_executables = {
\ 'go': {
\ 'name': 'sourcegraph/langserver-go',
\ 'cmd': ['langserver-go', '-trace', '-logfile', expand('~/Desktop/langserver-go.log')],
\ },
\ 'python': {
\ 'name': 'sourcegraph/python-langserver',
\ 'cmd': [expand('~/bin/python-langserver/python-langserver.py')],
\ },
\ 'javascript,typescript,jsx,tsx': {
\ 'name': 'javascript-typescript',
\ 'cmd': [],
\ },
\ }

AssertEqual 'javascript,typescript,jsx,tsx', langserver#util#get_executable_key('jsx')

let g:langserver_executables = g:__temp_exec

0 comments on commit 8fe8643

Please sign in to comment.