Skip to content

Commit

Permalink
path: return the unmodified GOPATH if autodetect is disabled
Browse files Browse the repository at this point in the history
fixes #1257
  • Loading branch information
fatih committed May 7, 2017
1 parent 1143f39 commit c609352
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions autoload/go/path.vim
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,16 @@ function! go#path#GoPath(...) abort
let $GOPATH = a:1
endfunction

" Default returns the default GOPATH. If there is a single GOPATH it returns
" it. For multiple GOPATHS separated with a the OS specific separator, only
" the first one is returned. If GOPATH is not set, it uses the default GOPATH
" set starting with GO 1.8. This GOPATH can be retrieved via 'go env GOPATH'
" Default returns the default GOPATH. If GOPATH is not set, it uses the
" default GOPATH set starting with Go 1.8. This GOPATH can be retrieved via
" 'go env GOPATH'
function! go#path#Default() abort
if $GOPATH == ""
" use default GOPATH via go env
return go#util#gopath()
endif

let go_paths = split($GOPATH, go#util#PathListSep())
if len(go_paths) == 1
return $GOPATH
endif

return go_paths[0]
return $GOPATH
endfunction

" HasPath checks whether the given path exists in GOPATH environment variable
Expand Down Expand Up @@ -134,8 +128,8 @@ function! go#path#BinPath() abort
elseif $GOBIN != ""
let bin_path = $GOBIN
else
" GOPATH (user set or default GO)
let bin_path = expand(go#path#Default() . "/bin/")
let go_paths = split(go#path#Default(), go#util#PathListSep())
let bin_path = expand(go_paths[0] . "/bin/")
endif

return bin_path
Expand Down

3 comments on commit c609352

@yohcop
Copy link

@yohcop yohcop commented on c609352 Jun 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit seems to be creating an issue for me. On every save, I get this error:

Error detected while processing function <SNR>41_fmt_autosave[3]..go#fmt#Format[40]..go#fmt#run[1]..<SNR>70_fmt_cmd[4]..go#path#CheckBinPath[7]..go#path#BinPath:                                                                                    
line   11:                                                                                                                                                                                                                                           
E684: list index out of range: 0                                                                                                                                                                                                                     
E116: Invalid arguments for function expand(go_paths[0] . "/bin/")

So... go_paths is empty?

This is the first commit that causes the problem (found via git bisect). The error happens at all the subsequent commits tested.

@fatih
Copy link
Owner Author

@fatih fatih commented on c609352 Jun 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please open a bug report with a small reproducible case and what GOPATH you use. There might be an edge case in your situation which is not covered by the code. I'm happy to look at it. Thanks

@yohcop
Copy link

@yohcop yohcop commented on c609352 Jun 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, see #1332. Thanks!

Please sign in to comment.