direnv / direnv-vscode

unclutter your .profile
https://marketplace.visualstudio.com/items?itemName=mkhl.direnv
BSD Zero Clause License
166 stars 12 forks source link

Environment variable substitution doesn't work in settings.json #592

Open anoopknayak opened 1 year ago

anoopknayak commented 1 year ago

I have a vscode workspace with the workspace settings as follows:

{
  "go.toolsEnvVars": {
    "GO": "${env:GO}",
    "GOBIN": "${env:GOBIN}",
    "GONOPROXY": "${env:GONOPROXY}",
    "GOPATH": "${env:GOPATH}",
    "GOPRIVATE": "${env:GOPRIVATE}",
    "GOPROXY": "${env:GOPROXY}",
    "GOROOT": "${env:GOROOT}",
    "GOSUMDB": "${env:GOSUMDB}",
    "USE_ATHENS_GO_PROXY": "${env:USE_ATHENS_GO_PROXY}"
  },
  "go.goroot": "${env:GOROOT}"
}

direnv extension logs picks up the value correctly but the Go extension complains saying that ${env:GOROOT} is not a valid goroot.

Is direnv the first extension to start or can that be guaranteed in any way so that the environment variables are loaded before any other extension?

mkhl commented 1 year ago

Is direnv the first extension to start or can that be guaranteed in any way so that the environment variables are loaded before any other extension?

It cannot be guaranteed so it may well not be, see also #109 which is mainly about getting it to run as early as possible.

People have also shared a workaround there which I think was to open a different kind of file first, like markdown, so the go extension would run later?

That said I would have assumed that vscode resolves the settings before loading any extensions, in which case your snippet would actively prevent this extension from affecting the go extension. Do you think you might be able to check that?

anoopknayak commented 11 months ago

Do you think you might be able to check that?

Sorry, I missed replying to this. I'm not exactly sure how to check this. What I did currently was to look at the Extension Host logs. From that logs I see that the direnv extension is loading before golang extension (which is an improvement from last time I checked), but I still face the same issue. It looks like workspace settings.json never resolves the direnv variables and I assume it might be resolving the env vars before loading any extensions...

Output from extension host is as below:

2023-11-06 21:30:48.943 [info] ExtensionService#_doActivateExtension vscode.emmet, startup: false, activationEvent: 'onLanguage'
2023-11-06 21:30:48.952 [info] ExtensionService#_doActivateExtension mkhl.direnv, startup: false, activationEvent: 'onLanguage'
2023-11-06 21:30:48.992 [info] ExtensionService#_doActivateExtension vscode.git-base, startup: true, activationEvent: '*', root cause: vscode.git
2023-11-06 21:30:49.011 [info] ExtensionService#_doActivateExtension vscode.git, startup: true, activationEvent: '*'
2023-11-06 21:30:49.051 [info] ExtensionService#_doActivateExtension vscode.github, startup: true, activationEvent: '*'
2023-11-06 21:30:49.115 [info] ExtensionService#_doActivateExtension ms-vscode.makefile-tools, startup: true, activationEvent: 'workspaceContains:**/makefile,**/Makefile,**/GNUmakefile'
2023-11-06 21:30:49.142 [info] ExtensionService#_doActivateExtension golang.go, startup: true, activationEvent: 'workspaceContains:*.go,*/*.go,*/*/*.go'