Skip to content

Commit b098775

Browse files
author
skywind3000
committed
asyncrun#get_root now accepts buffer number
1 parent 182c636 commit b098775

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

autoload/asyncrun/locator.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ endfunc
150150
"----------------------------------------------------------------------
151151
" root locator
152152
"----------------------------------------------------------------------
153-
function! asyncrun#locator#detect()
153+
function! asyncrun#locator#detect(name)
154154
if &bt == ''
155155
return asyncrun#locator#special_buffer_path()
156156
endif

plugin/asyncrun.vim

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
" Maintainer: skywind3000 (at) gmail.com, 2016-2024
44
" Homepage: https://github.com/skywind3000/asyncrun.vim
55
"
6-
" Last Modified: 2024/05/23 01:31
6+
" Last Modified: 2024/07/02 00:23
77
"
88
" Run shell command in background and output to quickfix:
99
" :AsyncRun[!] [options] {cmd} ...
@@ -1185,29 +1185,51 @@ function! s:guess_root(filename, markers)
11851185
endfunc
11861186

11871187
" find project root
1188-
function! s:find_root(path, markers, strict)
1189-
if a:path == '%'
1188+
function! s:find_root(name, markers, strict)
1189+
let path = ''
1190+
if type(a:name) == 0
1191+
let bid = (a:name < 0)? bufnr('%') : (a:name + 0)
1192+
let path = bufname(bid)
1193+
let root = getbufvar(bid, 'asyncrun_root', '')
1194+
if root != ''
1195+
return root
1196+
elseif exists('g:asyncrun_root') && g:asyncrun_root != ''
1197+
return g:asyncrun_root
1198+
elseif exists('g:asyncrun_locator')
1199+
let root = call(g:asyncrun_locator, [bid])
1200+
if root != ''
1201+
return root
1202+
endif
1203+
endif
1204+
if getbufvar(bid, '&buftype') != ''
1205+
let path = getcwd()
1206+
return asyncrun#fullname(path)
1207+
endif
1208+
elseif a:name == '%'
1209+
let path = a:name
11901210
if exists('b:asyncrun_root') && b:asyncrun_root != ''
11911211
return b:asyncrun_root
11921212
elseif exists('t:asyncrun_root') && t:asyncrun_root != ''
11931213
return t:asyncrun_root
11941214
elseif exists('g:asyncrun_root') && g:asyncrun_root != ''
11951215
return g:asyncrun_root
11961216
elseif exists('g:asyncrun_locator')
1197-
let root = call(g:asyncrun_locator, [])
1217+
let root = call(g:asyncrun_locator, [a:name])
11981218
if root != ''
11991219
return root
12001220
endif
12011221
endif
1222+
else
1223+
let path = printf('%s', a:name)
12021224
endif
1203-
let root = s:guess_root(a:path, a:markers)
1225+
let root = s:guess_root(path, a:markers)
12041226
if root != ''
12051227
return asyncrun#fullname(root)
12061228
elseif a:strict != 0
12071229
return ''
12081230
endif
12091231
" Not found: return parent directory of current file / file itself.
1210-
let fullname = asyncrun#fullname(a:path)
1232+
let fullname = asyncrun#fullname(path)
12111233
if isdirectory(fullname)
12121234
return fullname
12131235
endif
@@ -2315,7 +2337,7 @@ endfunc
23152337
" asyncrun - version
23162338
"----------------------------------------------------------------------
23172339
function! asyncrun#version()
2318-
return '2.12.9'
2340+
return '2.13.0'
23192341
endfunc
23202342

23212343

plugin/script_load.vim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,23 +110,23 @@ endfunc
110110
"----------------------------------------------------------------------
111111
" detect current root
112112
"----------------------------------------------------------------------
113-
function! s:root_locator()
113+
function! s:root_locator(name)
114114
let root = ''
115115
if exists('g:asyncrun_rooter')
116116
if type(g:asyncrun_rooter) == type('')
117-
let root = call(g:asyncrun_rooter, [])
117+
let root = call(g:asyncrun_rooter, [a:name])
118118
elseif type(g:asyncrun_rooter) == type({})
119119
let test = keys(g:asyncrun_rooter)
120120
call sort(test)
121121
for name in test
122-
let root = call(g:asyncrun_rooter[name], [])
122+
let root = call(g:asyncrun_rooter[name], [a:name])
123123
if root != ''
124124
return root
125125
endif
126126
endfor
127127
elseif type(g:asyncrun_rooter) == type([])
128128
for index in range(len(g:asyncrun_rooter))
129-
let root = call(g:asyncrun_rooter[index], [])
129+
let root = call(g:asyncrun_rooter[index], [a:name])
130130
if root != ''
131131
return root
132132
endif
@@ -136,7 +136,7 @@ function! s:root_locator()
136136
return root
137137
endif
138138
endif
139-
let root = asyncrun#locator#detect()
139+
let root = asyncrun#locator#detect(a:name)
140140
if root != '' && isdirectory(root)
141141
return root
142142
endif

0 commit comments

Comments
 (0)