Skip to content

Commit 2412a58

Browse files
cherry pick from master branch
1 parent 0d96d3a commit 2412a58

12 files changed

Lines changed: 99 additions & 22 deletions

File tree

news/1 Enhancements/4855.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add "Run In Interactive" command to run the contents of a file not cell by cell. Group data science context commands in one group. Add run file command to explorer context menu.

package.json

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,14 @@
340340
"title": "%python.command.python.datascience.showhistorypane.title%",
341341
"category": "Python"
342342
},
343+
{
344+
"command": "python.datascience.runFileInteractive",
345+
"title": "%python.command.python.datascience.runFileInteractive.title%",
346+
"category": "Python"
347+
},
343348
{
344349
"command": "python.datascience.runallcells",
345-
"title": "%python.command.python.datascience.runallcells.command.title%",
350+
"title": "%python.command.python.datascience.runallcells.title%",
346351
"category": "Python"
347352
},
348353
{
@@ -472,50 +477,55 @@
472477
"command": "python.runCurrentTestFile",
473478
"group": "Python"
474479
},
480+
{
481+
"when": "editorFocus && editorLangId == python && python.datascience.hascodecells && python.datascience.featureenabled",
482+
"command": "python.datascience.runallcells",
483+
"group": "Python2"
484+
},
475485
{
476486
"when": "editorFocus && editorLangId == python && python.datascience.hascodecells && python.datascience.featureenabled",
477487
"command": "python.datascience.runcurrentcell",
478-
"group": "Python"
488+
"group": "Python2"
479489
},
480490
{
481491
"when": "editorFocus && editorLangId == python && python.datascience.hascodecells && python.datascience.featureenabled",
482492
"command": "python.datascience.runcurrentcelladvance",
483-
"group": "Python"
493+
"group": "Python2"
484494
},
485495
{
486-
"command": "python.datascience.runallcells",
487-
"group": "Python",
488-
"when": "editorFocus && editorLangId == python && python.datascience.hascodecells && python.datascience.featureenabled"
496+
"command": "python.datascience.runFileInteractive",
497+
"group": "Python2",
498+
"when": "editorFocus && editorLangId == python && python.datascience.featureenabled"
489499
},
490500
{
491501
"command": "python.datascience.runfromline",
492-
"group": "Python",
502+
"group": "Python2",
493503
"when": "editorFocus && editorLangId == python && python.datascience.ownsSelection && python.datascience.featureenabled"
494504
},
495505
{
496506
"command": "python.datascience.runtoline",
497-
"group": "Python",
507+
"group": "Python2",
498508
"when": "editorFocus && editorLangId == python && python.datascience.ownsSelection && python.datascience.featureenabled"
499509
},
500510
{
501511
"command": "python.datascience.execSelectionInteractive",
502-
"group": "Python",
512+
"group": "Python2",
503513
"when": "editorFocus && editorLangId == python && python.datascience.featureenabled && python.datascience.ownsSelection"
504514
},
505515
{
506516
"when": "editorFocus && editorLangId == python && resourceLangId == jupyter && python.datascience.featureenabled",
507517
"command": "python.datascience.importnotebook",
508-
"group": "Python"
518+
"group": "Python3@1"
509519
},
510520
{
511521
"when": "editorFocus && editorLangId == python && python.datascience.hascodecells && python.datascience.featureenabled",
512522
"command": "python.datascience.exportfileasnotebook",
513-
"group": "Python2"
523+
"group": "Python3@2"
514524
},
515525
{
516526
"when": "editorFocus && editorLangId == python && python.datascience.hascodecells && python.datascience.featureenabled",
517527
"command": "python.datascience.exportfileandoutputasnotebook",
518-
"group": "Python2@2"
528+
"group": "Python3@3"
519529
}
520530
],
521531
"explorer/context": [
@@ -534,6 +544,11 @@
534544
"command": "python.execInTerminal",
535545
"group": "Python"
536546
},
547+
{
548+
"when": "resourceLangId == python && python.datascience.featureenabled",
549+
"command": "python.datascience.runFileInteractive",
550+
"group": "Python2"
551+
},
537552
{
538553
"when": "resourceLangId == jupyter",
539554
"command": "python.datascience.importnotebook",
@@ -594,7 +609,7 @@
594609
},
595610
{
596611
"command": "python.datascience.runallcells",
597-
"title": "%python.command.python.datascience.runallcells.command.title%",
612+
"title": "%python.command.python.datascience.runallcells.title%",
598613
"category": "Python",
599614
"when": "python.datascience.featureenabled"
600615
},
@@ -604,6 +619,12 @@
604619
"category": "Python",
605620
"when": "python.datascience.featureenabled"
606621
},
622+
{
623+
"command": "python.datascience.runFileInteractive",
624+
"title": "%python.command.python.datascience.runFileInteractive.title%",
625+
"category": "Python",
626+
"when": "python.datascience.featureenabled"
627+
},
607628
{
608629
"command": "python.datascience.importnotebook",
609630
"title": "%python.command.python.datascience.importnotebook.title%",

package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"python.command.python.setLinter.title": "Select Linter",
2727
"python.command.python.enableLinting.title": "Enable Linting",
2828
"python.command.python.runLinting.title": "Run Linting",
29-
"python.command.python.datascience.runallcells.command.title": "Run Current File in Python Interactive window",
29+
"python.command.python.datascience.runFileInteractive.title": "Run Current File in Python Interactive Window",
3030
"python.command.python.datascience.runallcells.title": "Run All Cells",
3131
"python.command.python.datascience.runallcellsabove.title": "Run Above",
3232
"python.command.python.datascience.runcellandallbelow.title": "Run Below",

package.nls.nl.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"python.command.python.setLinter.title": "Linter selecteren",
2424
"python.command.python.enableLinting.title": "Linting activeren",
2525
"python.command.python.runLinting.title": "Linting uitvoeren",
26-
"python.command.python.datascience.runallcells.command.title": "Huidige bestand in interactief Python-venster uitvoeren",
2726
"python.command.python.datascience.runallcells.title": "Alle cellen uitvoeren",
2827
"python.command.python.datascience.runcurrentcell.title": "Huidige cel uitvoeren",
2928
"python.command.python.datascience.runcurrentcelladvance.title": "Huidige cel uitvoeren en doorgaan",

package.nls.pl.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"python.command.python.setLinter.title": "Wybierz linter",
2626
"python.command.python.enableLinting.title": "Włącz linting",
2727
"python.command.python.runLinting.title": "Uruchom linting",
28-
"python.command.python.datascience.runallcells.command.title": "Uruchom bieżący plik w oknie IPythona",
2928
"python.command.python.datascience.runallcells.title": "Uruchom wszystkie komórki",
3029
"python.command.python.datascience.runcurrentcell.title": "Uruchom bieżącą komórkę",
3130
"python.command.python.datascience.runcurrentcelladvance.title": "Uruchom bieżące komórki i pokaż",

src/client/common/application/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,5 @@ export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgu
100100
[DSCommands.RunFromLine]: [string, number, number];
101101
[DSCommands.ImportNotebook]: [undefined | Uri, undefined | CommandSource];
102102
[DSCommands.ExportFileAsNotebook]: [undefined | Uri, undefined | CommandSource];
103+
[DSCommands.RunFileInInteractiveWindows]: [string];
103104
}

src/client/datascience/constants.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export namespace Commands {
3030
export const CollapseAllCells = 'python.datascience.collapseallcells';
3131
export const ExportOutputAsNotebook = 'python.datascience.exportoutputasnotebook';
3232
export const ExecSelectionInInteractiveWindow = 'python.datascience.execSelectionInteractive';
33+
export const RunFileInInteractiveWindows = 'python.datascience.runFileInteractive';
3334
}
3435

3536
export namespace EditorContexts {
@@ -90,7 +91,8 @@ export enum Telemetry {
9091
ConnectRemoteFailedJupyter = 'DATASCIENCE.CONNECTREMOTEFAILEDJUPYTER',
9192
RemoteAddCode = 'DATASCIENCE.LIVESHARE.ADDCODE',
9293
ShiftEnterBannerShown = 'DATASCIENCE.SHIFTENTER_BANNER_SHOWN',
93-
EnableInteractiveShiftEnter = 'DATASCIENCE.ENABLE_INTERACTIVE_SHIFT_ENTER'
94+
EnableInteractiveShiftEnter = 'DATASCIENCE.ENABLE_INTERACTIVE_SHIFT_ENTER',
95+
RunFileInteractive = 'DATASCIENCE.RUN_FILE_INTERACTIVE'
9496
}
9597

9698
export namespace HelpLinks {

src/client/datascience/datascience.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ export class DataScience implements IDataScience {
7474
}
7575
}
7676

77+
public async runFileInteractive(file: string): Promise<void> {
78+
this.dataScienceSurveyBanner.showBanner().ignoreErrors();
79+
80+
let codeWatcher = this.getCodeWatcher(file);
81+
if (!codeWatcher) {
82+
codeWatcher = this.getCurrentCodeWatcher();
83+
}
84+
if (codeWatcher) {
85+
return codeWatcher.runFileInteractive();
86+
} else {
87+
return Promise.resolve();
88+
}
89+
}
90+
7791
public async runAllCells(file: string): Promise<void> {
7892
this.dataScienceSurveyBanner.showBanner().ignoreErrors();
7993

@@ -278,6 +292,8 @@ export class DataScience implements IDataScience {
278292
this.disposableRegistry.push(disposable);
279293
disposable = this.commandManager.registerCommand(Commands.RunFromLine, this.runFromLine, this);
280294
this.disposableRegistry.push(disposable);
295+
disposable = this.commandManager.registerCommand(Commands.RunFileInInteractiveWindows, this.runFileInteractive, this);
296+
this.disposableRegistry.push(disposable);
281297
this.commandListeners.forEach((listener: IDataScienceCommandListener) => {
282298
listener.register(this.commandManager);
283299
});

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,15 @@ export class CodeWatcher implements ICodeWatcher {
108108

109109
// If there are no codelenses, just run all of the code as a single cell
110110
if (this.codeLenses.length === 0) {
111-
if (this.document) {
112-
const code = this.document.getText();
113-
const activeHistory = await this.historyProvider.getOrCreateActive();
114-
await activeHistory.addCode(code, this.getFileName(), 0);
115-
}
111+
return this.runFileInteractiveInternal();
116112
}
117113
}
118114

115+
@captureTelemetry(Telemetry.RunFileInteractive)
116+
public async runFileInteractive() {
117+
return this.runFileInteractiveInternal();
118+
}
119+
119120
// Run all cells up to the cell containing this start line and character
120121
@captureTelemetry(Telemetry.RunAllCellsAbove)
121122
public async runAllCellsAbove(stopLine: number, stopCharacter: number) {
@@ -274,6 +275,14 @@ export class CodeWatcher implements ICodeWatcher {
274275
}
275276
}
276277

278+
private async runFileInteractiveInternal() {
279+
if (this.document) {
280+
const code = this.document.getText();
281+
const activeHistory = await this.historyProvider.getOrCreateActive();
282+
await activeHistory.addCode(code, this.getFileName(), 0);
283+
}
284+
}
285+
277286
// tslint:disable-next-line:no-any
278287
private handleError = (err : any) => {
279288
if (err instanceof JupyterInstallError) {

src/client/datascience/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ export interface ICodeWatcher {
179179
runFromLine(targetLine: number): Promise<void>;
180180
runAllCellsAbove(stopLine: number, stopCharacter: number): Promise<void>;
181181
runCellAndAllBelow(startLine: number, startCharacter: number): Promise<void>;
182+
runFileInteractive(): Promise<void>;
182183
}
183184

184185
export enum CellState {

0 commit comments

Comments
 (0)