Skip to content

Commit

Permalink
Fix powershell core activation if executing scripts is not supported (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Raj authored Oct 25, 2023
1 parent 26b6255 commit fe22958
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
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

0 comments on commit fe22958

Please sign in to comment.