Skip to content

Commit

Permalink
multiplexingDebugService for the web (#10070)
Browse files Browse the repository at this point in the history
* multiplexingDebugService for the web

* unifying .node and .web

* addressing feedback by Ian and Rich
  • Loading branch information
sadasant authored May 23, 2022
1 parent b07aafe commit b8ae8c5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/kernels/serviceRegistry.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { KernelVariables } from './variables/kernelVariables';
import { PreWarmActivatedJupyterEnvironmentVariables } from './variables/preWarmVariables.node';
import { PythonVariablesRequester } from './variables/pythonVariableRequester.node';
import { IInteractiveWindowDebugger } from '../interactive-window/types';
import { MultiplexingDebugService } from '../platform/debugger/multiplexingDebugService.node';
import { MultiplexingDebugService } from '../platform/debugger/multiplexingDebugService';
import { JupyterVariableDataProvider } from '../webviews/extension-side/dataviewer/jupyterVariableDataProvider';
import { JupyterVariableDataProviderFactory } from '../webviews/extension-side/dataviewer/jupyterVariableDataProviderFactory.node';
import {
Expand Down
10 changes: 9 additions & 1 deletion src/kernels/serviceRegistry.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as vscode from 'vscode';
import { IExtensionSyncActivationService } from '../platform/activation/types';
import { IPythonExtensionChecker } from '../platform/api/types';
import { IApplicationEnvironment } from '../platform/common/application/types';
import { JVSC_EXTENSION_ID } from '../platform/common/constants';
import { Identifiers, JVSC_EXTENSION_ID } from '../platform/common/constants';

import { IServiceManager } from '../platform/ioc/types';
import { setSharedProperty } from '../telemetry';
Expand All @@ -20,6 +20,8 @@ import { KernelFinder } from './kernelFinder.web';
import { PreferredRemoteKernelIdProvider } from './jupyter/preferredRemoteKernelIdProvider';
import { IDataScienceCommandListener } from '../platform/common/types';
import { KernelCommandListener } from './kernelCommandListener';
import { IJupyterDebugService } from './debugging/types';
import { MultiplexingDebugService } from '../platform/debugger/multiplexingDebugService';

@injectable()
class RawNotebookSupportedService implements IRawNotebookSupportedService {
Expand Down Expand Up @@ -49,6 +51,12 @@ export function registerTypes(serviceManager: IServiceManager, isDevMode: boolea
const rawService = serviceManager.get<IRawNotebookSupportedService>(IRawNotebookSupportedService);
setSharedProperty('rawKernelSupported', rawService.isSupported ? 'true' : 'false');

serviceManager.addSingleton<IJupyterDebugService>(
IJupyterDebugService,
MultiplexingDebugService,
Identifiers.MULTIPLEXING_DEBUGSERVICE
);

serviceManager.addSingleton<IExtensionSyncActivationService>(IExtensionSyncActivationService, KernelCrashMonitor);
serviceManager.addSingleton<IKernelProvider>(IKernelProvider, KernelProvider);
serviceManager.addSingleton<PreferredRemoteKernelIdProvider>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { inject, injectable, named } from 'inversify';
import { inject, injectable, named, optional } from 'inversify';
import {
Breakpoint,
BreakpointsChangeEvent,
Expand Down Expand Up @@ -37,20 +37,26 @@ export class MultiplexingDebugService implements IJupyterDebugService {
@inject(IDisposableRegistry) disposableRegistry: IDisposableRegistry,
@inject(ICommandManager) private commandManager: ICommandManager,
@inject(IDebugService) private vscodeDebugService: IDebugService,
@optional()
@inject(IJupyterDebugService)
@named(Identifiers.RUN_BY_LINE_DEBUGSERVICE)
private jupyterDebugService: IJupyterDebugService
private jupyterDebugService: IJupyterDebugService | undefined
) {
disposableRegistry.push(vscodeDebugService.onDidTerminateDebugSession(this.endedDebugSession.bind(this)));
disposableRegistry.push(jupyterDebugService.onDidTerminateDebugSession(this.endedDebugSession.bind(this)));
disposableRegistry.push(vscodeDebugService.onDidStartDebugSession(this.startedDebugSession.bind(this)));
disposableRegistry.push(jupyterDebugService.onDidStartDebugSession(this.startedDebugSession.bind(this)));
disposableRegistry.push(vscodeDebugService.onDidChangeActiveDebugSession(this.changedDebugSession.bind(this)));
disposableRegistry.push(jupyterDebugService.onDidChangeActiveDebugSession(this.changedDebugSession.bind(this)));
disposableRegistry.push(vscodeDebugService.onDidReceiveDebugSessionCustomEvent(this.gotCustomEvent.bind(this)));
disposableRegistry.push(
jupyterDebugService.onDidReceiveDebugSessionCustomEvent(this.gotCustomEvent.bind(this))
);

if (jupyterDebugService) {
disposableRegistry.push(jupyterDebugService.onDidTerminateDebugSession(this.endedDebugSession.bind(this)));
disposableRegistry.push(jupyterDebugService.onDidStartDebugSession(this.startedDebugSession.bind(this)));
disposableRegistry.push(
jupyterDebugService.onDidChangeActiveDebugSession(this.changedDebugSession.bind(this))
);
disposableRegistry.push(
jupyterDebugService.onDidReceiveDebugSessionCustomEvent(this.gotCustomEvent.bind(this))
);
}
}
public get activeDebugSession(): DebugSession | undefined {
return this.activeService.activeDebugSession;
Expand Down Expand Up @@ -78,21 +84,33 @@ export class MultiplexingDebugService implements IJupyterDebugService {
return this.activeService.onDidChangeBreakpoints;
}
public get onBreakpointHit(): Event<void> {
if (!this.jupyterDebugService) {
throw new Error('No jupyter debugger service');
}
return this.jupyterDebugService.onBreakpointHit;
}
public startRunByLine(config: DebugConfiguration): Thenable<boolean> {
this.lastStartedService = this.jupyterDebugService;
if (!this.jupyterDebugService) {
throw new Error('No jupyter debugger service');
}
return this.jupyterDebugService.startRunByLine(config);
}
public registerDebugConfigurationProvider(debugType: string, provider: DebugConfigurationProvider): Disposable {
const d1 = this.vscodeDebugService.registerDebugConfigurationProvider(debugType, provider);
const d2 = this.jupyterDebugService.registerDebugConfigurationProvider(debugType, provider);
return this.combineDisposables(d1, d2);
if (this.jupyterDebugService) {
const d2 = this.jupyterDebugService.registerDebugConfigurationProvider(debugType, provider);
return this.combineDisposables(d1, d2);
}
return d1;
}
public registerDebugAdapterTrackerFactory(debugType: string, factory: DebugAdapterTrackerFactory): Disposable {
const d1 = this.vscodeDebugService.registerDebugAdapterTrackerFactory(debugType, factory);
const d2 = this.jupyterDebugService.registerDebugAdapterTrackerFactory(debugType, factory);
return this.combineDisposables(d1, d2);
if (this.jupyterDebugService) {
const d2 = this.jupyterDebugService.registerDebugAdapterTrackerFactory(debugType, factory);
return this.combineDisposables(d1, d2);
}
return d1;
}
public startDebugging(
folder: WorkspaceFolder | undefined,
Expand All @@ -110,32 +128,44 @@ export class MultiplexingDebugService implements IJupyterDebugService {
}

public getStack(): Promise<DebugProtocol.StackFrame[]> {
if (!this.jupyterDebugService) {
throw new Error('No jupyter debugger service');
}
if (this.lastStartedService === this.jupyterDebugService) {
return this.jupyterDebugService.getStack();
}
throw new Error('Requesting jupyter specific stack when not debugging.');
}
public step(): Promise<void> {
if (!this.jupyterDebugService) {
throw new Error('No jupyter debugger service');
}
if (this.lastStartedService === this.jupyterDebugService) {
return this.jupyterDebugService.step();
}
throw new Error('Requesting jupyter specific step when not debugging.');
}
public continue(): Promise<void> {
if (!this.jupyterDebugService) {
throw new Error('No jupyter debugger service');
}
if (this.lastStartedService === this.jupyterDebugService) {
return this.jupyterDebugService.continue();
}
throw new Error('Requesting jupyter specific step when not debugging.');
}
public requestVariables(): Promise<void> {
if (!this.jupyterDebugService) {
throw new Error('No jupyter debugger service');
}
if (this.lastStartedService === this.jupyterDebugService) {
return this.jupyterDebugService.requestVariables();
}
throw new Error('Requesting jupyter specific variables when not debugging.');
}

public stop(): void {
if (this.lastStartedService === this.jupyterDebugService) {
if (this.jupyterDebugService && this.lastStartedService === this.jupyterDebugService) {
this.jupyterDebugService.stop();
} else {
// Stop our debugging UI session, no await as we just want it stopped
Expand Down

0 comments on commit b8ae8c5

Please sign in to comment.