diff --git a/autoload/go/fmt.vim b/autoload/go/fmt.vim index 2b358f3bd2..849e2ef773 100644 --- a/autoload/go/fmt.vim +++ b/autoload/go/fmt.vim @@ -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('%')) @@ -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. diff --git a/autoload/go/path.vim b/autoload/go/path.vim index 78c0aa396e..ec87e46965 100644 --- a/autoload/go/path.vim +++ b/autoload/go/path.vim @@ -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 @@ -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 @@ -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 to $(cygpath '') 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 diff --git a/autoload/go/util.vim b/autoload/go/util.vim index 1d818ea172..d35783f3ba 100644 --- a/autoload/go/util.vim +++ b/autoload/go/util.vim @@ -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. @@ -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