Skip to content

Commit

Permalink
Fix crashing when chdir function doesn't exist
Browse files Browse the repository at this point in the history
Fixes arp242#50
  • Loading branch information
acomagu committed Jan 28, 2021
1 parent a758784 commit 83b8988
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions autoload/gopher/go.vim
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ fun! gopher#go#module() abort
let l:wd = getcwd()

try
call chdir(expand('%:h'))
call gopher#system#cd(expand('%:h'))
let [l:out, l:err] = gopher#system#run(['go', 'list', '-m', '-f',
\ "{{.Path}}\x01{{.Dir}}"])
if l:err
return [-1, -1]
endif
return split(l:out, "\x01")
finally
call chdir(l:wd)
call gopher#system#cd(l:wd)
endtry
endfun

Expand Down
9 changes: 9 additions & 0 deletions autoload/gopher/system.vim
Original file line number Diff line number Diff line change
Expand Up @@ -499,5 +499,14 @@ fun! gopher#system#closest(name) abort
endwhile
endfun

" Change the current directory to path.
fun! gophor#system#cd(path) abort
if exists('*chdir')
call chdir(a:path)
else
silent execute 'lcd' fnameescape(a:path)
endif
endfun


call s:init() " At end so entire file is parsed.

0 comments on commit 83b8988

Please sign in to comment.