Skip to content

Commit fd074ef

Browse files
working E2E
1 parent 33acc09 commit fd074ef

5 files changed

Lines changed: 62 additions & 148 deletions

File tree

src/client/common/application/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ interface ICommandNameWithoutArgumentTypeMapping {
2222
[Commands.Set_ShebangInterpreter]: [];
2323
[Commands.Run_Linter]: [];
2424
[Commands.Enable_Linter]: [];
25+
['workbench.action.debug.stop']: [];
2526
['workbench.action.reloadWindow']: [];
2627
['editor.action.formatDocument']: [];
2728
['editor.action.rename']: [];

src/client/datascience/editor-integration/codewatcher.ts

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,14 @@ export class CodeWatcher implements ICodeWatcher {
9393
return this.codeLenses;
9494
}
9595

96+
// IANHU: Add Telemetry
9697
public async debugCurrentCell() {
9798
if (!this.documentManager.activeTextEditor || !this.documentManager.activeTextEditor.document) {
9899
return Promise.resolve();
99100
}
100101

101102
// Run the cell that matches the current cursor position.
102-
return this.debugMatchingCell(this.documentManager.activeTextEditor.selection, false);
103+
return this.runMatchingCell(this.documentManager.activeTextEditor.selection, false, true);
103104
}
104105

105106
@captureTelemetry(Telemetry.RunAllCells)
@@ -260,7 +261,42 @@ export class CodeWatcher implements ICodeWatcher {
260261
}
261262

262263
// IANHU: Duplicating too much with run commands, perhaps debug is a parameter on run?
263-
private async debugMatchingCell(range: Range, advance?: boolean) {
264+
//private async debugMatchingCell(range: Range, advance?: boolean) {
265+
//const currentRunCellLens = this.getCurrentCellLens(range.start);
266+
//const nextRunCellLens = this.getNextCellLens(range.start);
267+
268+
//if (currentRunCellLens) {
269+
//// Move the next cell if allowed.
270+
//if (advance) {
271+
//// Either use the next cell that we found, or add a new one into the document
272+
//let nextRange: Range;
273+
//if (!nextRunCellLens) {
274+
//nextRange = this.createNewCell(currentRunCellLens.range);
275+
//} else {
276+
//nextRange = nextRunCellLens.range;
277+
//}
278+
279+
//if (nextRange) {
280+
//this.advanceToRange(nextRange);
281+
//}
282+
//}
283+
284+
//// Run the cell after moving the selection
285+
//if (this.document) {
286+
//// Use that to get our code.
287+
//const code = this.document.getText(currentRunCellLens.range);
288+
289+
//try {
290+
//const activeInteractiveWindow = await this.interactiveWindowProvider.getOrCreateActive();
291+
//await activeInteractiveWindow.addCode(code, this.getFileName(), range.start.line, this.documentManager.activeTextEditor, true);
292+
//} catch (err) {
293+
//this.handleError(err);
294+
//}
295+
//}
296+
//}
297+
//}
298+
299+
private async runMatchingCell(range: Range, advance?: boolean, debug?: boolean) {
264300
const currentRunCellLens = this.getCurrentCellLens(range.start);
265301
const nextRunCellLens = this.getNextCellLens(range.start);
266302

@@ -287,42 +323,7 @@ export class CodeWatcher implements ICodeWatcher {
287323

288324
try {
289325
const activeInteractiveWindow = await this.interactiveWindowProvider.getOrCreateActive();
290-
await activeInteractiveWindow.debugCode(code, this.getFileName(), range.start.line, this.documentManager.activeTextEditor);
291-
} catch (err) {
292-
this.handleError(err);
293-
}
294-
}
295-
}
296-
}
297-
298-
private async runMatchingCell(range: Range, advance?: boolean) {
299-
const currentRunCellLens = this.getCurrentCellLens(range.start);
300-
const nextRunCellLens = this.getNextCellLens(range.start);
301-
302-
if (currentRunCellLens) {
303-
// Move the next cell if allowed.
304-
if (advance) {
305-
// Either use the next cell that we found, or add a new one into the document
306-
let nextRange: Range;
307-
if (!nextRunCellLens) {
308-
nextRange = this.createNewCell(currentRunCellLens.range);
309-
} else {
310-
nextRange = nextRunCellLens.range;
311-
}
312-
313-
if (nextRange) {
314-
this.advanceToRange(nextRange);
315-
}
316-
}
317-
318-
// Run the cell after moving the selection
319-
if (this.document) {
320-
// Use that to get our code.
321-
const code = this.document.getText(currentRunCellLens.range);
322-
323-
try {
324-
const activeInteractiveWindow = await this.interactiveWindowProvider.getOrCreateActive();
325-
await activeInteractiveWindow.addCode(code, this.getFileName(), range.start.line, this.documentManager.activeTextEditor);
326+
await activeInteractiveWindow.addCode(code, this.getFileName(), range.start.line, this.documentManager.activeTextEditor, debug);
326327
} catch (err) {
327328
this.handleError(err);
328329
}

src/client/datascience/interactive-window/interactiveWindow.ts

Lines changed: 19 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { ContextKey } from '../../common/contextKey';
2727
import { traceInfo, traceWarning } from '../../common/logger';
2828
import { IFileSystem } from '../../common/platform/types';
2929
import { IConfigurationService, IDisposableRegistry, ILogger } from '../../common/types';
30-
import { createDeferred, Deferred, sleep } from '../../common/utils/async';
30+
import { createDeferred, Deferred } from '../../common/utils/async';
3131
import * as localize from '../../common/utils/localize';
3232
import { IInterpreterService, PythonInterpreter } from '../../interpreter/contracts';
3333
import { captureTelemetry, sendTelemetryEvent } from '../../telemetry';
@@ -180,14 +180,9 @@ export class InteractiveWindow extends WebViewHost<IInteractiveWindowMapping> im
180180
return this.executeEvent.event;
181181
}
182182

183-
public addCode(code: string, file: string, line: number, editor?: TextEditor) : Promise<void> {
183+
public addCode(code: string, file: string, line: number, editor?: TextEditor, debug?: boolean) : Promise<void> {
184184
// Call the internal method.
185-
return this.submitCode(code, file, line, undefined, editor);
186-
}
187-
188-
public debugCode(code: string, file: string, line: number, editor?: TextEditor) : Promise<void> {
189-
// Call the internal method.
190-
return this.debugCodeInternal(code, file, line, undefined, editor);
185+
return this.submitCode(code, file, line, undefined, editor, debug);
191186
}
192187

193188
// tslint:disable-next-line: no-any no-empty cyclomatic-complexity max-func-body-length
@@ -700,7 +695,7 @@ export class InteractiveWindow extends WebViewHost<IInteractiveWindowMapping> im
700695
}
701696
}
702697

703-
private async submitCode(code: string, file: string, line: number, id?: string, _editor?: TextEditor) : Promise<void> {
698+
private async submitCode(code: string, file: string, line: number, id?: string, _editor?: TextEditor, debug?: boolean) : Promise<void> {
704699
this.logger.logInformation(`Submitting code for ${this.id}`);
705700

706701
// Start a status item
@@ -749,6 +744,11 @@ export class InteractiveWindow extends WebViewHost<IInteractiveWindowMapping> im
749744
await this.jupyterServer.setInitialDirectory(path.dirname(file));
750745
}
751746

747+
if (debug) {
748+
// Attach our debugger
749+
await this.debuggerAttach();
750+
}
751+
752752
// Attempt to evaluate this cell in the jupyter notebook
753753
const observable = this.jupyterServer.executeObservable(code, file, line, id, false);
754754

@@ -774,6 +774,11 @@ export class InteractiveWindow extends WebViewHost<IInteractiveWindowMapping> im
774774
// Wait for the cell to finish
775775
await finishedAddingCode.promise;
776776
traceInfo(`Finished execution for ${id}`);
777+
778+
// IANHU: Right spot here?
779+
if (debug) {
780+
this.debuggerDetach();
781+
}
777782
}
778783
} catch (err) {
779784
status.dispose();
@@ -788,12 +793,6 @@ export class InteractiveWindow extends WebViewHost<IInteractiveWindowMapping> im
788793
// Get our connection info
789794
const debugConnectInfo = await this.jupyterServer.getDebuggerInfo();
790795

791-
// tslint:disable-next-line:no-multiline-string
792-
this.jupyterServer.execute(`import ptvsd\r\nptvsd.wait_for_attach()`, Identifiers.EmptyFileName, 0, uuid(), undefined, true);
793-
794-
// IANHU: Not right. Just giving time to see if we have actually executed
795-
await sleep(4000);
796-
797796
if (debugConnectInfo) {
798797
// First connect the VSCode UI
799798
const config: DebugConfiguration = {
@@ -807,6 +806,9 @@ export class InteractiveWindow extends WebViewHost<IInteractiveWindowMapping> im
807806
await this.debugService.startDebugging(undefined, config);
808807
}
809808

809+
// tslint:disable-next-line:no-multiline-string
810+
await this.jupyterServer.execute(`import ptvsd\r\nptvsd.wait_for_attach()`, Identifiers.EmptyFileName, 0, uuid(), undefined, true);
811+
810812
// Then enable tracing
811813
await this.jupyterServer.setDebugTracing(true);
812814
}
@@ -819,98 +821,8 @@ export class InteractiveWindow extends WebViewHost<IInteractiveWindowMapping> im
819821
}
820822

821823
// Stop our debugging UI session
822-
//if (this.debugService.activeDebugSession) {
823-
//this.debugService.activeDebugSession.
824-
//}
825-
}
826-
827-
private async debugCodeInternal(code: string, file: string, line: number, id?: string, _editor?: TextEditor) : Promise<void> {
828-
this.logger.logInformation(`Submitting code for ${this.id}`);
829-
830-
// Start a status item
831-
const status = this.setStatus(localize.DataScience.executingCode());
832-
833-
// Transmit this submission to all other listeners (in a live share session)
834-
if (!id) {
835-
id = uuid();
836-
this.shareMessage(InteractiveWindowMessages.RemoteAddCode, {code, file, line, id, originator: this.id});
837-
}
838-
839-
// Create a deferred object that will wait until the status is disposed
840-
const finishedAddingCode = createDeferred<void>();
841-
const actualDispose = status.dispose.bind(status);
842-
status.dispose = () => {
843-
finishedAddingCode.resolve();
844-
actualDispose();
845-
};
846-
847-
try {
848-
849-
// Make sure we're loaded first.
850-
try {
851-
this.logger.logInformation('Waiting for jupyter server and web panel ...');
852-
await this.loadPromise;
853-
} catch (exc) {
854-
// We should dispose ourselves if the load fails. Othewise the user
855-
// updates their install and we just fail again because the load promise is the same.
856-
this.dispose();
857-
858-
throw exc;
859-
}
860-
861-
// Then show our webpanel
862-
await this.show();
863-
864-
// Add our sys info if necessary
865-
if (file !== Identifiers.EmptyFileName) {
866-
await this.addSysInfo(SysInfoReason.Start);
867-
}
868-
869-
if (this.jupyterServer) {
870-
// Before we try to execute code make sure that we have an initial directory set
871-
// Normally set via the workspace, but we might not have one here if loading a single loose file
872-
if (file !== Identifiers.EmptyFileName) {
873-
await this.jupyterServer.setInitialDirectory(path.dirname(file));
874-
}
875-
876-
// Attach our debugger
877-
await this.debuggerAttach();
878-
879-
// Attempt to evaluate this cell in the jupyter notebook
880-
const observable = this.jupyterServer.executeObservable(code, file, line, id, false);
881-
882-
// Indicate we executed some code
883-
this.executeEvent.fire(code);
884-
885-
// Sign up for cell changes
886-
observable.subscribe(
887-
(cells: ICell[]) => {
888-
this.onAddCodeEvent(cells, undefined);
889-
},
890-
(error) => {
891-
status.dispose();
892-
if (!(error instanceof CancellationError)) {
893-
this.applicationShell.showErrorMessage(error.toString());
894-
}
895-
},
896-
() => {
897-
// Indicate executing until this cell is done.
898-
status.dispose();
899-
});
900-
901-
// Wait for the cell to finish
902-
await finishedAddingCode.promise;
903-
traceInfo(`Finished execution for ${id}`);
904-
905-
// Detach our debugger
906-
this.debuggerDetach();
907-
}
908-
} catch (err) {
909-
status.dispose();
910-
911-
const message = localize.DataScience.executingCodeFailure().format(err);
912-
this.applicationShell.showErrorMessage(message);
913-
}
824+
// IANHU: await not needed here?
825+
await this.commandManager.executeCommand('workbench.action.debug.stop');
914826
}
915827

916828
private setStatus = (message: string): Disposable => {

src/client/datascience/jupyter/jupyterServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ export class JupyterServerBase implements INotebookServer {
424424
}
425425

426426
public async setDebugTracing(tracingOn: boolean): Promise<void> {
427-
const silentResults = await this.executeSilently(`from ptvsd import tracing\r\ntracing(${tracingOn ? 'True' : 'False'})`);
427+
await this.executeSilently(`from ptvsd import tracing\r\ntracing(${tracingOn ? 'True' : 'False'})`);
428428
}
429429

430430
public getDebuggerInfo(): Promise<IDebuggerConnectInfo | undefined> {

src/client/datascience/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ export interface IInteractiveWindow extends Disposable {
178178
ready: Promise<void>;
179179
onExecutedCode: Event<string>;
180180
show() : Promise<void>;
181-
addCode(code: string, file: string, line: number, editor?: TextEditor) : Promise<void>;
181+
addCode(code: string, file: string, line: number, editor?: TextEditor, debug?: boolean) : Promise<void>;
182182
// IANHU combine with add code
183-
debugCode(code: string, file: string, line: number, editor?: TextEditor): Promise<void>;
183+
//debugCode(code: string, file: string, line: number, editor?: TextEditor): Promise<void>;
184184
// tslint:disable-next-line:no-any
185185
startProgress(): void;
186186
stopProgress(): void;

0 commit comments

Comments
 (0)