Skip to content

Commit f8c57f6

Browse files
jgutmanwesm
authored andcommitted
Update execute code command for Python -- immediately error when code is incomplete in Python (posit-dev/positron-python#426)
* add wrapper command and use that instead * prettier * update unit test expected output
1 parent 748ca02 commit f8c57f6

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

extensions/positron-python/package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@
401401
},
402402
{
403403
"category": "Python",
404-
"command": "workbench.action.positronConsole.executeCode",
404+
"command": "python.execSelectionInConsole",
405405
"icon": "$(play)",
406406
"title": "%python.command.python.execSelectionInConsole.title%"
407407
},
@@ -1206,6 +1206,12 @@
12061206
"key": "ctrl+shift+enter",
12071207
"mac": "cmd+shift+enter",
12081208
"when": "editorTextFocus && editorLangId == python && !findInputFocussed && !replaceInputFocussed && !jupyter.ownsSelection && !notebookEditorFocused"
1209+
},
1210+
{
1211+
"command": "python.execSelectionInConsole",
1212+
"key": "ctrl+enter",
1213+
"mac": "cmd+enter",
1214+
"when": "editorTextFocus && editorLangId == python && !findInputFocussed && !replaceInputFocussed && !jupyter.ownsSelection && !notebookEditorFocused"
12091215
}
12101216
],
12111217
"languages": [
@@ -1345,7 +1351,7 @@
13451351
},
13461352
{
13471353
"category": "Python",
1348-
"command": "workbench.action.positronConsole.executeCode",
1354+
"command": "python.execSelectionInConsole",
13491355
"title": "%python.command.python.execSelectionInConsole.title%",
13501356
"when": "!virtualWorkspace && shellExecutionSupported && editorLangId == python"
13511357
},
@@ -1447,7 +1453,7 @@
14471453
],
14481454
"python.run": [
14491455
{
1450-
"command": "workbench.action.positronConsole.executeCode",
1456+
"command": "python.execSelectionInConsole",
14511457
"group": "Python",
14521458
"when": "editorFocus && editorLangId == python && !virtualWorkspace && shellExecutionSupported"
14531459
},
@@ -1481,7 +1487,7 @@
14811487
],
14821488
"editor/title/run": [
14831489
{
1484-
"command": "workbench.action.positronConsole.executeCode",
1490+
"command": "python.execSelectionInConsole",
14851491
"group": "navigation@0",
14861492
"title": "%python.command.python.execSelectionInConsole.title%",
14871493
"when": "resourceLangId == python && !isInDiffEditor && !virtualWorkspace && shellExecutionSupported"

extensions/positron-python/positron-dts/positron.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,15 +1098,15 @@ declare module 'positron' {
10981098
* @param languageId The language ID of the code snippet
10991099
* @param code The code snippet to execute
11001100
* @param focus Whether to focus the runtime's console
1101-
* @param skipChecks Whether to bypass runtime code completeness checks. If true, the `code`
1101+
* @param allowIncomplete Whether to bypass runtime code completeness checks. If true, the `code`
11021102
* will be executed by the runtime even if it is incomplete or invalid. Defaults to false
11031103
* @returns A Thenable that resolves with true if the code was sent to a
11041104
* runtime successfully, false otherwise.
11051105
*/
11061106
export function executeCode(languageId: string,
11071107
code: string,
11081108
focus: boolean,
1109-
skipChecks?: boolean): Thenable<boolean>;
1109+
allowIncomplete?: boolean): Thenable<boolean>;
11101110

11111111
/**
11121112
* Register a language runtime manager with Positron. Returns a

extensions/positron-python/src/client/common/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export namespace Commands {
4848
export const Exec_In_Separate_Terminal = 'python.execInDedicatedTerminal';
4949
// --- Start Positron ---
5050
export const Exec_In_Console = 'python.execInConsole';
51+
export const Exec_Selection_In_Console = 'python.execSelectionInConsole';
5152
// --- End Positron ---
5253
export const Exec_Selection_In_Django_Shell = 'python.execSelectionInDjangoShell';
5354
export const Exec_Selection_In_Terminal = 'python.execSelectionInTerminal';

extensions/positron-python/src/client/terminals/codeExecution/codeExecutionManager.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ export class CodeExecutionManager implements ICodeExecutionManager {
124124
}
125125
}),
126126
);
127+
this.disposableRegistry.push(
128+
this.commandManager.registerCommand(Commands.Exec_Selection_In_Console as any, async () => {
129+
// Wrapper for passing the allowIncomplete opt to the console's executeCode command
130+
await vscode.commands.executeCommand('workbench.action.positronConsole.executeCode', {
131+
allowIncomplete: true,
132+
});
133+
}),
134+
);
127135
// --- End Positron ---
128136
this.disposableRegistry.push(
129137
this.commandManager.registerCommand(Commands.Exec_Selection_In_Terminal as any, async (file: Resource) => {

extensions/positron-python/src/test/terminals/codeExecution/codeExecutionManager.unit.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ suite('Terminal - Code Execution Manager', () => {
8989
expect(sorted).to.deep.equal(
9090
[
9191
// --- Start Positron ---
92-
// Add the Positron execute in console command.
92+
// Add the Positron execute in console command and execute selection in console command.
9393
Commands.Exec_In_Console,
94+
Commands.Exec_Selection_In_Console,
9495
// --- End Positron ---
9596
Commands.Exec_In_Separate_Terminal,
9697
Commands.Exec_In_Terminal,

0 commit comments

Comments
 (0)