From 16e875493d5d54ca274b3275d47e74d535cc31bd Mon Sep 17 00:00:00 2001 From: tracyone Date: Sat, 9 Dec 2023 22:06:14 +0800 Subject: [PATCH] complete: load complete plugin in normal mode Signed-off-by: tracyone --- autoload/plug.vim | 7 +++++++ autoload/te/complete.vim | 42 ++++++++++++++++++++++++++-------------- autoload/te/plug.vim | 14 +++++++++----- 3 files changed, 43 insertions(+), 20 deletions(-) diff --git a/autoload/plug.vim b/autoload/plug.vim index 9600874..a74483c 100644 --- a/autoload/plug.vim +++ b/autoload/plug.vim @@ -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') diff --git a/autoload/te/complete.vim b/autoload/te/complete.vim index 3c84ad6..50e2f79 100644 --- a/autoload/te/complete.vim +++ b/autoload/te/complete.vim @@ -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(".") @@ -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() @@ -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.*') @@ -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('') + + 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() diff --git a/autoload/te/plug.vim b/autoload/te/plug.vim index d1cb2f8..51fa7a3 100644 --- a/autoload/te/plug.vim +++ b/autoload/te/plug.vim @@ -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 @@ -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