mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-09 08:40: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/')
|
call add(g:spacevim_project_rooter_patterns, '.SpaceVim.d/')
|
||||||
let s:spacevim_project_rooter_patterns = copy(g:spacevim_project_rooter_patterns)
|
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
|
endfunction
|
||||||
|
|
||||||
function! SpaceVim#plugins#projectmanager#current_root() abort
|
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.
|
" if rooter patterns changed, clear cache.
|
||||||
" https://github.com/SpaceVim/SpaceVim/issues/2367
|
" https://github.com/SpaceVim/SpaceVim/issues/2367
|
||||||
if join(g:spacevim_project_rooter_patterns, ':') !=# join(s:spacevim_project_rooter_patterns, ':')
|
if join(g:spacevim_project_rooter_patterns, ':') !=# join(s:spacevim_project_rooter_patterns, ':')
|
||||||
@ -113,7 +122,8 @@ function! SpaceVim#plugins#projectmanager#current_root() abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:change_dir(dir) abort
|
function! s:change_dir(dir) abort
|
||||||
call SpaceVim#logger#info('change to root:' . a:dir)
|
call SpaceVim#logger#info('buffer name: ' . bufname('%'))
|
||||||
|
call SpaceVim#logger#info('change to root: ' . a:dir)
|
||||||
exe 'cd ' . fnameescape(fnamemodify(a:dir, ':p'))
|
exe 'cd ' . fnameescape(fnamemodify(a:dir, ':p'))
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -124,8 +134,6 @@ function! s:change_dir(dir) abort
|
|||||||
" let &l:statusline = SpaceVim#layers#core#statusline#get(1)
|
" let &l:statusline = SpaceVim#layers#core#statusline#get(1)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let s:BUFFER = SpaceVim#api#import('vim#buffer')
|
|
||||||
|
|
||||||
function! SpaceVim#plugins#projectmanager#kill_project() abort
|
function! SpaceVim#plugins#projectmanager#kill_project() abort
|
||||||
let name = get(b:, '_spacevim_project_name', '')
|
let name = get(b:, '_spacevim_project_name', '')
|
||||||
if name !=# ''
|
if name !=# ''
|
||||||
@ -152,7 +160,7 @@ endif
|
|||||||
function! s:find_root_directory() abort
|
function! s:find_root_directory() abort
|
||||||
let fd = expand('%:p')
|
let fd = expand('%:p')
|
||||||
let dirs = []
|
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
|
for pattern in g:spacevim_project_rooter_patterns
|
||||||
if stridx(pattern, '/') != -1
|
if stridx(pattern, '/') != -1
|
||||||
let dir = SpaceVim#util#findDirInParent(pattern, fd)
|
let dir = SpaceVim#util#findDirInParent(pattern, fd)
|
||||||
@ -161,11 +169,14 @@ function! s:find_root_directory() abort
|
|||||||
endif
|
endif
|
||||||
let ftype = getftype(dir)
|
let ftype = getftype(dir)
|
||||||
if ftype ==# 'dir' || ftype ==# 'file'
|
if ftype ==# 'dir' || ftype ==# 'file'
|
||||||
let dir = fnamemodify(dir, ':p')
|
let dir = s:FILE.unify_path(fnamemodify(dir, ':p'))
|
||||||
if dir !=# expand('~/.SpaceVim.d/')
|
if ftype ==# 'dir'
|
||||||
call SpaceVim#logger#info(' (' . pattern . '):' . dir)
|
let dir = fnamemodify(dir, ':h:h')
|
||||||
call add(dirs, dir)
|
else
|
||||||
|
let dir = fnamemodify(dir, ':h')
|
||||||
endif
|
endif
|
||||||
|
call SpaceVim#logger#info(' (' . pattern . '):' . dir)
|
||||||
|
call add(dirs, dir)
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
return s:sort_dirs(deepcopy(dirs))
|
return s:sort_dirs(deepcopy(dirs))
|
||||||
@ -178,17 +189,12 @@ function! s:sort_dirs(dirs) abort
|
|||||||
if bufdir ==# dir
|
if bufdir ==# dir
|
||||||
return ''
|
return ''
|
||||||
else
|
else
|
||||||
if isdirectory(dir)
|
|
||||||
let dir = fnamemodify(dir, ':p:h:h')
|
|
||||||
else
|
|
||||||
let dir = fnamemodify(dir, ':p:h')
|
|
||||||
endif
|
|
||||||
return dir
|
return dir
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:compare(d1, d2) abort
|
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
|
endfunction
|
||||||
|
|
||||||
let s:FILE = SpaceVim#api#import('file')
|
let s:FILE = SpaceVim#api#import('file')
|
||||||
|
Loading…
Reference in New Issue
Block a user