Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Unable to use rename symbol #1449

Closed
jolivares opened this issue Jan 9, 2018 · 16 comments
Closed

Unable to use rename symbol #1449

jolivares opened this issue Jan 9, 2018 · 16 comments

Comments

@jolivares
Copy link

When trying to use the rename symbol functionality I get the following error:

Rename failed: cgo failed: [go tool cgo -objdir /var/folders/1w/1bqmnq8d6v99xf3kf_3yb_bm0000gn/T/net_C700673720 -- -I /var/folders/1w/1bqmnq8d6v99xf3kf_3yb_bm0000gn/T/net_C700673720 cgo_bsd.go cgo_resnew.go cgo_sockold.go cgo_unix.go]: exec: "go": executable file not found in $PATH cgo failed: [go tool cgo -objdir /var/folders/1w/1bqmnq8d6v99xf3kf_3yb_bm0000gn/T/crypto_x509_C158393015 -- -I /var/folders/1w/1bqmnq8d6v99xf3kf_3yb_bm0000gn/T/crypto_x509_C158393015 -mmacosx-version-min=10.6 -D__MAC_OS_X_VERSION_MAX_ALLOWED=1080 root_cgo_darwin.go]: exec: "go": executable file not found in $PATH cgo failed: [go tool cgo -objdir /var/folders/1w/1bqmnq8d6v99xf3kf_3yb_bm0000gn/T/os_user_C579732138 -- -I /var/folders/1w/1bqmnq8d6v99xf3kf_3yb_bm0000gn/T/os_user_C579732138 cgo_lookup_unix.go getgrouplist_darwin.go listgroups_unix.go]: exec: "go": executable file not found in $PATH gorename: couldn't load packages due to errors: os/user, crypto/x509, net 

It works ok if I use the command line:

$gorename -from '"github.com/jolivares/snapshot-downloader".xxxx' -to client -v
gorename -from '"github.com/jolivares/snapshot-downloader".xxxx' -to client -vgorename: -from spec: {pkg:github.com/jolivares/snapshot-downloader fromName:xxxx searchFor: pkgMember:xxxx typeMember: filename: offset:0}
gorename: Loading package: github.com/jolivares/snapshot-downloader
gorename: Updating package github.com/jolivares/snapshot-downloader
Renamed 2 occurrences in 1 file in 1 package.

Other tools like gofmt, golint... works ok.

Go: Current GOPATH output: Current GOPATH: /Users/juanolivares/workspaces/go-programs
go env output:

go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/juanolivares/workspaces/go-programs"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/1w/1bqmnq8d6v99xf3kf_3yb_bm0000gn/T/go-build025874502=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

pwd output:
/Users/juanolivares/workspaces/go-programs/src/github.com/jolivares/snapshot-downloader

@ramya-rao-a
Copy link
Contributor

Can you try the -offset flag (which the Go extension uses when calling gorename) instead of -from flag in the command line and see if that works as well?

@jolivares
Copy link
Author

jolivares commented Jan 10, 2018

It works ok:

$ gorename -offset downloader.go:#600 -to mySuperClient -v
gorename: Loading package: github.com/jolivares/snapshot-downloader
gorename: Updating package github.com/jolivares/snapshot-downloader
Renamed 2 occurrences in 1 file in 1 package.

@ramya-rao-a
Copy link
Contributor

The error you are seeing is coming from gorename when it is run by the Go extension.
Looks like gorename tries to run go tool cgo which fails with exec: "go": executable file not found in $PATH

Your Go executable seems to be in /usr/local/Cellar/go/1.9.2/libexec/bin. Is this part of your $PATH?

@jolivares
Copy link
Author

Definitely I'm missing something. If I type go in my console it works. If I run which go it outputs /usr/local/Cellar/go/1.9.2/libexec/bin. I'm using fishshell. I tried same thing with bash and it works too. So basically, I added go to PATH in:

  • .bash_profile
  • .config/fish/config.fish
  • /etc/paths.d
    but visual studio code keeps complaining it cannot find go. Is there any other place I need to modify PATH env var?

@jolivares
Copy link
Author

jolivares commented Jan 11, 2018

I've just come across this: https://stackoverflow.com/questions/43983718/set-global-path-environment-variable-in-vs-code
After trying process.env.PATH in the developer tools I got: "/usr/bin:/bin:/usr/sbin:/sbin", no idea why this path is different from what I get from other sources.

BTW the visual studio code embedded terminal is working ok: it has go its path

@ramya-rao-a
Copy link
Contributor

How do you usually open vscode? Do you open it from the fish shell?
If yes, then can you open vscode from the bash shell and see if renaming works there?
We have had cases where from when VS Code is opened from certain shells, the env variables do not reach the extensions

@jolivares
Copy link
Author

I usually open it from the Dock. I've tried opening it from both shells (fish and bash) but none of them work. In all of the cases I got "/usr/bin:/bin:/usr/sbin:/sbin" when I run process.env.PATH from the Developer Tools.

@ramya-rao-a
Copy link
Contributor

A workaround until we figure this out is to add "go.goroot": "/usr/local/Cellar/go/1.9.2/libexec" in your settings. Can you see if that helps?

@jolivares
Copy link
Author

go.goroot It's already set in my user settings. Is there any way to debug visual studio code or the go extension to check why PATH variable is not properly set?

@ramya-rao-a
Copy link
Contributor

VS Code has 3 kinds of processes

  • 1 main process
  • multiple renderer processes (1 for each VS Code window that you open)
  • multiple extension host processes ( 1 for each VS Code window that you open)

The main process spawns the renderer process which in turn spawns the extension host process.
Its the extension host process which runs all the extensions.

When you open the Developer Tools and look for process.env.PATH, its the renderer process that you are looking at. This renderer process doesnt seem to get the right env vars, and since the extension host process is the child of the renderer process, it wont get the right env vars too.

I would suggest to open an issue in the vscode repo for the problem of env vars not reaching the renderer process

Meanwhile, for the Go extension I have pushed a fix that will ensure that the GOROOT is part of the PATH when the Go extension calls the dependent Go tools. Can you give this a try and see if this helps?

@jolivares
Copy link
Author

It finally works! 🎉 . Thanks a lot for your fix.

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Jan 14, 2018

Thats good to hear @jolivares
The fix applies to the processes that the Go extension starts.
The renderer process still doesn't get the right env variables (which you found by checking the value of process.env.PATH in the developer tools).
Can you log an issue for that in the vscode repo?

@jolivares
Copy link
Author

I was about to report the issue in the vscode repo when I realised that now I get the proper PATH contents when typing process.env.PATH. I'm not sure what has happened 🤔

@ramya-rao-a
Copy link
Contributor

well, if you ever encounter it again, please log the issue

Happy Coding!

@njgraf512
Copy link

njgraf512 commented Jan 29, 2018

@jolivares, @ramya-rao-a, thanks for your help with this issue. I had exactly the same problem, and this solved it. Note: my provess.env.PATH also updated after running code --install-extension Go-latest.vsix and restarting 😀

@ramya-rao-a
Copy link
Contributor

Just released an update (0.6.74) that has the fix for this issue. Thanks for your patience everyone!

@vscodebot vscodebot bot locked and limited conversation to collaborators Feb 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants