Skip to content

Commit 200ca1a

Browse files
committed
big progress
1 parent bc15f8f commit 200ca1a

File tree

1 file changed

+90
-5
lines changed

1 file changed

+90
-5
lines changed

src/client/repl/replCommands.ts

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
1-
import { commands, Uri, workspace } from 'vscode';
1+
import {
2+
commands,
3+
NotebookController,
4+
Uri,
5+
workspace,
6+
window,
7+
NotebookControllerAffinity,
8+
ViewColumn,
9+
NotebookEdit,
10+
NotebookCellData,
11+
NotebookCellKind,
12+
WorkspaceEdit,
13+
} from 'vscode';
214
import { Disposable } from 'vscode-jsonrpc';
3-
import { Commands } from '../common/constants';
15+
import { Commands, PVSC_EXTENSION_ID } from '../common/constants';
416
import { IInterpreterService } from '../interpreter/contracts';
517
import { createReplController, startRepl } from './replController';
618

19+
let ourController: NotebookController | undefined;
20+
721
export function registerReplCommands(disposables: Disposable[], interpreterService: IInterpreterService): void {
822
disposables.push(
923
commands.registerCommand(Commands.Exec_In_REPL, async (uri: Uri) => {
1024
const interpreter = await interpreterService.getActiveInterpreter(uri);
1125
if (interpreter) {
1226
const interpreterPath = interpreter.path;
1327
// How do we get instance of interactive window from Python extension?
14-
const ourController = createReplController(interpreterPath);
28+
if (!ourController) {
29+
ourController = createReplController(interpreterPath);
30+
}
1531

1632
// How to go from user clicking Run Python --> Run selection/line via Python REPL -> IW opening
1733

@@ -24,8 +40,77 @@ export function registerReplCommands(disposables: Disposable[], interpreterServi
2440
// TODO: execute the cell
2541
}
2642
// workspace.onDidOpenNotebookDocument;
27-
// await workspace.openNotebookDocument('interactive');
28-
// await window.showNotebookDocument()
43+
const ourResource = Uri.from({ scheme: 'untitled', path: 'repl.interactive' });
44+
const notebookDocument = await workspace.openNotebookDocument(ourResource);
45+
46+
const notebookEditor = await window.showNotebookDocument(notebookDocument, {
47+
viewColumn: ViewColumn.Beside,
48+
});
49+
50+
ourController!.updateNotebookAffinity(notebookDocument, NotebookControllerAffinity.Default);
51+
// await commands.executeCommand(
52+
// 'interactive.open',
53+
// // Keep focus on the owning file if there is one
54+
// { viewColum: 1, preserveFocus: true },
55+
// ourResource,
56+
// ourController?.id,
57+
// 'Python REPL',
58+
// );
59+
60+
await commands.executeCommand('notebook.selectKernel', {
61+
notebookEditor,
62+
id: ourController?.id,
63+
extension: PVSC_EXTENSION_ID,
64+
});
65+
66+
const notebookCellData = new NotebookCellData(NotebookCellKind.Code, 'x=5', 'python');
67+
// keep counter
68+
const { cellCount } = notebookDocument;
69+
const notebookEdit = NotebookEdit.insertCells(cellCount, [notebookCellData]);
70+
const workspaceEdit = new WorkspaceEdit();
71+
workspaceEdit.set(notebookDocument.uri, [notebookEdit]);
72+
workspace.applyEdit(workspaceEdit);
73+
74+
const notebookCellExecution = ourController!.createNotebookCellExecution(
75+
notebookDocument.cellAt(cellCount),
76+
);
77+
notebookCellExecution.start(Date.now());
78+
// NEED TO TELL TO EXECUTE THE CELL WHICH WILL CALL MY HANDLER
79+
80+
// args: [
81+
// {
82+
// name: 'showOptions',
83+
// description: 'Show Options',
84+
// schema: {
85+
// type: 'object',
86+
// properties: {
87+
// 'viewColumn': {
88+
// type: 'number',
89+
// default: -1
90+
// },
91+
// 'preserveFocus': {
92+
// type: 'boolean',
93+
// default: true
94+
// }
95+
// },
96+
// }
97+
// },
98+
// {
99+
// name: 'resource',
100+
// description: 'Interactive resource Uri',
101+
// isOptional: true
102+
// },
103+
// {
104+
// name: 'controllerId',
105+
// description: 'Notebook controller Id',
106+
// isOptional: true
107+
// },
108+
// {
109+
// name: 'title',
110+
// description: 'Notebook editor title',
111+
// isOptional: true
112+
// }
113+
// ]
29114
}),
30115
);
31116
}

0 commit comments

Comments
 (0)