Skip to content

Commit

Permalink
merging with main changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Huff authored and Ian Huff committed May 16, 2022
2 parents bf8e4ad + b88378a commit 044f453
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 71 deletions.
2 changes: 2 additions & 0 deletions news/1 Enhancements/8399.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Alert boxes of the form `<div style="alert alert-danger">` are now styled as colored boxes, to match how they are in Jupyter.
(thanks [Eric Wieser](https://github.com/eric-wieser/))
21 changes: 20 additions & 1 deletion resources/jupyter-markdown-style.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
/* These classnames are inherited from bootstrap, but are present in most notebook renderers */

.alert {
width: auto;
padding: 1em;
margin-top: 1em;
margin-bottom: 1em;
}
.alert > *:last-child {
margin-bottom: 0;
}
#preview > .alert:last-child {
/* Prevent this being set to zero by the default notebook stylesheet */
padding-bottom: 1em;
}

.alert-success {
/* Note there is no suitable color available, so we just copy "info" */
background-color: var(--theme-info-background);
color: var(--theme-info-foreground);
}
.alert-info {
background-color: var(--theme-info-background);
color: var(--theme-info-foreground);
Expand All @@ -11,4 +30,4 @@
.alert-danger {
background-color: var(--theme-error-background);
color: var(--theme-error-foreground);
}
}
11 changes: 10 additions & 1 deletion src/platform/debugger/jupyter/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { DebugProtocol } from 'vscode-debugprotocol';
import { IKernel } from '../../../kernels/types';
import { IKernelDebugAdapterConfig, KernelDebugMode } from '../types';
import { IKernelDebugAdapter, IKernelDebugAdapterConfig, KernelDebugMode } from '../types';

export enum IpykernelCheckResult {
Unknown,
Expand Down Expand Up @@ -122,3 +122,12 @@ export function shortNameMatchesLongName(shortNamePath: string, longNamePath: st
const r = new RegExp(shortNamePath.replace(/\\/g, '\\\\').replace(/~\d+\\\\/g, '[^\\\\]+\\\\'), 'i');
return r.test(longNamePath);
}

export async function cellDebugSetup(kernel: IKernel, debugAdapter: IKernelDebugAdapter): Promise<void> {
// remove this if when https://github.com/microsoft/debugpy/issues/706 is fixed and ipykernel ships it
// executing this code restarts debugpy and fixes https://github.com/microsoft/vscode-jupyter/issues/7251
const code = 'import debugpy\ndebugpy.debug_this_thread()';
await kernel.executeHidden(code);

await debugAdapter.dumpAllCells();
}
6 changes: 3 additions & 3 deletions src/platform/debugger/jupyter/kernelDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class KernelDebugAdapter implements DebugAdapter, IKernelDebugAdapter, ID
onDidSendMessage: Event<DebugProtocolMessage> = this.sendMessage.event;
onDidEndSession: Event<DebugSession> = this.endSession.event;
public readonly debugCell: NotebookCell | undefined;
private disconected: boolean = false;
private disconnected: boolean = false;
private kernelEventHook = (_event: 'willRestart' | 'willInterrupt') => this.disconnect();

constructor(
Expand Down Expand Up @@ -103,7 +103,7 @@ export class KernelDebugAdapter implements DebugAdapter, IKernelDebugAdapter, ID
if (
this.configuration.__cellIndex === cellStateChange.cell.index &&
cellStateChange.state === NotebookCellExecutionState.Idle &&
!this.disconected
!this.disconnected
) {
sendTelemetryEvent(DebuggingTelemetry.endedSession, undefined, { reason: 'normally' });
void this.disconnect();
Expand Down Expand Up @@ -184,7 +184,7 @@ export class KernelDebugAdapter implements DebugAdapter, IKernelDebugAdapter, ID
public async disconnect() {
await this.session.customRequest('disconnect', { restart: false });
this.endSession.fire(this.session);
this.disconected = true;
this.disconnected = true;
this.kernel?.removeEventHook(this.kernelEventHook);
}

Expand Down
37 changes: 37 additions & 0 deletions src/platform/debugger/jupyter/notebook/debugCellControllers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { DebugProtocolMessage, NotebookCell } from 'vscode';
import { DebugProtocol } from 'vscode-debugprotocol';
import { ICommandManager } from '../../../common/application/types';
import { IKernel } from '../../../../kernels/types';
import { sendTelemetryEvent } from '../../../../telemetry';
import { DebuggingTelemetry } from '../../constants';
import { IDebuggingDelegate, IKernelDebugAdapter } from '../../types';
import { cellDebugSetup } from '../helper';

export class DebugCellController implements IDebuggingDelegate {
constructor(
private readonly debugAdapter: IKernelDebugAdapter,
public readonly debugCell: NotebookCell,
private readonly kernel: IKernel,
private readonly commandManager: ICommandManager
) {
sendTelemetryEvent(DebuggingTelemetry.successfullyStartedRunAndDebugCell);
}

public async willSendEvent(_msg: DebugProtocolMessage): Promise<boolean> {
return false;
}

public async willSendRequest(request: DebugProtocol.Request): Promise<void> {
if (request.command === 'configurationDone') {
await cellDebugSetup(this.kernel, this.debugAdapter);

void this.commandManager.executeCommand('notebook.cell.execute', {
ranges: [{ start: this.debugCell.index, end: this.debugCell.index + 1 }],
document: this.debugCell.document.uri
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,25 @@ import {
EventEmitter,
NotebookEditor
} from 'vscode';
import * as path from '../../vscode-path/path';
import { IKernel, IKernelProvider } from '../../../kernels/types';
import { IConfigurationService, IDisposable } from '../../common/types';
import { KernelDebugAdapter } from './kernelDebugAdapter';
import { IExtensionSingleActivationService } from '../../activation/types';
import { ContextKey } from '../../common/contextKey';
import { IApplicationShell, ICommandManager, IVSCodeNotebook } from '../../common/application/types';
import { traceError, traceInfo, traceInfoIfCI } from '../../logging';
import { DataScience } from '../../common/utils/localize';
import { Commands as DSCommands, EditorContexts } from '../../../webviews/webview-side/common/constants';
import { IPlatformService } from '../../common/platform/types';
import { IDebuggingManager, IKernelDebugAdapterConfig, KernelDebugMode } from '../types';
import { DebuggingTelemetry, pythonKernelDebugAdapter } from '../constants';
import { sendTelemetryEvent } from '../../../telemetry';
import { DebugCellController, RunByLineController } from './debugControllers';
import { assertIsDebugConfig, IpykernelCheckResult, isUsingIpykernel6OrLater } from './helper';
import { Debugger } from './debugger';
import { INotebookControllerManager } from '../../../notebooks/types';
import * as path from '../../../vscode-path/path';
import { IKernel, IKernelProvider } from '../../../../kernels/types';
import { IConfigurationService, IDisposable } from '../../../common/types';
import { KernelDebugAdapter } from '../kernelDebugAdapter';
import { IExtensionSingleActivationService } from '../../../activation/types';
import { ContextKey } from '../../../common/contextKey';
import { IApplicationShell, ICommandManager, IVSCodeNotebook } from '../../../common/application/types';
import { traceError, traceInfo, traceInfoIfCI } from '../../../logging';
import { DataScience } from '../../../common/utils/localize';
import { Commands as DSCommands, EditorContexts } from '../../../../webviews/webview-side/common/constants';
import { IPlatformService } from '../../../common/platform/types';
import { IDebuggingManager, IKernelDebugAdapterConfig, KernelDebugMode } from '../../types';
import { DebuggingTelemetry, pythonKernelDebugAdapter } from '../../constants';
import { sendTelemetryEvent } from '../../../../telemetry';
import { DebugCellController } from './debugCellControllers';
import { assertIsDebugConfig, IpykernelCheckResult, isUsingIpykernel6OrLater } from '../helper';
import { Debugger } from '../debugger';
import { INotebookControllerManager } from '../../../../notebooks/types';
import { RunByLineController } from './runByLineController';

/**
* The DebuggingManager maintains the mapping between notebook documents and debug sessions.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import * as path from '../../vscode-path/path';
import * as path from '../../../vscode-path/path';
import { DebugProtocolMessage, NotebookCell } from 'vscode';
import { DebugProtocol } from 'vscode-debugprotocol';
import { parseForComments } from '../../../webviews/webview-side/common';
import { ICommandManager } from '../../common/application/types';
import { traceInfoIfCI, traceVerbose } from '../../logging';
import { IConfigurationService } from '../../common/types';
import { noop } from '../../common/utils/misc';
import { IKernel } from '../../../kernels/types';
import { sendTelemetryEvent } from '../../../telemetry';
import { DebuggingTelemetry } from '../constants';
import { IDebuggingDelegate, IKernelDebugAdapter, KernelDebugMode } from '../types';
import { Commands } from '../../common/constants';

export class DebugCellController implements IDebuggingDelegate {
constructor(
private readonly debugAdapter: IKernelDebugAdapter,
public readonly debugCell: NotebookCell,
private readonly kernel: IKernel,
private readonly commandManager: ICommandManager
) {
sendTelemetryEvent(DebuggingTelemetry.successfullyStartedRunAndDebugCell);
}

public async willSendEvent(_msg: DebugProtocolMessage): Promise<boolean> {
return false;
}

public async willSendRequest(request: DebugProtocol.Request): Promise<void> {
if (request.command === 'configurationDone') {
await cellDebugSetup(this.kernel, this.debugAdapter);

void this.commandManager.executeCommand('notebook.cell.execute', {
ranges: [{ start: this.debugCell.index, end: this.debugCell.index + 1 }],
document: this.debugCell.document.uri
});
}
}
}
import { parseForComments } from '../../../../webviews/webview-side/common';
import { ICommandManager } from '../../../common/application/types';
import { traceInfoIfCI, traceVerbose } from '../../../logging';
import { IConfigurationService } from '../../../common/types';
import { noop } from '../../../common/utils/misc';
import { IKernel } from '../../../../kernels/types';
import { sendTelemetryEvent } from '../../../../telemetry';
import { DebuggingTelemetry } from '../../constants';
import { IDebuggingDelegate, IKernelDebugAdapter, KernelDebugMode } from '../../types';
import { Commands } from '../../../common/constants';
import { cellDebugSetup } from '../helper';

export class RunByLineController implements IDebuggingDelegate {
private lastPausedThreadId: number | undefined;
Expand Down Expand Up @@ -170,12 +145,3 @@ export class RunByLineController implements IDebuggingDelegate {
});
}
}

async function cellDebugSetup(kernel: IKernel, debugAdapter: IKernelDebugAdapter): Promise<void> {
// remove this if when https://github.com/microsoft/debugpy/issues/706 is fixed and ipykernel ships it
// executing this code restarts debugpy and fixes https://github.com/microsoft/vscode-jupyter/issues/7251
const code = 'import debugpy\ndebugpy.debug_this_thread()';
await kernel.executeHidden(code);

await debugAdapter.dumpAllCells();
}
2 changes: 1 addition & 1 deletion src/platform/serviceRegistry.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { GlobalActivation } from './common/globalActivation';
import { PreReleaseChecker } from './common/prereleaseChecker.node';
import { IConfigurationService, IDataScienceCommandListener, IExtensionContext } from './common/types';
import { DebugLocationTrackerFactory } from './debugger/debugLocationTrackerFactory.node';
import { DebuggingManager } from './debugger/jupyter/debuggingManager';
import { DebuggingManager } from './debugger/jupyter/notebook/debuggingManager';
import { IDebugLocationTracker, IDebuggingManager } from './debugger/types';
import { DataScienceErrorHandler } from './errors/errorHandler';
import { IDataScienceErrorHandler } from './errors/types';
Expand Down
2 changes: 1 addition & 1 deletion src/platform/serviceRegistry.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { IExtensionSingleActivationService } from './activation/types';
import { ExtensionSideRenderer, IExtensionSideRenderer } from '../webviews/extension-side/renderer';
import { OutputCommandListener } from './logging/outputCommandListener';
import { IDebuggingManager } from './debugger/types';
import { DebuggingManager } from './debugger/jupyter/debuggingManager';
import { DebuggingManager } from './debugger/jupyter/notebook/debuggingManager';
import { ExportDialog } from './export/exportDialog';
import { ExportFormat, IExport, IExportDialog, IFileConverter } from './export/types';
import { FileConverter } from './export/fileConverter.web';
Expand Down

0 comments on commit 044f453

Please sign in to comment.