Skip to content

Commit

Permalink
Replace all v:t_* with type()
Browse files Browse the repository at this point in the history
Fixes #185

nvim has inconsistent support - rather than try to deal with figuring
out which work, avoid them entirely.
  • Loading branch information
natebosch committed May 22, 2019
1 parent 1fb7e1a commit 1900b06
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion autoload/lsc/capabilities.vim
Expand Up @@ -16,7 +16,7 @@ function! lsc#capabilities#normalize(capabilities) abort
let l:text_document_sync = a:capabilities['textDocumentSync']
let l:incremental = v:false
let l:send_did_save = v:true
if type(l:text_document_sync) == v:t_dict
if type(l:text_document_sync) == type{{}}
if has_key(l:text_document_sync, 'change')
let l:incremental = l:text_document_sync['change'] == 2
endif
Expand Down
2 changes: 1 addition & 1 deletion autoload/lsc/channel.vim
@@ -1,6 +1,6 @@
function! lsc#channel#open(command, Callback, ErrCallback, OnExit) abort
let l:c = s:Channel()
if type(a:command) == v:t_string && a:command =~# '[^:]\+:\d\+'
if type(a:command) == type('') && a:command =~# '[^:]\+:\d\+'
if !exists('*ch_open')
call lsc#message#error('No support for sockets for '.a:command)
return v:null
Expand Down
18 changes: 9 additions & 9 deletions autoload/lsc/complete.vim
Expand Up @@ -136,11 +136,11 @@ function! s:SuggestCompletions(completion) abort
endfunction

function! s:SetCompleteOpt() abort
if type(g:lsc_auto_completeopt) == v:t_string
if type(g:lsc_auto_completeopt) == type('')
" Set completeopt locally exactly like the user wants
execute 'setl completeopt='.g:lsc_auto_completeopt
elseif (type(g:lsc_auto_completeopt) == v:t_bool
\ || type(g:lsc_auto_completeopt) == v:t_number)
elseif (type(g:lsc_auto_completeopt) == type(v:true)
\ || type(g:lsc_auto_completeopt) == type(0))
\ && g:lsc_auto_completeopt
" Set the options that impact behavior for autocomplete use cases without
" touching other like `preview`
Expand Down Expand Up @@ -199,7 +199,7 @@ endfunction

function! s:MatchSuggestion(base, suggestion) abort
let word = a:suggestion
if type(word) == v:t_dict | let word = word.word | endif
if type(word) == type({}) | let word = word.word | endif
return word =~? a:base
endfunction

Expand All @@ -214,9 +214,9 @@ endfunction
" single start columns for every suggestion.
function! s:CompletionItems(completion_result) abort
let completion_items = []
if type(a:completion_result) == v:t_list
if type(a:completion_result) == type([])
let completion_items = a:completion_result
elseif type(a:completion_result) == v:t_dict
elseif type(a:completion_result) == type({})
let completion_items = a:completion_result.items
endif
call map(completion_items, {_, item -> s:CompletionItem(item)})
Expand All @@ -240,7 +240,7 @@ endfunction
function! s:CompletionItem(completion_item) abort
let item = {'abbr': a:completion_item.label, 'icase': 1, 'dup': 1}
if has_key(a:completion_item, 'textEdit')
\ && type(a:completion_item.textEdit) == v:t_dict
\ && type(a:completion_item.textEdit) == type({})
\ && has_key(a:completion_item.textEdit, 'newText')
let item.word = a:completion_item.textEdit.newText
let item.start_col = a:completion_item.textEdit.range.start.character + 1
Expand Down Expand Up @@ -268,9 +268,9 @@ function! s:CompletionItem(completion_item) abort
let item.info = ' '
if has_key(a:completion_item, 'documentation')
let documentation = a:completion_item.documentation
if type(documentation) == v:t_string
if type(documentation) == type('')
let item.info = documentation
elseif type(documentation) == v:t_dict && has_key(documentation, 'value')
elseif type(documentation) == type({}) && has_key(documentation, 'value')
let item.info = documentation.value
endif
endif
Expand Down
32 changes: 16 additions & 16 deletions autoload/lsc/config.vim
Expand Up @@ -19,10 +19,10 @@ if !exists('s:initialized')
endif

function! s:ApplyDefaults(config) abort
if type(a:config) == v:t_bool || type(a:config) == v:t_number
if type(a:config) == type(v:true) || type(a:config) == type(0)
return s:default_maps
endif
if type(a:config) != v:t_dict
if type(a:config) != type({})
\ || !has_key(a:config, 'defaults')
\ || !a:config.defaults
return a:config
Expand All @@ -41,12 +41,12 @@ endfunction

function! lsc#config#mapKeys() abort
if !exists('g:lsc_auto_map')
\ || (type(g:lsc_auto_map) == v:t_bool && !g:lsc_auto_map)
\ || (type(g:lsc_auto_map) == v:t_number && !g:lsc_auto_map)
\ || (type(g:lsc_auto_map) == type(v:true) && !g:lsc_auto_map)
\ || (type(g:lsc_auto_map) == type(0) && !g:lsc_auto_map)
return
endif
let l:maps = s:ApplyDefaults(g:lsc_auto_map)
if type(l:maps) != v:t_dict
if type(l:maps) != type({})
call lsc#message#error('g:lsc_auto_map must be a bool or dict')
return
endif
Expand All @@ -65,21 +65,21 @@ function! lsc#config#mapKeys() abort
\ 'SignatureHelp',
\] + (get(g:, 'lsc_enable_apply_edit', 1) ? ['Rename'] : [])
let lhs = get(l:maps, command, [])
if type(lhs) != v:t_string && type(lhs) != v:t_list
if type(lhs) != type('') && type(lhs) != type([])
continue
endif
for m in type(lhs) == v:t_list ? lhs : [lhs]
for m in type(lhs) == type([]) ? lhs : [lhs]
execute 'nnoremap <buffer>'.m.' :LSClient'.command.'<CR>'
endfor
endfor
if has_key(l:maps, 'Completion') &&
\ type(l:maps['Completion']) == v:t_string &&
\ type(l:maps['Completion']) == type('') &&
\ len(l:maps['Completion']) > 0
execute 'setlocal '.l:maps['Completion'].'=lsc#complete#complete'
endif
if has_key(l:maps, 'ShowHover')
let l:show_hover = l:maps['ShowHover']
if type(l:show_hover) == v:t_bool || type(l:show_hover) == v:t_number
if type(l:show_hover) == type(v:true) || type(l:show_hover) == type(0)
if l:show_hover
setlocal keywordprg=:LSClientShowHover
endif
Expand All @@ -92,9 +92,9 @@ function! lsc#config#messageHook(server, method, params) abort
let hooks = a:server.config.message_hooks
if !has_key(hooks, a:method) | return a:params | endif
let l:Hook = hooks[a:method]
if type(l:Hook) == v:t_func
if type(l:Hook) == type({_->_})
return s:RunHookFunction(l:Hook, a:method, a:params)
elseif type(l:Hook) == v:t_dict
elseif type(l:Hook) == type({})
return s:MergeHookDict(l:Hook, a:method, a:params)
else
call lsc#message#error('Message hook must be a function or a dict. '.
Expand Down Expand Up @@ -127,9 +127,9 @@ function! s:ResolveHookDict(hook, method, params) abort
if !s:HasFunction(a:hook) | return a:hook | endif
let copied = deepcopy(a:hook)
for key in keys(a:hook)
if type(a:hook[key]) == v:t_dict
if type(a:hook[key]) == type({})
let copied[key] = s:ResolveHookDict(a:hook[key], a:method, a:params)
elseif type(a:hook[key]) == v:t_func
elseif type(a:hook[key]) == type({_->_})
let Func = a:hook[key]
let copied[key] = Func(a:method, a:params)
endif
Expand All @@ -139,9 +139,9 @@ endfunction

function! s:HasFunction(hook) abort
for Value in values(a:hook)
if type(Value) == v:t_dict && s:HasFunction(Value)
if type(Value) == type({}) && s:HasFunction(Value)
return v:true
elseif type(Value) == v:t_func
elseif type(Value) == type({_->_})
return v:true
endif
endfor
Expand All @@ -155,7 +155,7 @@ endfunction
function! lsc#config#shouldEcho(server, type) abort
let l:threshold = 3
if has_key(a:server.config, 'log_level')
if type(a:server.config.log_level) == v:t_number
if type(a:server.config.log_level) == type(0)
let l:threshold = a:server.config.log_level
else
let l:config = a:server.config.log_level
Expand Down
10 changes: 5 additions & 5 deletions autoload/lsc/edit.vim
Expand Up @@ -14,19 +14,19 @@ function! lsc#edit#findCodeActions(...) abort
endfunction

function! s:SelectAction(result, action_filter) abort
if type(a:result) != v:t_list || len(a:result) == 0
if type(a:result) != type([]) || len(a:result) == 0
call lsc#message#show('No actions available')
return
endif
let l:choice = a:action_filter(a:result)
if type(l:choice) == v:t_dict
if has_key(l:choice, 'command') && type(l:choice.command) == v:t_string
if type(l:choice) == type({})
if has_key(l:choice, 'command') && type(l:choice.command) == type('')
call s:ExecuteCommand(l:choice)
else
if has_key(l:choice, 'edit') && type(l:choice.edit) == v:t_dict
if has_key(l:choice, 'edit') && type(l:choice.edit) == type({})
call lsc#edit#apply(l:choice.edit)
endif
if has_key(l:choice, 'command') && type(l:choice.command) == v:t_dict
if has_key(l:choice, 'command') && type(l:choice.command) == type({})
call s:ExecuteCommand(l:choice.command)
endif
endif
Expand Down
2 changes: 1 addition & 1 deletion autoload/lsc/message.vim
Expand Up @@ -33,7 +33,7 @@ function! s:Echo(echo_cmd, message, level) abort
endfunction

function! s:Level(level) abort
if type(a:level) == v:t_number
if type(a:level) == type(0)
if a:level == 1
return ['Error', 'lscDiagnosticError']
elseif a:level == 2
Expand Down
2 changes: 1 addition & 1 deletion autoload/lsc/protocol.vim
Expand Up @@ -73,7 +73,7 @@ function! s:Consume(server) abort
let a:server._buffer = remaining_message
try
let content = json_decode(payload)
if type(content) != v:t_dict | throw 1 | endif
if type(content) != type({}) | throw 1 | endif
catch
call lsc#message#error('Could not decode message: '.payload)
endtry
Expand Down
6 changes: 3 additions & 3 deletions autoload/lsc/reference.vim
Expand Up @@ -8,7 +8,7 @@ endfunction

function! s:GoToDefinition(mods, issplit, result) abort
if type(a:result) == type(v:null) ||
\ (type(a:result) == v:t_list && len(a:result) == 0)
\ (type(a:result) == type([]) && len(a:result) == 0)
call lsc#message#error('No definition found')
return
endif
Expand Down Expand Up @@ -132,12 +132,12 @@ function! s:showHover(result) abort
return
endif
let contents = a:result.contents
if type(contents) != v:t_list
if type(contents) != type([])
let contents = [contents]
endif
let lines = []
for item in contents
if type(item) == v:t_dict
if type(item) == type({})
let l:lines += split(item.value, "\n")
else
let l:lines += split(item, "\n")
Expand Down
2 changes: 1 addition & 1 deletion autoload/lsc/search.vim
Expand Up @@ -9,7 +9,7 @@ function! lsc#search#workspaceSymbol(...) abort
endfunction

function! s:setQuickFixSymbols(results) abort
if type(a:results) != v:t_list || len(a:results) == 0
if type(a:results) != type([]) || len(a:results) == 0
call lsc#message#show('No symbols found')
return
endif
Expand Down
8 changes: 4 additions & 4 deletions autoload/lsc/server.vim
Expand Up @@ -122,7 +122,7 @@ function! s:Start(server) abort
function! OnInitialize(init_result) closure abort
let a:server.status = 'running'
call a:server.notify('initialized', {})
if type(a:init_result) == v:t_dict && has_key(a:init_result, 'capabilities')
if type(a:init_result) == type({}) && has_key(a:init_result, 'capabilities')
let a:server.capabilities =
\ lsc#capabilities#normalize(a:init_result.capabilities)
endif
Expand Down Expand Up @@ -200,12 +200,12 @@ function! lsc#server#enable()
endfunction

function! lsc#server#register(filetype, config) abort
if type(a:config) == v:t_string
if type(a:config) == type('')
let config = {'command': a:config, 'name': a:config}
elseif type(a:config) == v:t_list
elseif type(a:config) == type([])
let config = {'command': a:config, 'name': string(a:config)}
else
if type(a:config) != v:t_dict
if type(a:config) != type({})
throw 'Server configuration must be an executable or a dict'
endif
let config = a:config
Expand Down
2 changes: 1 addition & 1 deletion autoload/lsc/signaturehelp.vim
Expand Up @@ -19,7 +19,7 @@ endfunction
function! s:ShowHelp(signatureHelp) abort
let signatures = []
if has_key(a:signatureHelp, 'signatures')
if type(a:signatureHelp.signatures) == v:t_list
if type(a:signatureHelp.signatures) == type([])
let signatures = a:signatureHelp.signatures
endif
endif
Expand Down
6 changes: 3 additions & 3 deletions autoload/lsc/util.vim
Expand Up @@ -146,12 +146,12 @@ function! lsc#util#gateResult(name, callback, ...)
endif
let gate = s:callback_gates[a:name]
let old_pos = getcurpos()
if a:0 >= 1 && type(a:1) == v:t_func
if a:0 >= 1 && type(a:1) == type({_->)})
let OnSkip = a:1
else
let OnSkip = v:false
endif
if a:0 >= 2 && type(a:2) == v:t_list
if a:0 >= 2 && type(a:2) == type([])
let extra_args = a:2
else
let extra_args = []
Expand All @@ -168,7 +168,7 @@ function! s:Gated(name, gate, old_pos, on_call, on_skip, extra_args, ...) abort
endif
if s:callback_gates[a:name] != a:gate ||
\ a:old_pos != getcurpos()
if type(a:on_skip) == v:t_func
if type(a:on_skip) == type({_->_})
call call(a:on_skip, args)
endif
else
Expand Down

0 comments on commit 1900b06

Please sign in to comment.