golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.86k stars 741 forks source link

Provide path to dot used by profile viewer #3339

Closed grgar closed 5 months ago

grgar commented 5 months ago

Without admin, I'm unable to install Graphviz's dot to one of the default system PATH directories, even though I have a dot available in my shell in the integrated terminal where I can set the PATH myself. I hit this error

https://github.com/golang/vscode-go/blob/9330b086651a8969c6a8b7a508cf3d8c37f1aae1/extension/src/goTest/profile.ts#L166

I would like to be able to specify the dot used by go tool pprof … that the extension calls when viewing a profile.

There appears to be two parts that would need to be affected:

  1. The extension's check of whether dot is available:

    https://github.com/golang/vscode-go/blob/9330b086651a8969c6a8b7a508cf3d8c37f1aae1/extension/src/goTest/profile.ts#L150

  2. The extension's invocation of go tool pprof:

    https://github.com/golang/vscode-go/blob/9330b086651a8969c6a8b7a508cf3d8c37f1aae1/extension/src/goTest/profile.ts#L173

While the former could be set from config, i.e. a config setting providing an absolute path to dot to use, the latter has no way of specifying which dot to use directly and just looks up dot in the PATH within Go code.

Therefore I am asking for the ability to specify a PATH for this extension's show function containing the above calls, so my own dot is available.

If this sounds sensible I can try a PR, or am I missing some other better way of doing this?

hyangah commented 5 months ago

I thought if you launch the code from your shell, vscode inherits the PATH env of the shell (and the extension also inherits vscode's PATH) Is it not true? If not, can you tell us more about your vscode launch flow and your environment?

grgar commented 5 months ago

That is indeed true and this does work, thanks! However, I'm on macOS, so this is a bit awkward because that's not how I usually open VS Code: using GUI means like Spotlight or Finder (opening files or dragging folders to the Dock icon). I guess this technically does work so I could use this if that is preferable over adding config.

hyangah commented 5 months ago

According to https://code.visualstudio.com/docs/terminal/advanced#_environment-inheritance

"When VS Code is opened, it launches a login shell environment in order to source a shell environment. This is done because developer tools are often added to the $PATH in a shell launch script like ~/.bash_profile."

Is it possible for you to adjust your login shell so the PATH is set up correctly? If you already did it, but vscode launched through GUI still doesn't get the path, I think it is a VS Code bug. (fyi, if you recently adjusted your login shell, make sure to completely stop vscode processes and restart vscode).

grgar commented 5 months ago

Aha thanks, that works!