Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix powershell core activation if executing scripts is not supported #22350

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/client/terminals/envCollectionActivation/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
this,
this.disposables,
);
const isActive = this.isShellIntegrationActive();
if (!isActive) {
const { shell } = this.applicationEnvironment;
const isActive = this.isShellIntegrationActive(shell);
const shellType = identifyShellFromShellPath(shell);
if (!isActive && shellType !== TerminalShellType.commandPrompt) {
traceWarn(`Shell integration is not active, environment activated maybe overriden by the shell.`);
}
this.registeredOnce = true;
Expand Down Expand Up @@ -182,7 +184,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ

// PS1 in some cases is a shell variable (not an env variable) so "env" might not contain it, calculate it in that case.
env.PS1 = await this.getPS1(shell, resource, env);
const prependOptions = this.getPrependOptions();
const prependOptions = this.getPrependOptions(shell);

// Clear any previously set env vars from collection
envVarCollection.clear();
Expand Down Expand Up @@ -275,7 +277,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
// PS1 should be set but no PS1 was set.
return;
}
const config = this.isShellIntegrationActive();
const config = this.isShellIntegrationActive(shell);
if (!config) {
traceVerbose('PS1 is not set when shell integration is disabled.');
return;
Expand Down Expand Up @@ -330,8 +332,8 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
}
}

private getPrependOptions(): EnvironmentVariableMutatorOptions {
const isActive = this.isShellIntegrationActive();
private getPrependOptions(shell: string): EnvironmentVariableMutatorOptions {
const isActive = this.isShellIntegrationActive(shell);
// Ideally we would want to prepend exactly once, either at shell integration or process creation.
// TODO: Stop prepending altogether once https://github.com/microsoft/vscode/issues/145234 is available.
return isActive
Expand All @@ -345,14 +347,11 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
};
}

private isShellIntegrationActive(): boolean {
private isShellIntegrationActive(shell: string): boolean {
const isEnabled = this.workspaceService
.getConfiguration('terminal')
.get<boolean>('integrated.shellIntegration.enabled')!;
if (
isEnabled &&
ShellIntegrationShells.includes(identifyShellFromShellPath(this.applicationEnvironment.shell))
) {
if (isEnabled && ShellIntegrationShells.includes(identifyShellFromShellPath(shell))) {
// Unfortunately shell integration could still've failed in remote scenarios, we can't know for sure:
// https://code.visualstudio.com/docs/terminal/shell-integration#_automatic-script-injection
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { TerminalShellType } from '../../common/terminal/types';
* https://code.visualstudio.com/docs/terminal/shell-integration
*/
export const ShellIntegrationShells = [
TerminalShellType.commandPrompt, // Shell integration is not supported, but is also not needed to activate the env.
TerminalShellType.powershell,
TerminalShellType.powershellCore,
TerminalShellType.bash,
Expand Down