From b6b61b8fe240d69d572ab2fff1db0ca4d4bebe2b Mon Sep 17 00:00:00 2001 From: HeeJae Chang Date: Tue, 3 Sep 2024 17:20:39 -0700 Subject: [PATCH] I fixed the Python extension failing in the virtual workspace on IInterpreterPathService. The root cause seems to be that `IDisposableRegistry` is now considered an array of services (after the Inversify update), and having one of the items with catch/then causes `Inversify` to think the service is being called with the wrong API (`get` instead of `getAsync`), throwing the following exception: > You are attempting to construct '" + key + "' in a synchronous way\n but it has asynchronous dependencies. Ideally, `IDisposableRegistry` should be an actual service rather than a type alias of `IDisposable[]`, but that would require too many changes. Instead, I fixed the item that goes into the `IDisposable[]`. That item (a mock) was considered a Promise because the mock automatically generates any symbol that is accessed. I bypassed `then` and `catch` by returning undefined, so it is no longer treated as a Promise. It would be nice if `IDisposableRegistry` became a real service at some point so this issue wouldn't occur again. --- src/client/extensionInit.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/client/extensionInit.ts b/src/client/extensionInit.ts index 851bc943cb8d..71f0cb1bacfd 100644 --- a/src/client/extensionInit.ts +++ b/src/client/extensionInit.ts @@ -30,6 +30,7 @@ import { IDiscoveryAPI } from './pythonEnvironments/base/locator'; import { registerLogger } from './logging'; import { OutputChannelLogger } from './logging/outputChannelLogger'; import { WorkspaceService } from './common/application/workspace'; +import { isString } from './common/utils/sysTypes'; // The code in this module should do nothing more complex than register // objects to DI and simple init (e.g. no side effects). That implies @@ -61,7 +62,7 @@ export function initializeGlobals( const unitTestOutChannel = workspaceService.isVirtualWorkspace || !workspaceService.isTrusted ? // Do not create any test related output UI when using virtual workspaces. - instance(mock()) + createTestOutputChannelMock() : window.createOutputChannel(OutputChannelNames.pythonTest); disposables.push(unitTestOutChannel); @@ -110,3 +111,18 @@ export async function initializeComponents(ext: ExtensionState): Promise()); + + return new Proxy(obj, { + get: (t, p) => { + if (isString(p) && ['then', 'catch'].includes(p)) { + return undefined; + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return (t as any)[p]; + }, + }); +}