mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-04-14 23:49:19 +08:00
Fix find path in project manager (#3761)
This commit is contained in:
parent
272ca05c17
commit
e5f245d2a4
@ -251,6 +251,43 @@ endfunction
|
||||
|
||||
let s:file['path_to_fname'] = function('s:path_to_fname')
|
||||
|
||||
function! s:findfile(what, where, ...) abort
|
||||
let old_suffixesadd = &suffixesadd
|
||||
let &suffixesadd = ''
|
||||
let l:count = get(a:000, 0, 0)
|
||||
if l:count > 0
|
||||
let file = findfile(a:what, escape(a:where, ' ') . ';', l:count)
|
||||
elseif a:0 ==# 0
|
||||
let file = findfile(a:what, escape(a:where, ' ') . ';')
|
||||
elseif l:count ==# 0
|
||||
let file = findfile(a:what, escape(a:where, ' ') . ';', -1)
|
||||
else
|
||||
let file = get(findfile(a:what, escape(a:where, ' ') . ';', -1), l:count, '')
|
||||
endif
|
||||
let &suffixesadd = old_suffixesadd
|
||||
return file
|
||||
endfunction
|
||||
|
||||
let s:file['findfile'] = function('s:findfile')
|
||||
|
||||
function! s:finddir(what, where, ...) abort
|
||||
let old_suffixesadd = &suffixesadd
|
||||
let &suffixesadd = ''
|
||||
let l:count = get(a:000, 0, 0)
|
||||
if l:count > 0
|
||||
let file = finddir(a:what, escape(a:where, ' ') . ';', l:count)
|
||||
elseif a:0 ==# 0
|
||||
let file = finddir(a:what, escape(a:where, ' ') . ';')
|
||||
elseif l:count ==# 0
|
||||
let file = finddir(a:what, escape(a:where, ' ') . ';', -1)
|
||||
else
|
||||
let file = get(finddir(a:what, escape(a:where, ' ') . ';', -1), l:count, '')
|
||||
endif
|
||||
let &suffixesadd = old_suffixesadd
|
||||
return file
|
||||
endfunction
|
||||
|
||||
let s:file['finddir'] = function('s:finddir')
|
||||
function! SpaceVim#api#file#get() abort
|
||||
return deepcopy(s:file)
|
||||
endfunction
|
||||
|
@ -188,9 +188,17 @@ function! s:find_root_directory() abort
|
||||
call SpaceVim#logger#info('Start to find root for: ' . s:FILE.unify_path(fd))
|
||||
for pattern in s:project_rooter_patterns
|
||||
if stridx(pattern, '/') != -1
|
||||
let find_path = SpaceVim#util#findDirInParent(pattern, fd)
|
||||
if g:spacevim_project_rooter_outermost
|
||||
let find_path = s:FILE.finddir(pattern, fd, -1)
|
||||
else
|
||||
let find_path = s:FILE.finddir(pattern, fd)
|
||||
endif
|
||||
else
|
||||
let find_path = SpaceVim#util#findFileInParent(pattern, fd)
|
||||
if g:spacevim_project_rooter_outermost
|
||||
let find_path = s:FILE.findfile(pattern, fd, -1)
|
||||
else
|
||||
let find_path = s:FILE.findfile(pattern, fd)
|
||||
endif
|
||||
endif
|
||||
let path_type = getftype(find_path)
|
||||
if ( path_type ==# 'dir' || path_type ==# 'file' )
|
||||
|
@ -3,3 +3,14 @@ Execute ( SpaceVim api: file ):
|
||||
let g:spacevim_filetype_icons = {}
|
||||
let file = SpaceVim#api#import('file')
|
||||
AssertEqual file.fticon('foo.md'), ''
|
||||
let path = fnamemodify('.SpaceVim.d/init.vim', ':p')
|
||||
AssertEqual file.unify_path(file.findfile('README.md', fnamemodify(path, ':p')), ':.'), '.SpaceVim.d/README.md'
|
||||
AssertEqual map(file.findfile('README.md', fnamemodify(path, ':p'), 0), 'file.unify_path(v:val, ":.")'), ['.SpaceVim.d/README.md', 'README.md']
|
||||
AssertEqual file.unify_path(file.findfile('README.md', fnamemodify(path, ':p'), 1), ':.'), '.SpaceVim.d/README.md'
|
||||
AssertEqual file.unify_path(file.findfile('README.md', fnamemodify(path, ':p'), -1), ':.'), 'README.md'
|
||||
AssertEqual file.unify_path(file.findfile('README.md', fnamemodify(path, ':p'), -2), ':.'), '.SpaceVim.d/README.md'
|
||||
let path = fnamemodify('bundle/dein.vim/autoload/dein.vim', ':p')
|
||||
AssertEqual file.unify_path(file.finddir('doc/', fnamemodify(path, ':p')), ':.'), 'bundle/dein.vim/doc/'
|
||||
AssertEqual map(file.finddir('doc/', fnamemodify(path, ':p'), 0), 'file.unify_path(v:val, ":.")'), ['bundle/dein.vim/doc/', 'doc/']
|
||||
AssertEqual file.unify_path(file.finddir('doc/', fnamemodify(path, ':p'), -1), ':.'), 'doc/'
|
||||
unlet file path
|
||||
|
Loading…
x
Reference in New Issue
Block a user