Skip to content
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

Complement the path of command for different situations of Cygwin env… #1394

Merged
merged 1 commit into from
Aug 5, 2017
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
4 changes: 2 additions & 2 deletions autoload/go/fmt.vim
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function! go#fmt#Format(withGoimport) abort

let current_col = col('.')
let out = go#fmt#run(bin_name, l:tmpname, expand('%'))
let diff_offset = len(readfile(l:tmpname)) - line('$')
let diff_offset = len(readfile(l:tmpname)) - line('$')

if go#util#ShellError() == 0
call go#fmt#update_file(l:tmpname, expand('%'))
Expand Down Expand Up @@ -175,7 +175,7 @@ function! s:fmt_cmd(bin_name, source, target)
let bin_path = go#util#Shellescape(bin_path)
let cmd = [bin_path]
call add(cmd, "-w")

" add the options for binary (if any). go_fmt_options was by default of type
" string, however to allow customization it's now a dictionary of binary
" name mapping to options.
Expand Down
24 changes: 13 additions & 11 deletions autoload/go/path.vim
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function! go#path#Detect() abort
" for cases like GOPATH/src/foo/src/bar, pick up GOPATH/src instead of
" GOPATH/src/foo/src
let src_root = ""
if len(src_roots) > 0
if len(src_roots) > 0
let src_root = src_roots[-1]
endif

Expand Down Expand Up @@ -168,6 +168,11 @@ function! go#path#CheckBinPath(binpath) abort
let binpath = exepath(binpath)
endif
let $PATH = old_path

if go#util#IsUsingCygwinShell() == 1
return go#path#CygwinPath(binpath)
endif

return binpath
endif

Expand All @@ -184,18 +189,15 @@ function! go#path#CheckBinPath(binpath) abort

let $PATH = old_path

" When you are using:
" 1) Windows system
" 2) Has cygpath executable
" 3) Use *sh* as 'shell'
"
" This converts your <path> to $(cygpath '<path>') to make cygwin working in
" shell of cygwin way
if go#util#IsWin() && executable('cygpath') && &shell !~ '.*sh.*'
return printf("$(cygpath '%s')", a:bin_path)
endif
if go#util#IsUsingCygwinShell() == 1
return go#path#CygwinPath(a:binpath)
endif

return go_bin_path . go#util#PathSep() . basename
endfunction

function! go#path#CygwinPath(path)
return substitute(a:path, '\\', '/', "g")
endfunction

" vim: sw=2 ts=2 et
10 changes: 9 additions & 1 deletion autoload/go/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ function! go#util#IsWin() abort
return 0
endfunction

" Checks if using:
" 1) Windows system,
" 2) And has cygpath executable,
" 3) And uses *sh* as 'shell'
function! go#util#IsUsingCygwinShell()
return go#util#IsWin() && executable('cygpath') && &shell =~ '.*sh.*'
endfunction

function! go#util#has_job() abort
" job was introduced in 7.4.xxx however there are multiple bug fixes and one
" of the latest is 8.0.0087 which is required for a stable async API.
Expand Down Expand Up @@ -102,7 +110,7 @@ function! go#util#osarch() abort
return go#util#env("goos") . '_' . go#util#env("goarch")
endfunction

" System runs a shell command. If possible, it will temporary set
" System runs a shell command. If possible, it will temporary set
" the shell to /bin/sh for Unix-like systems providing a Bourne
" POSIX like environment.
function! go#util#System(str, ...) abort
Expand Down