vscode icon indicating copy to clipboard operation
vscode copied to clipboard

`zsh` `shellIntegration.env` is undefined

Open meganrogge opened this issue 9 months ago • 2 comments

In working on a terminal suggest feature, which runs a script to fetch the installed extensions, I was noticing that the command would fail to run with exit code 1, which indicates it was not found on the path.

This was happening because shellIntegration.env was undefined for zsh. I have added fallback logic to use the process's environment which resolves this, but wanted to also document this as I believe it should be defined?

Image

cc @Tyriar

meganrogge avatar Mar 05 '25 20:03 meganrogge

Thanks for filing this. Is it just zsh that is giving undefined?

Since env shares and fires event through onDidChangeShellIntegration I'm wondering if it is a case where it will switch from undefined to the proper env later?

I'd love to provide the proper env for terminal suggest to make sure we have the best and updated info for env.

anthonykim1 avatar Mar 08 '25 00:03 anthonykim1

I was able to repro this but not consistently. I think what is happening is, we are sometimes trying to access shellIntegration.env before it is ready.

Adding

			vscode.window.onDidChangeTerminalShellIntegration((e) => {
				if (e.shellIntegration.env) {
					console.log(e);
				}
			})

before https://github.com/microsoft/vscode/blob/739de723a51dff7702ddbcc47fd45ca315911d4b/extensions/terminal-suggest/src/terminalSuggestMain.ts#L109 and debugging, it seems like .env is available towards the later part of all of the .onDidChangeTerminalShellIntegration that is being fired.

In debugging with adding the above referenced code and waiting a while before accessing shellIntegration.env I was successfully able to retrieve the .env value (for zsh)

Image

Perhaps I'm hoping we could wait a bit or add the subscription to the listener so then we can use the env from shellEnv API and apply to terminal suggest later when it is ready. Curious what you all think!

anthonykim1 avatar Mar 08 '25 01:03 anthonykim1