Skip to content

Commit 7e6d4aa

Browse files
committed
fix: powershell script update by querying $profile
1 parent aadffa0 commit 7e6d4aa

17 files changed

Lines changed: 198 additions & 138 deletions

File tree

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
3131
"skipFiles": ["<node_internals>/**"],
3232
"outFiles": ["${workspaceFolder}/out/**/*.js", "!${workspaceFolder}/**/node_modules**/*"],
33-
"preLaunchTask": "tasks: watch-tests"
33+
"preLaunchTask": "${defaultBuildTask}"
3434
},
3535
{
3636
"name": "Extension Tests",
@@ -41,7 +41,7 @@
4141
"--extensionTestsPath=${workspaceFolder}/out/test/"
4242
],
4343
"outFiles": ["${workspaceFolder}/out/**/*.js", "${workspaceFolder}/dist/**/*.js"],
44-
"preLaunchTask": "tasks: watch-tests"
44+
"preLaunchTask": "${defaultBuildTask}"
4545
}
4646
]
4747
}

.vscode/tasks.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
"presentation": {
1212
"reveal": "never",
1313
"group": "watchers"
14-
},
15-
"group": {
16-
"kind": "build",
17-
"isDefault": true
1814
}
1915
},
2016
{
@@ -25,13 +21,20 @@
2521
"presentation": {
2622
"reveal": "never",
2723
"group": "watchers"
28-
},
29-
"group": "build"
24+
}
3025
},
3126
{
32-
"label": "tasks: watch-tests",
27+
"label": "tasks: build",
3328
"dependsOn": ["npm: watch", "npm: watch-tests"],
34-
"problemMatcher": []
29+
"problemMatcher": [],
30+
"presentation": {
31+
"reveal": "never",
32+
"group": "watchers"
33+
},
34+
"group": {
35+
"kind": "build",
36+
"isDefault": true
37+
}
3538
},
3639
{
3740
"type": "npm",

src/common/commands.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export namespace Commands {
2+
export const viewLogs = 'python-envs.viewLogs';
3+
}

src/common/errors/utils.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as stackTrace from 'stack-trace';
2-
import { commands, LogOutputChannel, window } from 'vscode';
2+
import { commands, LogOutputChannel } from 'vscode';
33
import { Common } from '../localize';
4+
import { showErrorMessage, showWarningMessage } from '../window.apis';
45

56
export function parseStack(ex: Error) {
67
if (ex.stack && Array.isArray(ex.stack)) {
@@ -10,8 +11,8 @@ export function parseStack(ex: Error) {
1011
return stackTrace.parse.call(stackTrace, ex);
1112
}
1213

13-
export async function showErrorMessage(message: string, log?: LogOutputChannel) {
14-
const result = await window.showErrorMessage(message, Common.viewLogs);
14+
export async function showErrorMessageWithLogs(message: string, log?: LogOutputChannel) {
15+
const result = await showErrorMessage(message, Common.viewLogs);
1516
if (result === Common.viewLogs) {
1617
if (log) {
1718
log.show();
@@ -21,8 +22,8 @@ export async function showErrorMessage(message: string, log?: LogOutputChannel)
2122
}
2223
}
2324

24-
export async function showWarningMessage(message: string, log?: LogOutputChannel) {
25-
const result = await window.showWarningMessage(message, Common.viewLogs);
25+
export async function showWarningMessageWithLogs(message: string, log?: LogOutputChannel) {
26+
const result = await showWarningMessage(message, Common.viewLogs);
2627
if (result === Common.viewLogs) {
2728
if (log) {
2829
log.show();

src/common/localize.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { l10n } from 'vscode';
2+
import { Commands } from './commands';
23

34
export namespace Common {
45
export const recommended = l10n.t('Recommended');
@@ -147,10 +148,20 @@ export namespace EnvViewStrings {
147148

148149
export namespace ShellStartupActivationStrings {
149150
export const shellStartupScriptEditPrompt = l10n.t(
150-
'To support `shellStartup` we need to modify your shell profile. Do you want to proceed?',
151+
'To support Python Terminal activation using `shellStartup` we need to modify your shell profile. Do you want to proceed?',
151152
);
153+
export const updatingTheseProfiles = l10n.t('Updating these profiles');
152154
export const updateScript = l10n.t('Update Shell Profile');
153155
export const revertToCommandActivation = l10n.t(
154156
'Auto Shell Activation type set to "command", due to removing shell startup from profile.',
155157
);
158+
export const envCollectionDescription = l10n.t('Environment variables for shell activation');
159+
export const shellStartupScriptEditComplete = l10n.t(
160+
'Shell startup profile updated. See [logs](command:{0})',
161+
Commands.viewLogs,
162+
);
163+
export const shellStartupScriptEditFailed = l10n.t(
164+
'Failed to update shell startup profile. See [logs](command:{0})',
165+
Commands.viewLogs,
166+
);
156167
}

src/common/utils/pythonPath.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Uri, Progress, CancellationToken } from 'vscode';
22
import { PythonEnvironment } from '../../api';
33
import { InternalEnvironmentManager } from '../../internal.api';
4-
import { showErrorMessage } from '../errors/utils';
54
import { traceVerbose, traceError } from '../logging';
65
import { PYTHON_EXTENSION_ID } from '../constants';
6+
import { showErrorMessage } from '../window.apis';
77

88
const priorityOrder = [
99
`${PYTHON_EXTENSION_ID}:pyenv`,

src/common/window.apis.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,21 @@ export function showInformationMessage<T extends MessageItem>(
301301
return window.showInformationMessage(message, options, ...items);
302302
}
303303

304+
export function showErrorMessage<T extends string>(message: string, ...items: T[]): Thenable<T | undefined>;
305+
export function showErrorMessage<T extends MessageItem>(message: string, ...items: T[]): Thenable<T | undefined>;
306+
export function showErrorMessage<T extends string>(
307+
message: string,
308+
options: MessageOptions,
309+
...items: T[]
310+
): Thenable<T | undefined>;
311+
export function showErrorMessage<T extends MessageItem>(
312+
message: string,
313+
options: MessageOptions,
314+
...items: T[]
315+
): Thenable<T | undefined> {
316+
return window.showErrorMessage(message, options, ...items);
317+
}
318+
304319
export function showWarningMessage(message: string, ...items: string[]): Thenable<string | undefined> {
305320
return window.showWarningMessage(message, ...items);
306321
}

src/features/creators/autoFindProjects.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import * as path from 'path';
22
import { Uri } from 'vscode';
3-
import { showQuickPickWithButtons } from '../../common/window.apis';
3+
import { showErrorMessage, showQuickPickWithButtons } from '../../common/window.apis';
44
import { ProjectCreatorString } from '../../common/localize';
55
import { PythonProject, PythonProjectCreator, PythonProjectCreatorOptions } from '../../api';
66
import { PythonProjectManager } from '../../internal.api';
7-
import { showErrorMessage } from '../../common/errors/utils';
87
import { findFiles } from '../../common/workspace.apis';
98

109
function getUniqueUri(uris: Uri[]): {

src/features/envCommands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ import { pickProject, pickProjectMany } from '../common/pickers/projects';
4141
import { TerminalManager } from './terminal/terminalManager';
4242
import { runInTerminal } from './terminal/runInTerminal';
4343
import { quoteArgs } from './execution/execUtils';
44-
import { showErrorMessage } from '../common/errors/utils';
45-
import { activeTextEditor } from '../common/window.apis';
44+
import {} from '../common/errors/utils';
45+
import { activeTextEditor, showErrorMessage } from '../common/window.apis';
4646
import { clipboardWriteText } from '../common/env.apis';
4747

4848
export async function refreshManagerCommand(context: unknown): Promise<void> {

src/features/terminal/startup/activateUsingShellStartup.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { DidChangeEnvironmentEventArgs } from '../../../api';
66
import { EnvironmentManagers } from '../../../internal.api';
77
import { traceError, traceInfo } from '../../../common/logging';
88
import { ShellStartupActivationStrings } from '../../../common/localize';
9-
import { showInformationMessage } from '../../../common/window.apis';
9+
import { showErrorMessage, showInformationMessage } from '../../../common/window.apis';
1010

1111
export interface ShellStartupActivationManager extends Disposable {
1212
initialize(): Promise<void>;
@@ -21,6 +21,7 @@ export class ShellStartupActivationManagerImpl implements ShellStartupActivation
2121
private readonly shellStartupProviders: ShellStartupProvider[],
2222
private readonly em: EnvironmentManagers,
2323
) {
24+
this.envCollection.description = ShellStartupActivationStrings.envCollectionDescription;
2425
this.disposables.push(
2526
onDidChangeConfiguration((e: ConfigurationChangeEvent) => {
2627
this.handleConfigurationChange(e);
@@ -93,9 +94,10 @@ export class ShellStartupActivationManagerImpl implements ShellStartupActivation
9394
const autoActType = getAutoActivationType();
9495
if (autoActType === 'shellStartup') {
9596
if (await this.isSetupRequired()) {
97+
const shells = this.shellStartupProviders.map((provider) => provider.name).join(', ');
9698
const result = await showInformationMessage(
9799
ShellStartupActivationStrings.shellStartupScriptEditPrompt,
98-
{ modal: true },
100+
{ modal: true, detail: `${ShellStartupActivationStrings.updatingTheseProfiles}: ${shells}` },
99101
ShellStartupActivationStrings.updateScript,
100102
);
101103

@@ -143,7 +145,25 @@ export class ShellStartupActivationManagerImpl implements ShellStartupActivation
143145
}
144146

145147
public async updateStartupScripts(): Promise<void> {
146-
await Promise.all(this.shellStartupProviders.map((provider) => provider.setupScripts()));
148+
const results = await Promise.all(
149+
this.shellStartupProviders.map(async (provider) => {
150+
const result = await provider.setupScripts();
151+
if (!result) {
152+
traceError(`Failed to setup shell startup scripts for ${provider.name}`);
153+
}
154+
return result;
155+
}),
156+
);
157+
158+
const success = results.every((result) => result);
159+
160+
// Intentionally not awaiting this message. We don’t need a response here, and awaiting here for user response can
161+
// block setting up rest of the startup activation.
162+
if (success) {
163+
showInformationMessage(ShellStartupActivationStrings.shellStartupScriptEditComplete);
164+
} else {
165+
showErrorMessage(ShellStartupActivationStrings.shellStartupScriptEditFailed);
166+
}
147167
}
148168

149169
public async cleanupStartupScripts(): Promise<void> {

0 commit comments

Comments
 (0)