Open fcojavierdomenech opened 4 years ago
I think you should be able to only load the plugin for specific files using coc config or vim config
UPDATE
Based on discussions at https://github.com/neoclide/coc.nvim/issues/3176, an improved version:
" Project (and file type) specific CoC extensions
" Example:
" let g:coc_local_extensions = { 'coc-jira-complete': ['gitcommit'] }
let g:coc_local_extensions = {}
function! s:toggle_coc_local_extensions(activate) abort
if !get(g:, 'coc_service_initialized', 0)
return
endif
for [extension_id, fts] in items(g:coc_local_extensions)
if !empty(fts) && index(fts, getbufvar(+expand('<abuf>'), '&filetype')) >= 0
call CocActionAsync(a:activate ? 'activeExtension' : 'deactivateExtension', extension_id)
endif
endfor
endfunction
function! s:coc_local_extensions_rtp() abort
for [extension_id, fts] in items(g:coc_local_extensions)
let l:path = escape(join([coc#util#get_data_home(), 'local_extensions', 'node_modules', l:extension_id], '/'), ' \|,')
if empty(fts) || index(fts, getbufvar(+expand('<abuf>'), '&filetype')) >= 0
execute 'set runtimepath+=' . l:path
continue
endif
execute 'autocmd FileType ' . join(fts, ',') . ' ++nested set runtimepath+=' . l:path
endfor
endfunction
autocmd VimEnter * call <SID>coc_local_extensions_rtp()
autocmd BufRead * call <SID>toggle_coc_local_extensions(v:true)
autocmd BufUnload * call <SID>toggle_coc_local_extensions(v:false)
I'd like to see Jira completions only when writing Git commit messages. So far the best I can do:
" .exrc in projects that's got Jira
call add(g:coc_global_extensions, 'coc-jira-complete')
function! s:is_jira_enabled()
let extensions = CocAction('extensionStats')
for extension in extensions
if extension['id'] == 'coc-jira-complete'
if extension['state'] == 'disabled'
return v:false
endif
return v:true
endif
endfor
return v:false
endfunction
function! s:enable_jira() abort
let enabled = s:is_jira_enabled()
if !enabled
call CocAction('toggleExtension', 'coc-jira-complete')
endif
endfunction
function! s:disable_jira() abort
let enabled = s:is_jira_enabled()
if enabled
call CocAction('toggleExtension', 'coc-jira-complete')
endif
endfunction
function! s:toggle_jira() abort
if &filetype == 'gitcommit'
call CocActionAsync('activeExtension', 'coc-jira-complete')
else
call CocActionAsync('deactivateExtension', 'coc-jira-complete')
endif
endfunction
autocmd User CocNvimInit call <SID>enable_jira()
autocmd BufEnter * call <SID>toggle_jira()
autocmd VimLeave * call <SID>disable_jira()
IMO still it'd be nice to have something like:
It can be a bit annoying having Jira issues suggestions when you're autocompleting code.
It would be nice to restrict it to
COMMIT_EDITMSG
files or only when no text has been chained for the autocompletion.