Skip to content

Un-register extension between steps to prevent cascading test failures #5227

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export async function activate(
externalApi.unregisterExternalExtension(uuid),
getPowerShellVersionDetails: (uuid) =>
externalApi.getPowerShellVersionDetails(uuid),
getRegisteredExtensions: () => externalApi.getRegisteredExtensions(),
waitUntilStarted: (uuid) => externalApi.waitUntilStarted(uuid),
getStorageUri: () => externalApi.getStorageUri(),
getLogUri: () => externalApi.getLogUri(),
Expand Down
16 changes: 16 additions & 0 deletions src/features/ExternalApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface IPowerShellExtensionClient {
getPowerShellVersionDetails(
uuid: string,
): Promise<IExternalPowerShellDetails>;
getRegisteredExtensions(): Map<string, IExternalExtension>;
waitUntilStarted(uuid: string): Promise<void>;
getStorageUri(): vscode.Uri;
getLogUri(): vscode.Uri;
Expand Down Expand Up @@ -135,6 +136,21 @@ export class ExternalApiFeature implements IPowerShellExtensionClient {
return ExternalApiFeature.registeredExternalExtension.get(uuid)!;
}

/*
DESCRIPTION:
returns a map of all registered extensions that have registered.

USAGE:
powerShellExtensionClient.getRegisteredExtensions();

RETURNS:
a map containing the UUID as the key and an IExternalExtension showing
the extension id and api version.
*/
public getRegisteredExtensions(): Map<string, IExternalExtension> {
return ExternalApiFeature.registeredExternalExtension;
}

/*
DESCRIPTION:
This will fetch the version details of the PowerShell used to start
Expand Down
9 changes: 9 additions & 0 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ export async function ensureExtensionIsActivated(): Promise<IPowerShellExtension

export async function ensureEditorServicesIsConnected(): Promise<IPowerShellExtensionClient> {
const extension = await ensureExtensionIsActivated();
for (const [
_name,
externalExtension,
] of extension.getRegisteredExtensions().entries()) {
if (externalExtension.id === extensionId) {
extension.unregisterExternalExtension(_name);
}
};
Copy link
Preview

Copilot AI Jun 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] There is an unnecessary semicolon after the for loop block; removing it would improve code readability.

Suggested change
};
}

Copilot uses AI. Check for mistakes.


const sessionId = extension.registerExternalExtension(extensionId);
await extension.waitUntilStarted(sessionId);
extension.unregisterExternalExtension(sessionId);
Expand Down