Skip to content

Commit

Permalink
complete: load complete plugin in normal mode
Browse files Browse the repository at this point in the history
Signed-off-by: tracyone <[email protected]>
  • Loading branch information
tracyone committed Dec 9, 2023
1 parent cb2d3de commit 16e8754
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 20 deletions.
7 changes: 7 additions & 0 deletions autoload/plug.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2531,6 +2531,13 @@ function! s:upgrade_specs()
endfor
endfunction

function! plug#is_plugin_load(name) abort
if get(s:loaded, a:name, 0) == 0
return 0
endif
return 1
endfunction

function! s:status()
call s:prepare()
call append(0, 'Checking plugins')
Expand Down
42 changes: 27 additions & 15 deletions autoload/te/complete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ function! te#complete#cstag(timer) abort
endif
endfunction

function! s:load_complete_plugin() abort
if get(g:, 'feat_enable_complete', 0)
if !plug#is_plugin_load(g:complete_plugin.name[0])
call te#utils#EchoWarning("Try to load ".g:complete_plugin.name[0].' ...')
call plug#load(g:complete_plugin.name)
if type(g:complete_plugin.enable_func) == g:t_func
call g:complete_plugin.enable_func()
else
execute g:complete_plugin.enable_func
endif
autocmd! lazy_load_group
call te#utils#EchoWarning('Finish! Please try again!')
return 1
endif
endif
return 0
endfunction

function! te#complete#goto_def(open_type) abort
let l:ret = -1
let s:cur_line = line(".")
Expand All @@ -33,6 +51,10 @@ function! te#complete#goto_def(open_type) abort
endif
endif

if s:load_complete_plugin() == 1
return 0
endif

if get(g:, 'feat_enable_complete', 0) &&
\ g:complete_plugin_type.cur_val ==# 'YouCompleteMe'
let l:ret=s:YcmGotoDef()
Expand Down Expand Up @@ -92,21 +114,6 @@ function! s:get_input() abort
endfunction

function! s:YcmGotoDef() abort
if g:complete_plugin_type.cur_val ==# 'YouCompleteMe'
if exists('*youcompleteme#Enable') == 0
if te#pg#top_of_kernel_tree(getcwd())
let g:ycm_global_ycm_extra_conf = $VIMFILES.'/rc/ycm_conf_for_arm_linux.py'
endif
call te#utils#EchoWarning('Loading ycm ...')
call plug#load(g:complete_plugin.name)
call delete('.ycm_extra_conf.pyc')
call youcompleteme#Enable()
let g:is_load_ycm = 1
autocmd! lazy_load_group
call te#utils#EchoWarning('ycm has been loaded!')
return -1
endif
endif
let l:ret = te#utils#GetError(':YcmCompleter GoToDefinition','Runtime.*')
if l:ret == -1
let l:ret = te#utils#GetError(':YcmCompleter GoToDeclaration','Runtime.*')
Expand Down Expand Up @@ -151,6 +158,11 @@ function te#complete#lookup_reference(open_type) abort
let s:cur_line = line(".")
let s:cur_file_name = expand('%:t')
let s:cur_word=expand('<cword>')

if s:load_complete_plugin() == 1
return 0
endif

execute a:open_type
if g:feat_enable_lsp == 1
let l:ret=te#lsp#references()
Expand Down
14 changes: 9 additions & 5 deletions autoload/te/plug.vim
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,15 @@ function! s:syntax() abort
syntax region plug2 start=/\%2l/ end=/\%3l/ contains=plugBracket,plugX
syn match plugDash /^-/
syn match plugName /\(^- \)\@<=[^ ]*:/
syn match plugNotLoaded /(http.*)/
syn match MoreMsg /(http.*)/
syn match plugError /\[missing\]/
syn match plugNotLoaded /\[unloaded\]/
syn keyword Function PlugInstall PlugStatus PlugUpdate PlugClean
hi def link plug1 Title
hi def link plug2 Repeat
hi def link plugDash Special
hi def link plugName Label
hi def link plugNotLoaded Comment
hi def link plugName Label
hi def link plugError Error
endfunction

Expand Down Expand Up @@ -184,11 +185,14 @@ function! te#plug#list() abort
let l:i=3

for l:needle in g:plugs_order
let l:status=''
if !isdirectory(g:plugs[l:needle].dir)
call add(l:output, printf('- %s:%s [missing]', l:needle,' ('.g:plugs[l:needle].uri.')' ) )
else
call add(l:output, printf('- %s:%s', l:needle,' ('.g:plugs[l:needle].uri.')' ) )
let l:status='[missing]'
endif
if !plug#is_plugin_load(l:needle)
let l:status.=' [unloaded]'
endif
call add(l:output, printf('- %s:%s %s', l:needle,' ('.g:plugs[l:needle].uri.')', l:status ) )
let l:i=l:i + 1
endfor
let l:output[0].=l:i-3
Expand Down

0 comments on commit 16e8754

Please sign in to comment.