Skip to content

Commit

Permalink
asyncrun#get_root now accepts buffer number
Browse files Browse the repository at this point in the history
  • Loading branch information
skywind3000 committed Jul 1, 2024
1 parent 182c636 commit b098775
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion autoload/asyncrun/locator.vim
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ endfunc
"----------------------------------------------------------------------
" root locator
"----------------------------------------------------------------------
function! asyncrun#locator#detect()
function! asyncrun#locator#detect(name)
if &bt == ''
return asyncrun#locator#special_buffer_path()
endif
Expand Down
36 changes: 29 additions & 7 deletions plugin/asyncrun.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
" Maintainer: skywind3000 (at) gmail.com, 2016-2024
" Homepage: https://github.com/skywind3000/asyncrun.vim
"
" Last Modified: 2024/05/23 01:31
" Last Modified: 2024/07/02 00:23
"
" Run shell command in background and output to quickfix:
" :AsyncRun[!] [options] {cmd} ...
Expand Down Expand Up @@ -1185,29 +1185,51 @@ function! s:guess_root(filename, markers)
endfunc

" find project root
function! s:find_root(path, markers, strict)
if a:path == '%'
function! s:find_root(name, markers, strict)
let path = ''
if type(a:name) == 0
let bid = (a:name < 0)? bufnr('%') : (a:name + 0)
let path = bufname(bid)
let root = getbufvar(bid, 'asyncrun_root', '')
if root != ''
return root
elseif exists('g:asyncrun_root') && g:asyncrun_root != ''
return g:asyncrun_root
elseif exists('g:asyncrun_locator')
let root = call(g:asyncrun_locator, [bid])
if root != ''
return root
endif
endif
if getbufvar(bid, '&buftype') != ''
let path = getcwd()
return asyncrun#fullname(path)
endif
elseif a:name == '%'
let path = a:name
if exists('b:asyncrun_root') && b:asyncrun_root != ''
return b:asyncrun_root
elseif exists('t:asyncrun_root') && t:asyncrun_root != ''
return t:asyncrun_root
elseif exists('g:asyncrun_root') && g:asyncrun_root != ''
return g:asyncrun_root
elseif exists('g:asyncrun_locator')
let root = call(g:asyncrun_locator, [])
let root = call(g:asyncrun_locator, [a:name])
if root != ''
return root
endif
endif
else
let path = printf('%s', a:name)
endif
let root = s:guess_root(a:path, a:markers)
let root = s:guess_root(path, a:markers)
if root != ''
return asyncrun#fullname(root)
elseif a:strict != 0
return ''
endif
" Not found: return parent directory of current file / file itself.
let fullname = asyncrun#fullname(a:path)
let fullname = asyncrun#fullname(path)
if isdirectory(fullname)
return fullname
endif
Expand Down Expand Up @@ -2315,7 +2337,7 @@ endfunc
" asyncrun - version
"----------------------------------------------------------------------
function! asyncrun#version()
return '2.12.9'
return '2.13.0'
endfunc


Expand Down
10 changes: 5 additions & 5 deletions plugin/script_load.vim
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,23 @@ endfunc
"----------------------------------------------------------------------
" detect current root
"----------------------------------------------------------------------
function! s:root_locator()
function! s:root_locator(name)
let root = ''
if exists('g:asyncrun_rooter')
if type(g:asyncrun_rooter) == type('')
let root = call(g:asyncrun_rooter, [])
let root = call(g:asyncrun_rooter, [a:name])
elseif type(g:asyncrun_rooter) == type({})
let test = keys(g:asyncrun_rooter)
call sort(test)
for name in test
let root = call(g:asyncrun_rooter[name], [])
let root = call(g:asyncrun_rooter[name], [a:name])
if root != ''
return root
endif
endfor
elseif type(g:asyncrun_rooter) == type([])
for index in range(len(g:asyncrun_rooter))
let root = call(g:asyncrun_rooter[index], [])
let root = call(g:asyncrun_rooter[index], [a:name])
if root != ''
return root
endif
Expand All @@ -136,7 +136,7 @@ function! s:root_locator()
return root
endif
endif
let root = asyncrun#locator#detect()
let root = asyncrun#locator#detect(a:name)
if root != '' && isdirectory(root)
return root
endif
Expand Down

0 comments on commit b098775

Please sign in to comment.