Skip to content

Commit 2151164

Browse files
edvilmeCopilot
andcommitted
fix: address PR review comments
- Wrap promptInstallExtensionIfMissing with void/.catch for unhandled rejections - Attempt activation post-timeout when extension is installed but inactive - Fix question punctuation (period → question mark) - Deduplicate install prompts per extension ID per session via prompted Set Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6857c59 commit 2151164

1 file changed

Lines changed: 30 additions & 8 deletions

File tree

src/features/common/managerReady.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ export function withManagerTimeout(
5555
managerKind: kind,
5656
});
5757
deferred.resolve();
58-
promptInstallExtensionIfMissing(managerId);
58+
void promptInstallExtensionIfMissing(managerId).catch((err) => {
59+
traceError(`Failed to prompt installation for manager extension "${managerId}".`, err);
60+
});
5961
}
6062
}, MANAGER_READY_TIMEOUT_MS);
6163

@@ -75,8 +77,10 @@ export function withManagerTimeout(
7577
/**
7678
* Shows an install prompt only if the extension for the given manager ID
7779
* is genuinely not available. Called after the timeout expires, giving the
78-
* extension host ample time to initialize.
80+
* extension host ample time to initialize. Deduplicated per extension ID
81+
* so each missing extension only prompts once per session.
7982
*/
83+
const prompted: Set<string> = new Set();
8084
async function promptInstallExtensionIfMissing(managerId: string): Promise<void> {
8185
const extId = getExtensionId(managerId);
8286
if (!extId) {
@@ -87,17 +91,34 @@ async function promptInstallExtensionIfMissing(managerId: string): Promise<void>
8791
const ext = getExtension(extId);
8892
if (ext) {
8993
// Extension is installed but the manager never registered — don't prompt to install.
90-
// This can happen if the extension activated but failed to register its manager.
91-
traceWarn(
92-
`Extension ${extId} is installed but manager "${managerId}" never registered. ` +
93-
`The extension may have failed during activation or manager registration.`,
94-
);
94+
// Attempt activation as a recovery step since the extension host is reliable at this point.
95+
if (!ext.isActive) {
96+
traceWarn(
97+
`Extension ${extId} is installed but manager "${managerId}" never registered. Attempting activation...`,
98+
);
99+
try {
100+
await ext.activate();
101+
traceInfo(`Extension ${extId} activated post-timeout for manager "${managerId}".`);
102+
} catch (err) {
103+
traceError(`Failed to activate extension ${extId} post-timeout for: ${managerId}`, err);
104+
}
105+
} else {
106+
traceWarn(
107+
`Extension ${extId} is installed and active but manager "${managerId}" never registered. ` +
108+
`The extension may have failed during manager registration.`,
109+
);
110+
}
111+
return;
112+
}
113+
114+
if (prompted.has(extId)) {
95115
return;
96116
}
117+
prompted.add(extId);
97118

98119
traceError(`Extension for manager ${managerId} is not installed. Looked up extId="${extId}" via getExtension().`);
99120
const result = await showErrorMessage(
100-
l10n.t(`Do you want to install extension {0} to enable {1} support.`, extId, managerId),
121+
l10n.t(`Do you want to install extension {0} to enable {1} support?`, extId, managerId),
101122
WorkbenchStrings.installExtension,
102123
);
103124
if (result === WorkbenchStrings.installExtension) {
@@ -284,6 +305,7 @@ export function createManagerReady(em: EnvironmentManagers, pm: PythonProjectMan
284305
*/
285306
export function _resetManagerReadyForTesting(): void {
286307
_deferred = createDeferred<ManagerReady>();
308+
prompted.clear();
287309
}
288310

289311
export async function waitForEnvManager(uris?: Uri[]): Promise<void> {

0 commit comments

Comments
 (0)