Skip to content

Commit

Permalink
Use sync initialization where possible (#12458)
Browse files Browse the repository at this point in the history
* Use sync initialization where possible

* Fix tests
  • Loading branch information
DonJayamanne authored Dec 29, 2022
1 parent da4eb4d commit 91a3a3a
Show file tree
Hide file tree
Showing 55 changed files with 568 additions and 530 deletions.
6 changes: 3 additions & 3 deletions src/interactive-window/commands/commandRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import { IDataScienceCodeLensProvider, ICodeWatcher } from '../editor-integratio
import { IInteractiveWindowProvider } from '../types';
import * as urlPath from '../../platform/vscode-path/resources';
import { getDisplayPath, getFilePath } from '../../platform/common/platform/fs-paths';
import { IExtensionSingleActivationService } from '../../platform/activation/types';
import { IExtensionSyncActivationService } from '../../platform/activation/types';
import { ExportFormat, IExportDialog, IFileConverter } from '../../notebooks/export/types';
import { openAndShowNotebook } from '../../platform/common/utils/notebooks';
import { JupyterInstallError } from '../../platform/errors/jupyterInstallError';
Expand All @@ -64,7 +64,7 @@ import { StatusProvider } from './statusProvider';
* Class that registers command handlers for interactive window commands.
*/
@injectable()
export class CommandRegistry implements IDisposable, IExtensionSingleActivationService {
export class CommandRegistry implements IDisposable, IExtensionSyncActivationService {
private readonly statusProvider: StatusProvider;
constructor(
@inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry,
Expand Down Expand Up @@ -98,7 +98,7 @@ export class CommandRegistry implements IDisposable, IExtensionSingleActivationS
this.workspace.onDidGrantWorkspaceTrust(this.registerCommandsIfTrusted, this, this.disposables);
}
}
public async activate(): Promise<void> {
public activate() {
this.registerCommandsIfTrusted();
this.registerCommand(Commands.InsertCellBelowPosition, this.insertCellBelowPosition);
this.registerCommand(Commands.InsertCellBelow, this.insertCellBelow);
Expand Down
8 changes: 4 additions & 4 deletions src/interactive-window/debugger/jupyter/debuggingManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
KernelDebugMode
} from '../../../notebooks/debugger/debuggingTypes';
import { assertIsInteractiveWindowDebugConfig, IpykernelCheckResult } from '../../../notebooks/debugger/helper';
import { IExtensionSingleActivationService } from '../../../platform/activation/types';
import { IExtensionSyncActivationService } from '../../../platform/activation/types';
import {
IApplicationShell,
ICommandManager,
Expand Down Expand Up @@ -50,7 +50,7 @@ import { RestartNotSupportedController } from './restartNotSupportedController';
@injectable()
export class InteractiveWindowDebuggingManager
extends DebuggingManagerBase
implements IExtensionSingleActivationService, IInteractiveWindowDebuggingManager
implements IExtensionSyncActivationService, IInteractiveWindowDebuggingManager
{
public constructor(
@inject(IKernelProvider) kernelProvider: IKernelProvider,
Expand All @@ -77,8 +77,8 @@ export class InteractiveWindowDebuggingManager
);
}

public override async activate(): Promise<void> {
await super.activate();
public override activate() {
super.activate();
// factory for kernel debug adapters
this.disposables.push(
debug.registerDebugAdapterDescriptorFactory(pythonIWKernelDebugAdapter, {
Expand Down
7 changes: 3 additions & 4 deletions src/interactive-window/editor-integration/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { inject, injectable } from 'inversify';
import * as vscode from 'vscode';

import { IExtensionSingleActivationService } from '../../platform/activation/types';
import { IExtensionSyncActivationService } from '../../platform/activation/types';
import { IPythonExtensionChecker } from '../../platform/api/types';
import { IDocumentManager } from '../../platform/common/application/types';
import { PYTHON_LANGUAGE } from '../../platform/common/constants';
Expand All @@ -17,7 +17,7 @@ import { generateCellRangesFromDocument } from './cellFactory';
* Provides the lines that show up between cells in the editor.
*/
@injectable()
export class Decorator implements IExtensionSingleActivationService, IDisposable {
export class Decorator implements IExtensionSyncActivationService, IDisposable {
private currentCellTop: vscode.TextEditorDecorationType | undefined;
private currentCellBottom: vscode.TextEditorDecorationType | undefined;
private currentCellTopUnfocused: vscode.TextEditorDecorationType | undefined;
Expand All @@ -39,10 +39,9 @@ export class Decorator implements IExtensionSingleActivationService, IDisposable
this.settingsChanged();
}

public activate(): Promise<void> {
public activate() {
// We don't need to do anything here as we already did all of our work in the
// constructor.
return Promise.resolve();
}

public dispose() {
Expand Down
8 changes: 4 additions & 4 deletions src/interactive-window/serviceRegistry.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
'use strict';

import { IStartupCodeProvider, ITracebackFormatter } from '../kernels/types';
import { IExtensionSyncActivationService, IExtensionSingleActivationService } from '../platform/activation/types';
import { IJupyterExtensionBanner } from '../platform/common/types';
import { IServiceManager } from '../platform/ioc/types';
import { CommandRegistry } from './commands/commandRegistry';
Expand Down Expand Up @@ -32,10 +31,11 @@ import { BANNER_NAME_INTERACTIVE_SHIFTENTER, InteractiveShiftEnterBanner } from
import { InteractiveWindowDebuggingStartupCodeProvider } from './debugger/startupCodeProvider';
import { PythonCellFoldingProvider } from './editor-integration/pythonCellFoldingProvider';
import { CodeLensProviderActivator } from './editor-integration/codelensProviderActivator';
import { IExtensionSyncActivationService } from '../platform/activation/types';

export function registerTypes(serviceManager: IServiceManager) {
serviceManager.addSingleton<IInteractiveWindowProvider>(IInteractiveWindowProvider, InteractiveWindowProvider);
serviceManager.addSingleton<IExtensionSingleActivationService>(IExtensionSingleActivationService, CommandRegistry);
serviceManager.addSingleton<IExtensionSyncActivationService>(IExtensionSyncActivationService, CommandRegistry);
serviceManager.addSingleton<IExtensionSyncActivationService>(IExtensionSyncActivationService, HoverProvider);
serviceManager.add<ICodeWatcher>(ICodeWatcher, CodeWatcher);
serviceManager.addSingleton<ICodeLensFactory>(ICodeLensFactory, CodeLensFactory);
Expand All @@ -51,7 +51,7 @@ export function registerTypes(serviceManager: IServiceManager) {
IExtensionSyncActivationService,
PythonCellFoldingProvider
);
serviceManager.addSingleton<IExtensionSingleActivationService>(IExtensionSingleActivationService, Decorator);
serviceManager.addSingleton<IExtensionSyncActivationService>(IExtensionSyncActivationService, Decorator);
serviceManager.addSingleton<IExtensionSyncActivationService>(
IExtensionSyncActivationService,
GeneratedCodeStorageManager
Expand All @@ -69,7 +69,7 @@ export function registerTypes(serviceManager: IServiceManager) {
IInteractiveWindowDebuggingManager,
InteractiveWindowDebuggingManager,
undefined,
[IExtensionSingleActivationService]
[IExtensionSyncActivationService]
);
serviceManager.addSingleton<IJupyterExtensionBanner>(
IJupyterExtensionBanner,
Expand Down
8 changes: 4 additions & 4 deletions src/interactive-window/serviceRegistry.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'use strict';

import { IStartupCodeProvider, ITracebackFormatter } from '../kernels/types';
import { IExtensionSingleActivationService, IExtensionSyncActivationService } from '../platform/activation/types';
import { IExtensionSyncActivationService } from '../platform/activation/types';
import { IServiceManager } from '../platform/ioc/types';
import { CommandRegistry } from './commands/commandRegistry';
import { CodeLensFactory } from './editor-integration/codeLensFactory';
Expand All @@ -31,7 +31,7 @@ import { CodeLensProviderActivator } from './editor-integration/codelensProvider

export function registerTypes(serviceManager: IServiceManager) {
serviceManager.addSingleton<IInteractiveWindowProvider>(IInteractiveWindowProvider, InteractiveWindowProvider);
serviceManager.addSingleton<IExtensionSingleActivationService>(IExtensionSingleActivationService, CommandRegistry);
serviceManager.addSingleton<IExtensionSyncActivationService>(IExtensionSyncActivationService, CommandRegistry);
serviceManager.add<ICodeWatcher>(ICodeWatcher, CodeWatcher);
serviceManager.addSingleton<ICodeLensFactory>(ICodeLensFactory, CodeLensFactory);
serviceManager.addSingleton<IDataScienceCodeLensProvider>(
Expand All @@ -46,7 +46,7 @@ export function registerTypes(serviceManager: IServiceManager) {
IExtensionSyncActivationService,
PythonCellFoldingProvider
);
serviceManager.addSingleton<IExtensionSingleActivationService>(IExtensionSingleActivationService, Decorator);
serviceManager.addSingleton<IExtensionSyncActivationService>(IExtensionSyncActivationService, Decorator);
serviceManager.addSingleton<IExtensionSyncActivationService>(
IExtensionSyncActivationService,
GeneratedCodeStorageManager
Expand All @@ -63,7 +63,7 @@ export function registerTypes(serviceManager: IServiceManager) {
IInteractiveWindowDebuggingManager,
InteractiveWindowDebuggingManager,
undefined,
[IExtensionSingleActivationService]
[IExtensionSyncActivationService]
);
serviceManager.addSingleton<IStartupCodeProvider>(
IStartupCodeProvider,
Expand Down
6 changes: 3 additions & 3 deletions src/kernels/activation.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { inject, injectable } from 'inversify';
import { NotebookDocument } from 'vscode';
import { IExtensionSingleActivationService } from '../platform/activation/types';
import { IExtensionSyncActivationService } from '../platform/activation/types';
import { IPythonExtensionChecker } from '../platform/api/types';
import { IVSCodeNotebook } from '../platform/common/application/types';
import { Telemetry } from '../platform/common/constants';
Expand All @@ -19,7 +19,7 @@ import { IRawNotebookSupportedService } from './raw/types';
* Starts up a bunch of objects when running in a node environment.
*/
@injectable()
export class Activation implements IExtensionSingleActivationService {
export class Activation implements IExtensionSyncActivationService {
private notebookOpened = false;
constructor(
@inject(IVSCodeNotebook) private readonly vscNotebook: IVSCodeNotebook,
Expand All @@ -28,7 +28,7 @@ export class Activation implements IExtensionSingleActivationService {
@inject(IRawNotebookSupportedService) private readonly rawSupported: IRawNotebookSupportedService,
@inject(IPythonExtensionChecker) private readonly extensionChecker: IPythonExtensionChecker
) {}
public async activate(): Promise<void> {
public activate() {
this.disposables.push(this.vscNotebook.onDidOpenNotebookDocument(this.onDidOpenNotebookEditor, this));
this.disposables.push(this.jupyterInterpreterService.onDidChangeInterpreter(this.onDidChangeInterpreter, this));
}
Expand Down
6 changes: 3 additions & 3 deletions src/kernels/jupyter/commands/commandRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'use strict';

import { inject, injectable } from 'inversify';
import { IExtensionSingleActivationService } from '../../../platform/activation/types';
import { IExtensionSyncActivationService } from '../../../platform/activation/types';
import { IWorkspaceService } from '../../../platform/common/application/types';
import { IDisposable } from '../../../platform/common/types';
import { JupyterCommandLineSelectorCommand } from './commandLineSelector';
Expand All @@ -13,14 +13,14 @@ import { JupyterCommandLineSelectorCommand } from './commandLineSelector';
* Registers jupyter (non ZMQ) specific commands
*/
@injectable()
export class CommandRegistry implements IExtensionSingleActivationService {
export class CommandRegistry implements IExtensionSyncActivationService {
private readonly disposables: IDisposable[] = [];
constructor(
@inject(JupyterCommandLineSelectorCommand)
private readonly commandLineCommand: JupyterCommandLineSelectorCommand,
@inject(IWorkspaceService) private readonly workspace: IWorkspaceService
) {}
public async activate() {
public activate() {
this.registerCommandsIfTrusted();
}
public dispose() {
Expand Down
6 changes: 3 additions & 3 deletions src/kernels/jupyter/finder/remoteKernelFinderController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { IPythonExtensionChecker } from '../../../platform/api/types';
import { noop } from '../../../platform/common/utils/misc';
import { IApplicationEnvironment } from '../../../platform/common/application/types';
import { KernelFinder } from '../../kernelFinder';
import { IExtensionSingleActivationService } from '../../../platform/activation/types';
import { IExtensionSyncActivationService } from '../../../platform/activation/types';
import { RemoteKernelFinder } from './remoteKernelFinder';
import { ContributedKernelFinderKind } from '../../internalTypes';
import * as localize from '../../../platform/common/utils/localize';
Expand Down Expand Up @@ -190,7 +190,7 @@ class SingleServerStrategy implements IRemoteKernelFinderRegistrationStrategy {

// This class creates RemoteKernelFinders for all registered Jupyter Server URIs
@injectable()
export class RemoteKernelFinderController implements IExtensionSingleActivationService {
export class RemoteKernelFinderController implements IExtensionSyncActivationService {
private _strategy: IRemoteKernelFinderRegistrationStrategy;
private _localDisposables: Disposable[] = [];

Expand Down Expand Up @@ -267,7 +267,7 @@ export class RemoteKernelFinderController implements IExtensionSingleActivationS
}
}

async activate(): Promise<void> {
activate() {
this._strategy.activate().then(noop, noop);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'use strict';

import { inject, injectable } from 'inversify';
import { IExtensionSingleActivationService } from '../../../platform/activation/types';
import { IExtensionSyncActivationService } from '../../../platform/activation/types';
import { ICommandManager } from '../../../platform/common/application/types';
import { IDisposableRegistry } from '../../../platform/common/types';
import { sendTelemetryEvent, Telemetry } from '../../../telemetry';
Expand All @@ -14,13 +14,13 @@ import { JupyterInterpreterService } from './jupyterInterpreterService.node';
* Registers the command for setting the interpreter to launch jupyter with
*/
@injectable()
export class JupyterInterpreterSelectionCommand implements IExtensionSingleActivationService {
export class JupyterInterpreterSelectionCommand implements IExtensionSyncActivationService {
constructor(
@inject(JupyterInterpreterService) private readonly service: JupyterInterpreterService,
@inject(ICommandManager) private readonly cmdManager: ICommandManager,
@inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry
) {}
public async activate(): Promise<void> {
public activate() {
this.disposables.push(
this.cmdManager.registerCommand('jupyter.selectJupyterInterpreter', () => {
sendTelemetryEvent(Telemetry.SelectJupyterInterpreterCommand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { inject, injectable, named } from 'inversify';
import { Memento, Uri } from 'vscode';
import { IExtensionSingleActivationService } from '../../../platform/activation/types';
import { IExtensionSyncActivationService } from '../../../platform/activation/types';
import { IPythonApiProvider, IPythonExtensionChecker } from '../../../platform/api/types';
import { IMemento, GLOBAL_MEMENTO, IDisposableRegistry } from '../../../platform/common/types';
import { noop } from '../../../platform/common/utils/misc';
Expand Down Expand Up @@ -50,7 +50,7 @@ export class JupyterInterpreterStateStore {
}

@injectable()
export class MigrateJupyterInterpreterStateService implements IExtensionSingleActivationService {
export class MigrateJupyterInterpreterStateService implements IExtensionSyncActivationService {
private settingsMigrated?: boolean;
constructor(
@inject(IPythonApiProvider) private readonly api: IPythonApiProvider,
Expand All @@ -60,7 +60,7 @@ export class MigrateJupyterInterpreterStateService implements IExtensionSingleAc
) {}

// Migrate the interpreter path selected for Jupyter server from the Python extension's globalState memento
public async activate() {
public activate() {
this.activateBackground().catch(noop);
this.api.onDidActivatePythonExtension(this.activateBackground, this, this.disposables);
}
Expand Down
9 changes: 3 additions & 6 deletions src/kernels/jupyter/launcher/serverPreload.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'use strict';
import { inject, injectable, named } from 'inversify';
import { CancellationTokenSource, Memento, NotebookDocument } from 'vscode';
import { IExtensionSingleActivationService } from '../../../platform/activation/types';
import { IExtensionSyncActivationService } from '../../../platform/activation/types';
import { IVSCodeNotebook, IWorkspaceService } from '../../../platform/common/application/types';
import { PYTHON_LANGUAGE } from '../../../platform/common/constants';
import { traceInfo, traceError } from '../../../platform/logging';
Expand All @@ -28,7 +28,7 @@ const LastNotebookCreatedKey = 'last-notebook-created';
* Class used for preloading a kernel. Makes first run of a kernel faster as it loads as soon as the extension does.
*/
@injectable()
export class ServerPreload implements IExtensionSingleActivationService {
export class ServerPreload implements IExtensionSyncActivationService {
constructor(
@inject(IVSCodeNotebook) notebook: IVSCodeNotebook,
@inject(IConfigurationService) private configService: IConfigurationService,
Expand All @@ -41,7 +41,7 @@ export class ServerPreload implements IExtensionSingleActivationService {
) {
notebook.onDidOpenNotebookDocument(this.onDidOpenNotebook.bind(this), this, disposables);
}
public activate(): Promise<void> {
public activate() {
// This is the list of things that should cause us to start a local server
// 1) Notebook is opened
// 2) Notebook was opened in the past 7 days
Expand All @@ -51,9 +51,6 @@ export class ServerPreload implements IExtensionSingleActivationService {
this.checkDateForServerStart();

this.disposables.push(this.kernelProvider.onDidStartKernel(this.kernelStarted, this));

// Don't hold up activation though
return Promise.resolve();
}

private get lastNotebookCreated() {
Expand Down
Loading

0 comments on commit 91a3a3a

Please sign in to comment.