Skip to content

Commit 8fa3a9e

Browse files
committed
fix: powershell special case
1 parent f922863 commit 8fa3a9e

3 files changed

Lines changed: 21 additions & 57 deletions

File tree

src/features/terminal/shellStartupSetupHandlers.ts

Lines changed: 13 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,27 @@ import { l10n } from 'vscode';
22
import { executeCommand } from '../../common/command.api';
33
import { Common, ShellStartupActivationStrings } from '../../common/localize';
44
import { traceInfo, traceVerbose } from '../../common/logging';
5+
import { isWindows } from '../../common/utils/platformUtils';
56
import { showErrorMessage, showInformationMessage } from '../../common/window.apis';
7+
import { ShellConstants } from '../common/shellConstants';
68
import { ShellScriptEditState, ShellStartupScriptProvider } from './shells/startupProvider';
79
import { getAutoActivationType, setAutoActivationType } from './utils';
810

9-
export async function handleSettingUpShellProfile(provider: ShellStartupScriptProvider): Promise<boolean> {
10-
const response = await showInformationMessage(
11-
l10n.t(
12-
'To use "{0}" activation, the shell profile for "{1}" shell needs to be set up. Do you want to set it up now?',
13-
'shellStartup',
14-
provider.shellType,
15-
),
16-
{ modal: true },
17-
Common.yes,
18-
Common.no,
19-
);
20-
if (response === Common.yes) {
21-
traceVerbose(`User chose to set up shell profile for ${provider.shellType} shell`);
22-
const state = await provider.setupScripts();
23-
24-
if (state === ShellScriptEditState.Edited) {
25-
setImmediate(async () => {
26-
await showInformationMessage(
27-
l10n.t(
28-
'Shell profile for "{0}" shell has been set up successfully. Extension will use shell startup activation next time a new terminal is created.',
29-
provider.shellType,
30-
),
31-
Common.ok,
32-
);
33-
});
11+
function getProviders(shellTypes: Set<string>, providers: ShellStartupScriptProvider[]): ShellStartupScriptProvider[] {
12+
return providers.filter((provider) => {
13+
if (isWindows() && shellTypes.has(ShellConstants.PWSH) && provider.shellType === 'powershell') {
3414
return true;
35-
} else if (state === ShellScriptEditState.NotEdited || state === ShellScriptEditState.NotInstalled) {
36-
setImmediate(async () => {
37-
const button = await showErrorMessage(
38-
l10n.t(
39-
'Failed to set up shell profile for "{0}" shell. Please check the output panel for more details.',
40-
provider.shellType,
41-
),
42-
Common.viewLogs,
43-
);
44-
if (button === Common.viewLogs) {
45-
await executeCommand('python-envs.viewLogs');
46-
}
47-
});
4815
}
49-
} else {
50-
traceVerbose(`User chose not to set up shell profile for ${provider.shellType} shell`);
51-
}
52-
return false;
16+
return shellTypes.has(provider.shellType);
17+
});
5318
}
5419

55-
export async function handleSettingUpShellProfileMultiple(
56-
providers: ShellStartupScriptProvider[],
20+
export async function handleSettingUpShellProfile(
21+
shellTypes: Set<string>,
22+
allProviders: ShellStartupScriptProvider[],
5723
callback: (provider: ShellStartupScriptProvider, result: boolean) => void,
5824
): Promise<void> {
25+
const providers = getProviders(shellTypes, allProviders);
5926
const shells = providers.map((p) => p.shellType).join(', ');
6027
const response = await showInformationMessage(
6128
l10n.t(
@@ -95,8 +62,8 @@ export async function handleSettingUpShellProfileMultiple(
9562
}
9663
}
9764

98-
export async function cleanupStartupScripts(shellStartupProviders: ShellStartupScriptProvider[]): Promise<void> {
99-
await Promise.all(shellStartupProviders.map((provider) => provider.teardownScripts()));
65+
export async function cleanupStartupScripts(allProviders: ShellStartupScriptProvider[]): Promise<void> {
66+
await Promise.all(allProviders.map((provider) => provider.teardownScripts()));
10067
if (getAutoActivationType() === 'shellStartup') {
10168
setAutoActivationType('command');
10269
traceInfo(

src/features/terminal/shells/pwsh/pwshStartup.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ export class PowerShellClassicStartupProvider implements ShellStartupScriptProvi
216216
async setupScripts(): Promise<ShellScriptEditState> {
217217
const isInstalled = await this.checkInstallation();
218218
if (!isInstalled) {
219-
traceVerbose('PowerShell is not installed');
220219
return ShellScriptEditState.NotInstalled;
221220
}
222221

@@ -267,7 +266,6 @@ export class PwshStartupProvider implements ShellStartupScriptProvider {
267266
async isSetup(): Promise<ShellSetupState> {
268267
const isInstalled = await this.checkInstallation();
269268
if (!isInstalled) {
270-
traceVerbose('PowerShell is not installed');
271269
return ShellSetupState.NotInstalled;
272270
}
273271

src/features/terminal/terminalManager.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { isActivatableEnvironment } from '../common/activation';
1515
import { identifyTerminalShell } from '../common/shellDetector';
1616
import { getPythonApi } from '../pythonApi';
1717
import { ShellEnvsProvider, ShellStartupScriptProvider } from './shells/startupProvider';
18-
import { handleSettingUpShellProfile, handleSettingUpShellProfileMultiple } from './shellStartupSetupHandlers';
18+
import { handleSettingUpShellProfile } from './shellStartupSetupHandlers';
1919
import {
2020
DidChangeTerminalActivationStateEvent,
2121
TerminalActivation,
@@ -112,9 +112,8 @@ export class TerminalManagerImpl implements TerminalManager {
112112
.map((t) => identifyTerminalShell(t))
113113
.filter((t) => t !== 'unknown'),
114114
);
115-
await handleSettingUpShellProfileMultiple(
116-
this.startupScriptProviders.filter((p) => shells.has(p.shellType)),
117-
(p, v) => this.shellSetup.set(p.shellType, v),
115+
await handleSettingUpShellProfile(shells, this.startupScriptProviders, (p, v) =>
116+
this.shellSetup.set(p.shellType, v),
118117
);
119118
}
120119
}
@@ -145,8 +144,9 @@ export class TerminalManagerImpl implements TerminalManager {
145144
traceVerbose(`Shell profile for ${shellType} is not setup, falling back to command activation`);
146145

147146
setImmediate(async () => {
148-
const result = await handleSettingUpShellProfile(provider);
149-
this.shellSetup.set(shellType, result);
147+
await handleSettingUpShellProfile(new Set([shellType]), this.startupScriptProviders, (p, v) =>
148+
this.shellSetup.set(p.shellType, v),
149+
);
150150
});
151151
return 'command';
152152
}
@@ -319,9 +319,8 @@ export class TerminalManagerImpl implements TerminalManager {
319319
.map((t) => identifyTerminalShell(t))
320320
.filter((t) => t !== 'unknown'),
321321
);
322-
await handleSettingUpShellProfileMultiple(
323-
this.startupScriptProviders.filter((p) => shells.has(p.shellType)),
324-
(p, v) => this.shellSetup.set(p.shellType, v),
322+
await handleSettingUpShellProfile(shells, this.startupScriptProviders, (p, v) =>
323+
this.shellSetup.set(p.shellType, v),
325324
);
326325
}
327326
}

0 commit comments

Comments
 (0)