@@ -65,94 +65,93 @@ export async function registerReplCommands(disposables: Disposable[], interprete
65
65
const activeEditor = window . activeTextEditor as TextEditor ;
66
66
67
67
const code = await getSelectedTextToExecute ( activeEditor ) ;
68
- }
68
+ const ourResource = Uri . from ( { scheme : 'untitled' , path : 'repl.interactive' } ) ;
69
+ // How to go from user clicking Run Python --> Run selection/line via Python REPL -> IW opening
70
+ const notebookDocument = await workspace . openNotebookDocument ( ourResource ) ;
71
+ // We want to keep notebookEditor, whenever we want to run.
72
+ // Find interactive window, or open it.
73
+ if ( ! ourNotebookEditor ) {
74
+ ourNotebookEditor = await window . showNotebookDocument ( notebookDocument , {
75
+ viewColumn : ViewColumn . Beside ,
76
+ } ) ;
77
+ }
69
78
70
- const ourResource = Uri . from ( { scheme : 'untitled' , path : 'repl.interactive' } ) ;
71
- // How to go from user clicking Run Python --> Run selection/line via Python REPL -> IW opening
72
- const notebookDocument = await workspace . openNotebookDocument ( ourResource ) ;
73
- // We want to keep notebookEditor, whenever we want to run.
74
- // Find interactive window, or open it.
75
- if ( ! ourNotebookEditor ) {
76
- ourNotebookEditor = await window . showNotebookDocument ( notebookDocument , {
77
- viewColumn : ViewColumn . Beside ,
79
+ ourController ! . updateNotebookAffinity ( notebookDocument , NotebookControllerAffinity . Default ) ;
80
+ // await commands.executeCommand(
81
+ // 'interactive.open',
82
+ // // Keep focus on the owning file if there is one
83
+ // { viewColum: 1, preserveFocus: true },
84
+ // ourResource,
85
+ // ourController?.id,
86
+ // 'Python REPL',
87
+ // );
88
+
89
+ // Auto-Select Python REPL Kernel
90
+ await commands . executeCommand ( 'notebook.selectKernel' , {
91
+ ourNotebookEditor,
92
+ id : ourController ?. id ,
93
+ extension : PVSC_EXTENSION_ID ,
78
94
} ) ;
79
- }
80
95
81
- ourController ! . updateNotebookAffinity ( notebookDocument , NotebookControllerAffinity . Default ) ;
82
- // await commands.executeCommand(
83
- // 'interactive.open',
84
- // // Keep focus on the owning file if there is one
85
- // { viewColum: 1, preserveFocus: true },
86
- // ourResource,
87
- // ourController?.id,
88
- // 'Python REPL',
89
- // );
90
-
91
- // Auto-Select Python REPL Kernel
92
- await commands . executeCommand ( 'notebook.selectKernel' , {
93
- ourNotebookEditor,
94
- id : ourController ?. id ,
95
- extension : PVSC_EXTENSION_ID ,
96
- } ) ;
97
-
98
- // Add new cell to interactive window document
99
- const notebookCellData = new NotebookCellData ( NotebookCellKind . Code , 'x=5' , 'python' ) ; // this is manual atm but need to pass in user input here
100
- const { cellCount } = notebookDocument ;
101
- const notebookEdit = NotebookEdit . insertCells ( cellCount , [ notebookCellData ] ) ;
102
- const workspaceEdit = new WorkspaceEdit ( ) ;
103
- workspaceEdit . set ( notebookDocument . uri , [ notebookEdit ] ) ;
104
- workspace . applyEdit ( workspaceEdit ) ;
105
-
106
- // const notebookCellExecution = ourController!.createNotebookCellExecution(
107
- // notebookDocument.cellAt(cellCount),
108
- // );
109
- // notebookCellExecution.start(Date.now());
110
- // notebookCellExecution.end(true);
111
-
112
- // Execute the cell
113
- commands . executeCommand ( 'notebook.cell.execute' , {
114
- ranges : [ { start : cellCount , end : cellCount + 1 } ] ,
115
- document : ourResource ,
116
- } ) ;
117
-
118
- // event fire our executeHandler we made for notebook controller
119
-
120
- // NEED TO TELL TO EXECUTE THE CELL WHICH WILL CALL MY HANDLER
121
-
122
- // args: [
123
- // {
124
- // name: 'showOptions',
125
- // description: 'Show Options',
126
- // schema: {
127
- // type: 'object',
128
- // properties: {
129
- // 'viewColumn': {
130
- // type: 'number',
131
- // default: -1
132
- // },
133
- // 'preserveFocus': {
134
- // type: 'boolean',
135
- // default: true
136
- // }
137
- // },
138
- // }
139
- // },
140
- // {
141
- // name: 'resource',
142
- // description: 'Interactive resource Uri',
143
- // isOptional: true
144
- // },
145
- // {
146
- // name: 'controllerId',
147
- // description: 'Notebook controller Id',
148
- // isOptional: true
149
- // },
150
- // {
151
- // name: 'title',
152
- // description: 'Notebook editor title',
153
- // isOptional: true
154
- // }
155
- // ]
96
+ // Add new cell to interactive window document
97
+ const notebookCellData = new NotebookCellData ( NotebookCellKind . Code , code as string , 'python' ) ; // this is manual atm but need to pass in user input here
98
+ const { cellCount } = notebookDocument ;
99
+ const notebookEdit = NotebookEdit . insertCells ( cellCount , [ notebookCellData ] ) ;
100
+ const workspaceEdit = new WorkspaceEdit ( ) ;
101
+ workspaceEdit . set ( notebookDocument . uri , [ notebookEdit ] ) ;
102
+ workspace . applyEdit ( workspaceEdit ) ;
103
+
104
+ // const notebookCellExecution = ourController!.createNotebookCellExecution(
105
+ // notebookDocument.cellAt(cellCount),
106
+ // );
107
+ // notebookCellExecution.start(Date.now());
108
+ // notebookCellExecution.end(true);
109
+
110
+ // Execute the cell
111
+ commands . executeCommand ( 'notebook.cell.execute' , {
112
+ ranges : [ { start : cellCount , end : cellCount + 1 } ] ,
113
+ document : ourResource ,
114
+ } ) ;
115
+
116
+ // event fire our executeHandler we made for notebook controller
117
+
118
+ // NEED TO TELL TO EXECUTE THE CELL WHICH WILL CALL MY HANDLER
119
+
120
+ // args: [
121
+ // {
122
+ // name: 'showOptions',
123
+ // description: 'Show Options',
124
+ // schema: {
125
+ // type: 'object',
126
+ // properties: {
127
+ // 'viewColumn': {
128
+ // type: 'number',
129
+ // default: -1
130
+ // },
131
+ // 'preserveFocus': {
132
+ // type: 'boolean',
133
+ // default: true
134
+ // }
135
+ // },
136
+ // }
137
+ // },
138
+ // {
139
+ // name: 'resource',
140
+ // description: 'Interactive resource Uri',
141
+ // isOptional: true
142
+ // },
143
+ // {
144
+ // name: 'controllerId',
145
+ // description: 'Notebook controller Id',
146
+ // isOptional: true
147
+ // },
148
+ // {
149
+ // name: 'title',
150
+ // description: 'Notebook editor title',
151
+ // isOptional: true
152
+ // }
153
+ // ]
154
+ }
156
155
} ) ,
157
156
) ;
158
157
}
0 commit comments