Skip to content

Commit

Permalink
Move debugger files from platform folder (#10097)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne authored May 24, 2022
1 parent da7f1a4 commit 760d61e
Show file tree
Hide file tree
Showing 36 changed files with 166 additions and 249 deletions.
1 change: 0 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@
"DataScience.cellStopOnErrorMessage": "Cell was canceled due to an error in a previous cell.",
"DataScience.instructionComments": "# To add a new cell, type '{0}'\n# To add a new markdown cell, type '{0} [markdown]'\n",
"DataScience.scrollToCellTitleFormatMessage": "Go to [{0}]",
"DataScience.remoteDebuggerNotSupported": "Debugging while attached to a remote server is not currently supported.",
"DataScience.save": "Save notebook",
"DataScience.nativeEditorTitle": "Notebook Editor",
"DataScience.untitledNotebookFileName": "Untitled",
Expand Down
1 change: 0 additions & 1 deletion package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@
"DataScience.jupyterDebuggerInstallNo": "",
"DataScience.instructionComments": "# 要添加一个新单元,输入 '{0}'\n# 要添加一个新的标记单元,输入 '{0} [markdown]'\n",
"DataScience.scrollToCellTitleFormatMessage": "转到 [{0}]",
"DataScience.remoteDebuggerNotSupported": "目前不支持连接到远程服务器时进行调试。",
"DataScience.save": "保存笔记本",
"DataScience.nativeEditorTitle": "笔记本编辑器",
"DataScience.untitledNotebookFileName": "Untitled",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ import { IConfigurationService } from '../../platform/common/types';
import { DataScience } from '../../platform/common/utils/localize';
import { Identifiers, Telemetry } from '../../webviews/webview-side/common/constants';
import { JupyterDebuggerNotInstalledError } from '../../platform/errors/jupyterDebuggerNotInstalledError';
import { JupyterDebuggerRemoteNotSupportedError } from '../../platform/errors/jupyterDebuggerRemoteNotSupportedError';
import { getPlainTextOrStreamOutput } from '../kernel.base';
import { IKernel, isLocalConnection } from '../types';
import { IInteractiveWindowDebugger } from '../../interactive-window/types';
import { IFileGeneratedCodes } from '../../interactive-window/editor-integration/types';
import { IJupyterDebugService, ISourceMapRequest } from './types';
import { getPlainTextOrStreamOutput } from '../../kernels/kernel.base';
import { IKernel, isLocalConnection } from '../../kernels/types';
import { IInteractiveWindowDebugger } from '../types';
import { IFileGeneratedCodes } from '../editor-integration/types';
import { IJupyterDebugService, ISourceMapRequest } from '../../kernels/debugger/types';
import { getAssociatedNotebookDocument } from '../../notebooks/controllers/kernelSelector';
import { executeSilently } from '../helpers';
import { executeSilently } from '../../kernels/helpers';

@injectable()
export class InteractiveWindowDebugger implements IInteractiveWindowDebugger {
Expand Down Expand Up @@ -85,12 +84,12 @@ export class InteractiveWindowDebugger implements IInteractiveWindowDebugger {
}
}

public async updateSourceMaps(generatedCodes: IFileGeneratedCodes[]): Promise<void> {
public async updateSourceMaps(hashes: IFileGeneratedCodes[]): Promise<void> {
// Make sure that we have an active debugging session at this point
if (this.debugService.activeDebugSession && this.debuggingActive) {
traceInfoIfCI(`Sending debug request for source map`);
await Promise.all(
generatedCodes.map(async (fileHash) => {
hashes.map(async (fileHash) => {
if (this.debuggingActive) {
return this.debugService.activeDebugSession!.customRequest(
'setPydevdSourceMap',
Expand Down Expand Up @@ -192,15 +191,9 @@ export class InteractiveWindowDebugger implements IInteractiveWindowDebugger {
request: 'attach',
...extraConfig
};
if (isLocalConnection(kernel.kernelConnectionMetadata)) {
const { host, port } = await this.connectToLocal(kernel);
result.host = host;
result.port = port;
} else {
const { host, port } = await this.connectToRemote(kernel);
result.host = host;
result.port = port;
}
const { host, port } = await this.connectToLocal(kernel);
result.host = host;
result.port = port;

if (result.port) {
this.configs.set(notebook, result);
Expand Down Expand Up @@ -338,61 +331,4 @@ export class InteractiveWindowDebugger implements IInteractiveWindowDebugger {
kernel.kernelConnectionMetadata
);
}

private async connectToRemote(kernel: IKernel): Promise<{ port: number; host: string }> {
// We actually need a token. This isn't supported at the moment
throw new JupyterDebuggerRemoteNotSupportedError(kernel.kernelConnectionMetadata);

// let portNumber = this.configService.getSettings().remoteDebuggerPort;
// if (!portNumber) {
// portNumber = -1;
// }

// // Loop through a bunch of ports until we find one we can use. Note how we
// // are connecting to '0.0.0.0' here. That's the location as far as ptvsd is concerned.
// const attachCode = portNumber !== -1 ?
// `import ptvsd
// ptvsd.enable_attach(('0.0.0.0', ${portNumber}))
// print("('${connectionInfo.hostName}', ${portNumber})")` :
// eslint-disable-next-line no-multi-str
// `import ptvsd
// port = ${Settings.RemoteDebuggerPortBegin}
// attached = False
// while not attached and port <= ${Settings.RemoteDebuggerPortEnd}:
// try:
// ptvsd.enable_attach(('0.0.0.0', port))
// print("('${connectionInfo.hostName}', " + str(port) + ")")
// attached = True
// except Exception as e:
// print("Exception: " + str(e))
// port +=1`;
// const enableDebuggerResults = await this.executeSilently(server, attachCode);

// // Save our connection info to this server
// const result = this.parseConnectInfo(enableDebuggerResults, false);

// // If that didn't work, throw an error so somebody can open the port
// if (!result) {
// throw new JupyterDebuggerPortNotAvailableError(portNumber, Settings.RemoteDebuggerPortBegin, Settings.RemoteDebuggerPortEnd);
// }

// // Double check, open a socket? This won't work if we're remote ourselves. Actually the debug adapter runs
// // from the remote machine.
// try {
// const deferred = createDeferred();
// const socket = net.createConnection(result.port, result.host, () => {
// deferred.resolve();
// });
// socket.on('error', (err) => deferred.reject(err));
// socket.setTimeout(2000, () => deferred.reject(new Error('Timeout trying to ping remote debugger')));
// await deferred.promise;
// socket.end();
// } catch (exc) {
// traceWarning(`Cannot connect to remote debugger at ${result.host}:${result.port} => ${exc}`);
// // We can't connect. Must be a firewall issue
// throw new JupyterDebuggerPortBlockedError(portNumber, Settings.RemoteDebuggerPortBegin, Settings.RemoteDebuggerPortEnd);
// }

// return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import {
PYTHON_UNTITLED,
Telemetry
} from '../../platform/common/constants';
import { IDebugLocationTracker } from '../../platform/debugger/types';
import { IDataScienceCodeLensProvider, ICodeWatcher } from './types';
import * as urlPath from '../../platform/vscode-path/resources';
import { IDebugLocationTracker } from '../../kernels/debugger/types';

@injectable()
export class DataScienceCodeLensProvider implements IDataScienceCodeLensProvider, IDisposable {
Expand Down
29 changes: 13 additions & 16 deletions src/interactive-window/interactiveWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ import * as uuid from 'uuid/v4';

import { IConfigurationService, InteractiveWindowMode, Resource } from '../platform/common/types';
import { noop } from '../platform/common/utils/misc';
import { IKernel, KernelAction, KernelConnectionMetadata, NotebookCellRunState } from '../kernels/types';
import {
IKernel,
isLocalConnection,
KernelAction,
KernelConnectionMetadata,
NotebookCellRunState
} from '../kernels/types';
import { INotebookControllerManager } from '../notebooks/types';
import { generateMarkdownFromCodeLines, parseForComments } from '../webviews/webview-side/common';
import { initializeInteractiveOrNotebookTelemetryBasedOnUserAction } from '../telemetry/telemetry';
Expand Down Expand Up @@ -568,21 +574,12 @@ export class InteractiveWindow implements IInteractiveWindowLoadable {
let detachKernel = async () => noop();
try {
const kernel = await kernelPromise;
if (
kernel.kernelConnectionMetadata.kind === 'connectToLiveRemoteKernel' ||
kernel.kernelConnectionMetadata.kind === 'startUsingRemoteKernelSpec'
) {
void this.appShell.showErrorMessage(DataScience.remoteDebuggerNotSupported());
isDebug = false;
}
detachKernel = async () => {
if (isDebug) {
await this.interactiveWindowDebugger.detach(kernel!);
}
};

// If debugging attach to the kernel but don't enable tracing just yet
if (isDebug) {
if (isDebug && (settings.useJupyterDebugger || !isLocalConnection(kernel.kernelConnectionMetadata))) {
// New ipykernel 7 debugger.
} else if (isDebug && isLocalConnection(kernel.kernelConnectionMetadata)) {
// Old ipykernel 6 debugger.
// If debugging attach to the kernel but don't enable tracing just yet
detachKernel = async () => this.interactiveWindowDebugger.detach(kernel);
await this.interactiveWindowDebugger.attach(kernel);
await this.interactiveWindowDebugger.updateSourceMaps(
this.storageFactory.get({ notebook: cell.notebook })?.all || []
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
'use strict';
import { DebugAdapterTracker, Event, EventEmitter } from 'vscode';
import { DebugProtocol } from 'vscode-debugprotocol';

import { IDebugLocation } from './types';

// When a python debugging session is active keep track of the current debug location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
ProviderResult
} from 'vscode';

import { IDebugService } from '../common/application/types';
import { IDisposableRegistry } from '../common/types';
import { IDebugService } from '../../platform/common/application/types';
import { IDisposableRegistry } from '../../platform/common/types';
import { DebugLocationTracker } from './debugLocationTracker';
import { IDebugLocationTracker } from './types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import {
WorkspaceFolder
} from 'vscode';
import { DebugProtocol } from 'vscode-debugprotocol';
import { IJupyterDebugService } from '../../kernels/debugging/types';
import { ICommandManager, IDebugService } from '../common/application/types';
import { Identifiers } from '../common/constants';
import { IDisposableRegistry } from '../common/types';
import { IJupyterDebugService } from './types';
import { ICommandManager, IDebugService } from '../../platform/common/application/types';
import { Identifiers } from '../../platform/common/constants';
import { IDisposableRegistry } from '../../platform/common/types';

/**
* IJupyterDebugService that will pick the correct debugger based on if doing run by line or normal debugging.
Expand Down
50 changes: 49 additions & 1 deletion src/platform/debugger/types.ts → src/kernels/debugger/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';

import { DebugProtocol } from 'vscode-debugprotocol';
import { IDebugService } from '../../platform/common/application/types';
import {
DebugAdapter,
DebugConfiguration,
Expand All @@ -10,7 +13,52 @@ import {
NotebookCell,
NotebookDocument
} from 'vscode';
import { DebugProtocol } from 'vscode-debugprotocol';

export interface ISourceMapMapping {
line: number;
endLine: number;
runtimeSource: { path: string };
runtimeLine: number;
}

export interface ISourceMapRequest {
source: { path: string };
pydevdSourceMaps: ISourceMapMapping[];
}

export const IJupyterDebugService = Symbol('IJupyterDebugService');
export interface IJupyterDebugService extends IDebugService {
/**
* Event fired when a breakpoint is hit (debugger has stopped)
*/
readonly onBreakpointHit: Event<void>;
/**
* Start debugging a notebook cell.
* @param nameOrConfiguration Either the name of a debug or compound configuration or a [DebugConfiguration](#DebugConfiguration) object.
* @return A thenable that resolves when debugging could be successfully started.
*/
startRunByLine(config: DebugConfiguration): Thenable<boolean>;
/**
* Gets the current stack frame for the current thread
*/
getStack(): Promise<DebugProtocol.StackFrame[]>;
/**
* Steps the current thread. Returns after the request is sent. Wait for onBreakpointHit or onDidTerminateDebugSession to determine when done.
*/
step(): Promise<void>;
/**
* Runs the current thread. Will keep running until a breakpoint or end of session.
*/
continue(): Promise<void>;
/**
* Force a request for variables. DebugAdapterTrackers can listen for the results.
*/
requestVariables(): Promise<void>;
/**
* Stop debugging
*/
stop(): void;
}

export interface IKernelDebugAdapter extends DebugAdapter {
stepIn(threadId: number): Thenable<DebugProtocol.StepInResponse['body']>;
Expand Down
53 changes: 0 additions & 53 deletions src/kernels/debugging/types.ts

This file was deleted.

7 changes: 7 additions & 0 deletions src/kernels/kernel.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ export class Kernel extends BaseKernel {
}

protected async getDebugCellHook(): Promise<string[]> {
const useNewDebugger = this.configService.getSettings(undefined).useJupyterDebugger === true;
if (useNewDebugger) {
return [];
}
if (!isLocalConnection(this.kernelConnectionMetadata)) {
return [];
}
// Only do this for interactive windows. IPYKERNEL_CELL_NAME is set other ways in
// notebooks
if (getAssociatedNotebookDocument(this)?.notebookType === InteractiveWindowView) {
Expand Down
8 changes: 4 additions & 4 deletions src/kernels/serviceRegistry.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { ProtocolParser } from '../platform/debugger/extension/helpers/protocolP
import { IProtocolParser } from '../platform/debugger/extension/types.node';
import { IServiceManager } from '../platform/ioc/types';
import { setSharedProperty } from '../telemetry';
import { InteractiveWindowDebugger } from './debugging/interactiveWindowDebugger.node';
import { JupyterDebugService } from './debugging/jupyterDebugService.node';
import { InteractiveWindowDebugger } from '../interactive-window/debugger/interactiveWindowDebugger.node';
import { JupyterDebugService } from '../notebooks/debugger/jupyterDebugService.node';
import { registerInstallerTypes } from './installer/serviceRegistry.node';
import { KernelCommandListener } from './kernelCommandListener';
import { KernelDependencyService } from './kernelDependencyService.node';
Expand All @@ -34,14 +34,14 @@ 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';
import { MultiplexingDebugService } from './debugger/multiplexingDebugService';
import { JupyterVariableDataProvider } from '../webviews/extension-side/dataviewer/jupyterVariableDataProvider';
import { JupyterVariableDataProviderFactory } from '../webviews/extension-side/dataviewer/jupyterVariableDataProviderFactory.node';
import {
IJupyterVariableDataProvider,
IJupyterVariableDataProviderFactory
} from '../webviews/extension-side/dataviewer/types';
import { IJupyterDebugService } from './debugging/types';
import { IJupyterDebugService } from './debugger/types';
import { IKernelDependencyService, IKernelFinder, IKernelProvider } from './types';
import { IJupyterVariables, IKernelVariableRequester } from './variables/types';
import { KernelCrashMonitor } from './kernelCrashMonitor';
Expand Down
4 changes: 2 additions & 2 deletions src/kernels/serviceRegistry.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +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';
import { MultiplexingDebugService } from './debugger/multiplexingDebugService';
import { IJupyterDebugService } from './debugger/types';

@injectable()
class RawNotebookSupportedService implements IRawNotebookSupportedService {
Expand Down
Loading

0 comments on commit 760d61e

Please sign in to comment.