Skip to content

support rename all file for go.mod project #2917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions autoload/go/lint.vim
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ function! go#lint#Vet(bang, ...) abort

let l:winid = win_getid(winnr())
let l:errorformat = "%-Gexit status %\\d%\\+," . &errorformat
let l:dir = getcwd()
call go#util#Chdir(expand('%:p:h'))
let l:dir = go#util#Chdir(expand('%:p:h'))
try
call go#list#ParseFormat(l:listtype, l:errorformat, out, "GoVet", 0)
finally
Expand Down
12 changes: 11 additions & 1 deletion autoload/go/rename.vim
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ function! go#rename#Rename(bang, ...) abort
return
endif

let [l:out, l:err] = go#util#ExecInDir(l:cmd)
let l:wd = go#util#ModuleRoot()
if l:wd == -1
let l:wd = expand("%:p:h")
endif

let [l:out, l:err] = go#util#ExecInWorkDir(l:cmd, l:wd)
call s:parse_errors(l:err, a:bang, split(l:out, '\n'))
endfunction

Expand All @@ -67,6 +72,11 @@ function s:rename_job(args)
call go#cmd#autowrite()
let l:cbs = go#job#Options(l:job_opts)

let l:wd = go#util#ModuleRoot()
if l:wd != -1
let l:cbs.cwd = l:wd
endif

" wrap l:cbs.exit_cb in s:exit_cb.
let l:cbs.exit_cb = funcref('s:exit_cb', [l:cbs.exit_cb])

Expand Down
22 changes: 15 additions & 7 deletions autoload/go/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,25 @@ function! go#util#Exec(cmd, ...) abort
return call('s:exec', [[l:bin] + a:cmd[1:]] + a:000)
endfunction

" ExecInDir will execute cmd with the working directory set to the current
" buffer's directory.
function! go#util#ExecInDir(cmd, ...) abort
if !isdirectory(expand("%:p:h"))
let l:wd = expand('%:p:h')
return call('go#util#ExecInWorkDir', [a:cmd, l:wd] + a:000)
endfunction

" ExecInWorkDir will execute cmd with the working diretory set to wd. Additional arguments will be passed
" to cmd.
function! go#util#ExecInWorkDir(cmd, wd, ...) abort
if !isdirectory(a:wd)
return ['', 1]
endif

let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
let dir = getcwd()
let l:dir = go#util#Chdir(a:wd)
try
execute cd . fnameescape(expand("%:p:h"))
let [l:out, l:err] = call('go#util#Exec', [a:cmd] + a:000)
finally
execute cd . fnameescape(l:dir)
call go#util#Chdir(l:dir)
endtry
return [l:out, l:err]
endfunction
Expand Down Expand Up @@ -687,11 +694,12 @@ endfunction

function! go#util#Chdir(dir) abort
if !exists('*chdir')
let l:olddir = getcwd()
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
execute cd . a:dir
return
return l:olddir
endif
call chdir(a:dir)
return chdir(a:dir)
endfunction

" restore Vi compatibility settings
Expand Down