From 75f3a03cb794d33299a621cb50dd3b59d753e291 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Wed, 5 May 2021 23:28:41 -0700 Subject: [PATCH] Do not retrigger discovery on change everytime --- src/client/extensionActivation.ts | 13 ++--------- src/client/pythonEnvironments/index.ts | 1 - src/client/pythonEnvironments/legacyIOC.ts | 25 ++++------------------ src/test/pythonEnvironments/legacyIOC.ts | 1 - 4 files changed, 6 insertions(+), 34 deletions(-) diff --git a/src/client/extensionActivation.ts b/src/client/extensionActivation.ts index 0292da87c1bb..fe7616bf2a70 100644 --- a/src/client/extensionActivation.ts +++ b/src/client/extensionActivation.ts @@ -6,11 +6,7 @@ import { CodeActionKind, debug, DebugConfigurationProvider, languages, OutputChannel, window } from 'vscode'; import { registerTypes as activationRegisterTypes } from './activation/serviceRegistry'; -import { - IExtensionActivationManager, - IExtensionSingleActivationService, - ILanguageServerExtension, -} from './activation/types'; +import { IExtensionActivationManager, ILanguageServerExtension } from './activation/types'; import { registerTypes as appRegisterTypes } from './application/serviceRegistry'; import { IApplicationDiagnostics } from './application/types'; import { DebugService } from './common/application/debugService'; @@ -35,7 +31,7 @@ import { IDebugSessionEventHandlers } from './debugger/extension/hooks/types'; import { registerTypes as debugConfigurationRegisterTypes } from './debugger/extension/serviceRegistry'; import { IDebugConfigurationService, IDebuggerBanner } from './debugger/extension/types'; import { registerTypes as formattersRegisterTypes } from './formatters/serviceRegistry'; -import { IComponentAdapter, IInterpreterService } from './interpreter/contracts'; +import { IInterpreterService } from './interpreter/contracts'; import { getLanguageConfiguration } from './language/languageConfiguration'; import { LinterCommands } from './linters/linterCommands'; import { registerTypes as lintersRegisterTypes } from './linters/serviceRegistry'; @@ -151,11 +147,6 @@ async function activateLegacy(ext: ExtensionState): Promise { // "initialize" "services" - // There's a bug now due to which IExtensionSingleActivationService is only activated in background. - // However for some cases particularly IComponentAdapter we need to block on activation before rest - // of the extension is activated. Hence explicitly activate it for now. - await serviceContainer.get(IComponentAdapter).activate(); - const interpreterManager = serviceContainer.get(IInterpreterService); interpreterManager.initialize(); diff --git a/src/client/pythonEnvironments/index.ts b/src/client/pythonEnvironments/index.ts index 8e7f59118161..36e829c95465 100644 --- a/src/client/pythonEnvironments/index.ts +++ b/src/client/pythonEnvironments/index.ts @@ -49,7 +49,6 @@ export async function initialize(ext: ExtensionState): Promise { interface IPythonEnvironments extends ILocator {} @injectable() -class ComponentAdapter implements IComponentAdapter, IExtensionSingleActivationService { +class ComponentAdapter implements IComponentAdapter { private readonly refreshing = new vscode.EventEmitter(); private readonly refreshed = new vscode.EventEmitter(); @@ -147,23 +147,8 @@ class ComponentAdapter implements IComponentAdapter, IExtensionSingleActivationS // The adapter only wraps one thing: the component API. private readonly api: IPythonEnvironments, private readonly environmentsSecurity: IEnvironmentsSecurity, - private readonly disposables: IDisposableRegistry, ) {} - public async activate(): Promise { - this.disposables.push( - this.api.onChanged((e) => { - const query = { - kinds: e.kind ? [e.kind] : undefined, - searchLocations: e.searchLocation ? { roots: [e.searchLocation] } : undefined, - ignoreCache: true, - }; - // Trigger a background refresh of the environments. - getEnvs(this.api.iterEnvs(query)).ignoreErrors(); - }), - ); - } - // For use in VirtualEnvironmentPrompt.activate() // Call callback if an environment gets created within the resource provided. @@ -437,11 +422,9 @@ export function registerNewDiscoveryForIOC( serviceManager: IServiceManager, api: IPythonEnvironments, environmentsSecurity: EnvironmentsSecurity, - disposables: IDisposableRegistry, ): void { serviceManager.addSingletonInstance( IComponentAdapter, - new ComponentAdapter(api, environmentsSecurity, disposables), + new ComponentAdapter(api, environmentsSecurity), ); - serviceManager.addBinding(IComponentAdapter, IExtensionSingleActivationService); } diff --git a/src/test/pythonEnvironments/legacyIOC.ts b/src/test/pythonEnvironments/legacyIOC.ts index b849bf8ec29f..7ba5f4c8167c 100644 --- a/src/test/pythonEnvironments/legacyIOC.ts +++ b/src/test/pythonEnvironments/legacyIOC.ts @@ -22,7 +22,6 @@ export async function registerForIOC( serviceManager, instance(mock(PythonEnvironments)), instance(mock(EnvironmentsSecurity)), - [], ); await registerLegacyDiscoveryForIOC(serviceManager); }