Skip to content

Commit a7256df

Browse files
author
David Kutugata
authored
Make it easier to add Cells (microsoft#6558)
* added code lens option and code snippet to add a new cell, in order to make it easier * added news entry * only add the 'Add Cell' code lens on the last cell, add cell when you press Alt+Enter, update codewatcher.unit.test.ts to expect more code lenses * removed addcellbelow from the default settings, changed the command for the keybing 'alt+enter', user can now make 'Add Cell' code lens appear anywhere he likes, but it will always appear as the last code lens in the last cell, updated codewatcher unit test to reflect the changes in code lens * added code snippets to add markdown cells, added instruction comments at the begining of imported jupyter files, and added a keybinding for alt+enter with a command that matches the behaviour in jupyter. * localized a constant string, used cellMatcher in the codewatcher command, and returned codewatcher unit test to its original expected Code Lenses amount * changed a label, also updated the codewatcher unit test with correct amount of code lenses
1 parent 92d24ed commit a7256df

File tree

12 files changed

+891
-812
lines changed

12 files changed

+891
-812
lines changed

news/1 Enhancements/6367.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added Code Lens and Snippet to add new cell.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@
104104
"command": "python.datascience.runcurrentcell",
105105
"key": "ctrl+enter",
106106
"when": "editorTextFocus && !editorHasSelection && python.datascience.hascodecells && python.datascience.featureenabled"
107+
},
108+
{
109+
"command": "python.datascience.runcurrentcellandaddbelow",
110+
"key": "alt+enter",
111+
"when": "editorTextFocus && !editorHasSelection && python.datascience.hascodecells && python.datascience.featureenabled"
107112
}
108113
],
109114
"commands": [

package.nls.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@
302302
"DataScience.jupyterDataRateExceeded": "Cannot view variable because data rate exceeded. Please restart your server with a higher data rate limit. For example, --NotebookApp.iopub_data_rate_limit=10000000000.0",
303303
"DataScience.addCellBelowCommandTitle": "Add cell",
304304
"DataScience.debugCellCommandTitle": "Debug cell",
305+
"DataScience.runCurrentCellAndAddBelow":"Run current and add cell below",
305306
"DataScience.variableExplorerDisabledDuringDebugging": "Variables are not available while debugging.",
306307
"DataScience.jupyterDebuggerNotInstalledError" : "Pip module ptvsd is required for debugging cells. You will need to install it to debug cells.",
307308
"DataScience.jupyterDebuggerPortNotAvailableError" : "Port {0} cannot be opened for debugging. Please specify a different port in the remoteDebuggerPort setting.",
@@ -312,5 +313,6 @@
312313
"DataScience.jupyterDebuggerInstallPtvsdUpdate" : "The version of ptvsd installed does not support debugging cells. Update ptvsd to newest version and continue to debug cell?",
313314
"DataScience.jupyterDebuggerInstallPtvsdYes" : "Yes",
314315
"DataScience.jupyterDebuggerInstallPtvsdNo" : "No",
315-
"DataScience.cellStopOnErrorFormatMessage" : "{0} cells were canceled due to an error in the previous cell."
316+
"DataScience.cellStopOnErrorFormatMessage" : "{0} cells were canceled due to an error in the previous cell.",
317+
"DataScience.instructionComments": "# To add a new cell, type '#%%'\n# To add a new markdown cell, type '#%% [markdown]'\n"
316318
}

snippets/python.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
"prefix": "__main__",
188188
"body": [
189189
"if __name__ == \"__main__\":",
190-
" ${1:pass}",
190+
" ${1:pass}"
191191
],
192192
"description": "Code snippet for a `if __name__ == \"__main__\": ...` block"
193193
},
@@ -240,4 +240,14 @@
240240
"body": "import pudb; pudb.set_trace()",
241241
"description": "Code snippet for pudb debug"
242242
},
243+
"add/new/cell": {
244+
"prefix": "add/new/cell",
245+
"body": "#%%",
246+
"description": "Code snippet to add a new cell"
247+
},
248+
"mark/markdown": {
249+
"prefix": "mark/markdown",
250+
"body": "#%% [markdown]",
251+
"description": "Code snippet to add a new markdown cell"
252+
}
243253
}

src/client/common/application/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,5 @@ export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgu
112112
[DSCommands.ExportFileAsNotebook]: [undefined | Uri, undefined | CommandSource];
113113
[DSCommands.RunFileInInteractiveWindows]: [string];
114114
[DSCommands.DebugCell]: [string, number, number, number, number];
115+
[DSCommands.RunCurrentCellAndAddBelow]: [string];
115116
}

src/client/common/utils/localize.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ export namespace DataScience {
228228
export const jupyterDataRateExceeded = localize('DataScience.jupyterDataRateExceeded', 'Cannot view variable because data rate exceeded. Please restart your server with a higher data rate limit. For example, --NotebookApp.iopub_data_rate_limit=10000000000.0');
229229
export const addCellBelowCommandTitle = localize('DataScience.addCellBelowCommandTitle', 'Add cell');
230230
export const debugCellCommandTitle = localize('DataScience.debugCellCommandTitle', 'Debug cell');
231+
export const runCurrentCellAndAddBelow = localize('DataScience.runCurrentCellAndAddBelow', 'Run current and add cell below');
231232
export const variableExplorerDisabledDuringDebugging = localize('DataScience.variableExplorerDisabledDuringDebugging', 'Variables are not available while debugging.');
232233
export const jupyterDebuggerNotInstalledError = localize('DataScience.jupyterDebuggerNotInstalledError', 'Pip module ptvsd is required for debugging cells. You will need to install it to debug cells.');
233234
export const jupyterDebuggerPortNotAvailableError = localize('DataScience.jupyterDebuggerPortNotAvailableError', 'Port {0} cannot be opened for debugging. Please specify a different port in the remoteDebuggerPort setting.');
@@ -239,6 +240,7 @@ export namespace DataScience {
239240
export const jupyterDebuggerInstallPtvsdYes = localize('DataScience.jupyterDebuggerInstallPtvsdYes', 'Yes');
240241
export const jupyterDebuggerInstallPtvsdNo = localize('DataScience.jupyterDebuggerInstallPtvsdNo', 'No');
241242
export const cellStopOnErrorFormatMessage = localize('DataScience.cellStopOnErrorFormatMessage', '{0} cells were canceled due to an error in the previous cell.');
243+
export const instructionComments = localize('DataScience.instructionComments', '# To add a new cell, type "#%%"\n# To add a new markdown cell, type "#%% [markdown]"\n');
242244
}
243245

244246
export namespace DebugConfigStrings {

0 commit comments

Comments
 (0)