From b0987750dddf0ee678d160fe50e3d5397cd0c9e9 Mon Sep 17 00:00:00 2001 From: skywind3000 Date: Tue, 2 Jul 2024 00:39:58 +0800 Subject: [PATCH] asyncrun#get_root now accepts buffer number --- autoload/asyncrun/locator.vim | 2 +- plugin/asyncrun.vim | 36 ++++++++++++++++++++++++++++------- plugin/script_load.vim | 10 +++++----- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/autoload/asyncrun/locator.vim b/autoload/asyncrun/locator.vim index 7a7a85b..dda9c60 100644 --- a/autoload/asyncrun/locator.vim +++ b/autoload/asyncrun/locator.vim @@ -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 diff --git a/plugin/asyncrun.vim b/plugin/asyncrun.vim index a8388da..87795d8 100644 --- a/plugin/asyncrun.vim +++ b/plugin/asyncrun.vim @@ -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} ... @@ -1185,8 +1185,28 @@ 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 != '' @@ -1194,20 +1214,22 @@ function! s:find_root(path, markers, strict) 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 @@ -2315,7 +2337,7 @@ endfunc " asyncrun - version "---------------------------------------------------------------------- function! asyncrun#version() - return '2.12.9' + return '2.13.0' endfunc diff --git a/plugin/script_load.vim b/plugin/script_load.vim index 53f8e6b..1833689 100644 --- a/plugin/script_load.vim +++ b/plugin/script_load.vim @@ -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 @@ -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