Skip to content

Commit f282cf1

Browse files
author
skywind3000
committed
Fix bug in asyncrun#locator#detect and add support for DiffviewFiles buffer type.
1 parent 061bf87 commit f282cf1

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

autoload/asyncrun/locator.vim

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,42 @@
88
"======================================================================
99

1010

11+
"----------------------------------------------------------------------
12+
" initialize
13+
"----------------------------------------------------------------------
14+
let s:windows = has('win32') || has('win64') || has('win16') || has('win95')
15+
16+
17+
"----------------------------------------------------------------------
18+
" special buffer
19+
"----------------------------------------------------------------------
20+
function! asyncrun#locator#special_buffer_path() abort
21+
if &bt != ''
22+
return ''
23+
endif
24+
let name = bufname('%')
25+
if name =~ '\v^fugitive\:[\\\/][\\\/][\\\/]'
26+
let path = strpart(name, s:windows? 12 : 11)
27+
let pos = stridx(path, '.git')
28+
if pos >= 0
29+
let path = strpart(path, 0, pos)
30+
endif
31+
return fnamemodify(path, ':h')
32+
elseif name =~ '^diffview:\/\/'
33+
let part = strpart(name, 11)
34+
let pos = stridx(part, '/.git/:')
35+
if pos > 0
36+
return strpart(part, 0, pos)
37+
endif
38+
endif
39+
return ''
40+
endfunc
41+
42+
1143
"----------------------------------------------------------------------
1244
" guess current buffer's directory
1345
"----------------------------------------------------------------------
14-
function! asyncrun#locator#nofile_buffer_path()
46+
function! asyncrun#locator#nofile_buffer_path() abort
1547
if &bt == ''
1648
return ''
1749
elseif &bt == 'nofile'
@@ -35,6 +67,11 @@ function! asyncrun#locator#nofile_buffer_path()
3567
return t
3668
catch
3769
endtry
70+
elseif &ft == 'DiffviewFiles' && has('nvim')
71+
let t = getline(1)
72+
if t != '' && isdirectory(t)
73+
return t
74+
endif
3875
endif
3976
if exists('b:git_dir')
4077
return b:git_dir
@@ -49,7 +86,7 @@ endfunc
4986
"----------------------------------------------------------------------
5087
function! asyncrun#locator#detect()
5188
if &bt == ''
52-
return ''
89+
return asyncrun#locator#special_buffer_path()
5390
endif
5491
let path = asyncrun#locator#nofile_buffer_path()
5592
if path != '' && (isdirectory(path) || filereadable(path))

0 commit comments

Comments
 (0)