mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-03 00:00:04 +08:00
Improve project manager plugin (#3316)
This commit is contained in:
parent
4a77d41c37
commit
c50bc1eced
@ -14,6 +14,10 @@
|
||||
" }
|
||||
"
|
||||
|
||||
let s:BUFFER = SpaceVim#api#import('vim#buffer')
|
||||
let s:FILE = SpaceVim#api#import('file')
|
||||
|
||||
|
||||
|
||||
call add(g:spacevim_project_rooter_patterns, '.SpaceVim.d/')
|
||||
let s:spacevim_project_rooter_patterns = copy(g:spacevim_project_rooter_patterns)
|
||||
@ -91,6 +95,11 @@ function! SpaceVim#plugins#projectmanager#reg_callback(func) abort
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#plugins#projectmanager#current_root() abort
|
||||
" @todo skip some plugin buffer
|
||||
if bufname('%') =~# '\[denite\]-'
|
||||
\ || bufname('%') ==# 'denite-filter'
|
||||
return
|
||||
endif
|
||||
" if rooter patterns changed, clear cache.
|
||||
" https://github.com/SpaceVim/SpaceVim/issues/2367
|
||||
if join(g:spacevim_project_rooter_patterns, ':') !=# join(s:spacevim_project_rooter_patterns, ':')
|
||||
@ -113,6 +122,7 @@ function! SpaceVim#plugins#projectmanager#current_root() abort
|
||||
endfunction
|
||||
|
||||
function! s:change_dir(dir) abort
|
||||
call SpaceVim#logger#info('buffer name: ' . bufname('%'))
|
||||
call SpaceVim#logger#info('change to root: ' . a:dir)
|
||||
exe 'cd ' . fnameescape(fnamemodify(a:dir, ':p'))
|
||||
|
||||
@ -124,8 +134,6 @@ function! s:change_dir(dir) abort
|
||||
" let &l:statusline = SpaceVim#layers#core#statusline#get(1)
|
||||
endfunction
|
||||
|
||||
let s:BUFFER = SpaceVim#api#import('vim#buffer')
|
||||
|
||||
function! SpaceVim#plugins#projectmanager#kill_project() abort
|
||||
let name = get(b:, '_spacevim_project_name', '')
|
||||
if name !=# ''
|
||||
@ -152,7 +160,7 @@ endif
|
||||
function! s:find_root_directory() abort
|
||||
let fd = expand('%:p')
|
||||
let dirs = []
|
||||
call SpaceVim#logger#info('Start to find root for: ' . fd)
|
||||
call SpaceVim#logger#info('Start to find root for: ' . s:FILE.unify_path(fd))
|
||||
for pattern in g:spacevim_project_rooter_patterns
|
||||
if stridx(pattern, '/') != -1
|
||||
let dir = SpaceVim#util#findDirInParent(pattern, fd)
|
||||
@ -161,12 +169,15 @@ function! s:find_root_directory() abort
|
||||
endif
|
||||
let ftype = getftype(dir)
|
||||
if ftype ==# 'dir' || ftype ==# 'file'
|
||||
let dir = fnamemodify(dir, ':p')
|
||||
if dir !=# expand('~/.SpaceVim.d/')
|
||||
let dir = s:FILE.unify_path(fnamemodify(dir, ':p'))
|
||||
if ftype ==# 'dir'
|
||||
let dir = fnamemodify(dir, ':h:h')
|
||||
else
|
||||
let dir = fnamemodify(dir, ':h')
|
||||
endif
|
||||
call SpaceVim#logger#info(' (' . pattern . '):' . dir)
|
||||
call add(dirs, dir)
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
return s:sort_dirs(deepcopy(dirs))
|
||||
endfunction
|
||||
@ -178,17 +189,12 @@ function! s:sort_dirs(dirs) abort
|
||||
if bufdir ==# dir
|
||||
return ''
|
||||
else
|
||||
if isdirectory(dir)
|
||||
let dir = fnamemodify(dir, ':p:h:h')
|
||||
else
|
||||
let dir = fnamemodify(dir, ':p:h')
|
||||
endif
|
||||
return dir
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:compare(d1, d2) abort
|
||||
return len(split(a:d2, '/')) - len(split(a:d1, '/'))
|
||||
return len(split(a:d1, '/')) - len(split(a:d2, '/'))
|
||||
endfunction
|
||||
|
||||
let s:FILE = SpaceVim#api#import('file')
|
||||
|
Loading…
Reference in New Issue
Block a user