Skip to content

Commit 85aaf48

Browse files
committed
execute seletion in python terminal
1 parent e4238e6 commit 85aaf48

4 files changed

Lines changed: 32 additions & 21 deletions

File tree

package.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
"onCommand:python.viewTestUI",
4242
"onCommand:python.viewTestOutput",
4343
"onCommand:python.selectAndRunTestMethod",
44-
"onCommand:python.runFailedTests"
44+
"onCommand:python.runFailedTests",
45+
"onCommand:python.execSelectionInTerminal"
4546
],
4647
"main": "./out/client/extension",
4748
"contributes": {
@@ -96,6 +97,11 @@
9697
"command": "python.runFailedTests",
9798
"title": "Run Failed Unit Tests",
9899
"category": "Python"
100+
},
101+
{
102+
"command": "python.execSelectionInTerminal",
103+
"title": "Run Selection in Python Terminal",
104+
"category": "Python"
99105
}
100106
],
101107
"menus": {
@@ -112,6 +118,11 @@
112118
"group": "Refactor",
113119
"when": "editorHasSelection && editorLangId == python"
114120
},
121+
{
122+
"command": "python.execSelectionInTerminal",
123+
"group": "Python",
124+
"when": "editorHasSelection && editorLangId == python"
125+
},
115126
{
116127
"when": "resourceLangId == python",
117128
"command": "python.execInTerminal",
@@ -120,6 +131,7 @@
120131
],
121132
"explorer/context": [
122133
{
134+
"when": "resourceLangId == python",
123135
"command": "python.runtests",
124136
"group": "Python"
125137
},

src/client/common/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const PythonLanguage = { language: 'python', scheme: 'file' };
44
export namespace Commands {
55
export const Set_Interpreter = 'python.setInterpreter';
66
export const Exec_In_Terminal = 'python.execInTerminal';
7+
export const Exec_Selection_In_Terminal = 'python.execSelectionInTerminal';
78
export const Tests_View_UI = 'python.viewTestUI';
89
export const Tests_Picker_UI = 'python.selectTestToRun';
910
export const Tests_Discover = 'python.discoverTests';

src/client/providers/execInTerminalProvider.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Commands } from '../common/constants';
55

66
export function activateExecInTerminalProvider() {
77
vscode.commands.registerCommand(Commands.Exec_In_Terminal, execInTerminal);
8+
vscode.commands.registerCommand(Commands.Exec_Selection_In_Terminal, execSelectionInTerminal);
89
}
910

1011
function execInTerminal(fileUri?: vscode.Uri) {
@@ -37,3 +38,19 @@ function execInTerminal(fileUri?: vscode.Uri) {
3738
terminal.sendText(`${currentPythonPath} ${filePath}`);
3839

3940
}
41+
42+
function execSelectionInTerminal() {
43+
const currentPythonPath = settings.PythonSettings.getInstance().pythonPath;
44+
const activeEditor = vscode.window.activeTextEditor;
45+
if (!activeEditor) {
46+
return;
47+
}
48+
49+
const selection = vscode.window.activeTextEditor.selection;
50+
if (selection.isEmpty){
51+
return;
52+
}
53+
const code = vscode.window.activeTextEditor.document.getText(new vscode.Range(selection.start, selection.end));
54+
const terminal = (<any>vscode.window).createTerminal(`Python`);
55+
terminal.sendText(`${currentPythonPath} -c "${code}"`);
56+
}

src/client/unittests/todo.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,5 @@ Do we use the vscode.executeCodeLensProvider? (complex commands)
2121

2222
**Status Bar**
2323
- Add command for satusbar:
24-
<<<<<<< a9df1f18b91727c5d1f6a21f5587baa36f04d781
25-
<<<<<<< b0927e0baf2e1c2fd0cc96b48ae637343410c4b2:src/client/unittests/todo.md
26-
=======
27-
>>>>>>> more changes to unittests #239
28-
+ In the pick list of functions, if a function is selected:
29-
+ View test result for selected function
30-
+ Debug function
31-
+ Run test function
32-
+ Navigate to that test function
33-
<<<<<<< a9df1f18b91727c5d1f6a21f5587baa36f04d781
34-
35-
=======
36-
+ Run all tests
37-
+ Run failed tests
3824
+ Run previous tests
39-
+ Run specific test
40-
+ This displays a picklist of tests (user can filter and select)
41-
(again low priority)
42-
>>>>>>> support python unittest framework #239:src/client/unittests/todo.md
43-
=======
44-
>>>>>>> more changes to unittests #239
25+
+ Debug Unit Test

0 commit comments

Comments
 (0)