Skip to content

Commit

Permalink
toggle coc-deno and coc-tsserver extensions based on ecma runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
filmaj committed Aug 27, 2022
1 parent 0cb4819 commit e4bba25
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,36 @@ function! s:disable_coc_for_type()
let b:coc_enabled = 0
endif
endfunction
function! s:enable_extensions_for_deno()
call CocActionAsync('activeExtension', 'coc-deno')
call CocActionAsync('deactivateExtension', 'coc-tsserver')
endfunction
function! s:enable_extensions_for_node()
call CocActionAsync('activeExtension', 'coc-tsserver')
call CocActionAsync('deactivateExtension', 'coc-deno')
endfunction
function! s:set_ts_lsp()
" enable/disable coc-tsserver/coc-deno based on detection of diff ecma runtimes
let l:bufname = expand('%')
" The buffer is deno lsp virtual file
if l:bufname =~# '^deno:/'
call s:enable_extensions_for_deno()
return
endif
let l:path = empty(l:bufname) ? '.' : expand('%:p:h')
if !empty(finddir('node_modules', l:path . ';')) || !empty(findfile('package.json', l:path . ';'))
call s:enable_extensions_for_node()
return
endif
if !empty(findfile('deno.jsonc', l:path . ';')) || !empty(findfile('import_map.json', l:path . ';'))
call s:enable_extensions_for_deno()
return
endif
" TODO: check for existence of .vim/coc-settings.json and look for
" deno.enable and/or tsserver.enable config props
endfunction
autocmd BufRead,BufNewFile * call s:disable_coc_for_type()
autocmd filetype javascript,typescript call s:set_ts_lsp()
" Tweaking colours used in vim w/ coc.nvim
highlight Conceal ctermfg=7 ctermbg=0

Expand Down

0 comments on commit e4bba25

Please sign in to comment.