Skip to content

Commit 1f486d0

Browse files
committed
rename command to run-inferred-block
1 parent 1143115 commit 1f486d0

File tree

4 files changed

+34
-27
lines changed

4 files changed

+34
-27
lines changed

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@
1313
"Other"
1414
],
1515
"activationEvents": [
16-
"onCommand:vscode-jupyter-python.sayHello"
16+
"onCommand:vscode-jupyter-python.run-inferred-block",
17+
"onCommand:vscode-jupyter-python.run-inferred-block-and-move-down"
1718
],
1819
"main": "./out/extension",
1920
"contributes": {
2021
"commands": [
2122
{
22-
"command": "vscode-jupyter-python.sayHello",
23-
"title": "Run python code cell"
23+
"command": "vscode-jupyter-python.run-inferred-block",
24+
"title": "Run inferred code block"
25+
},
26+
{
27+
"command": "vscode-jupyter-python.run-inferred-block-and-move-down",
28+
"title": "Run inferred code block and move down"
2429
}
2530
],
2631
"configuration": {

src/extension.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
// The module 'vscode' contains the VS Code extensibility API
33
// Import the module and reference it with the alias vscode in your code below
44
import * as vscode from "vscode";
5-
import { runEntireFile, runInferredCodeBlock } from "./run-code";
5+
import {
6+
runInferredCodeBlock,
7+
runInferredCodeBlockAndMoveDown,
8+
} from "./run-code";
69

710
// this method is called when your extension is activated
811
// your extension is activated the very first time the command is executed
@@ -13,23 +16,21 @@ export function activate(context: vscode.ExtensionContext) {
1316
'Congratulations, your extension "vscode-jupyter-python" is now active!'
1417
);
1518

16-
const tmp = vscode.workspace.getConfiguration("vscode-jupyter-python");
17-
const expandCode = tmp.get("expandCode");
18-
19-
2019
// The command has been defined in the package.json file
2120
// Now provide the implementation of the command with registerCommand
2221
// The commandId parameter must match the command field in package.json
23-
let disposable = vscode.commands.registerCommand("vscode-jupyter-python.sayHello", async () => {
24-
// The code you place here will be executed every time your command is executed
22+
let disposable1 = vscode.commands.registerCommand(
23+
"vscode-jupyter-python.run-inferred-block",
24+
async () => runInferredCodeBlock()
25+
);
2526

26-
// Display a message box to the user
27-
// vscode.window.showInformationMessage(`Hello World ${expandCode} from vscode-jupyter-python!`);
28-
// await vscode.commands.executeCommand('jupyter.execSelectionInteractive', "print('sent to Interactive Window by package')\n");
29-
runInferredCodeBlock();
30-
});
27+
let disposable2 = vscode.commands.registerCommand(
28+
"vscode-jupyter-python.run-inferred-block-and-move-down",
29+
async () => runInferredCodeBlockAndMoveDown()
30+
);
3131

32-
context.subscriptions.push(disposable);
32+
context.subscriptions.push(disposable1);
33+
context.subscriptions.push(disposable2);
3334
}
3435

3536
// this method is called when your extension is deactivated

src/run-code.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,34 @@ export function runEntireFile() {
99
vscode.commands.executeCommand("jupyter.execSelectionInteractive", text);
1010
}
1111

12-
export function runInferredCodeBlock() {
12+
export function runInferredCodeBlock(): void {
1313
const textEditor = vscode.window.activeTextEditor;
14-
console.log('textEditor', textEditor);
14+
console.log("textEditor", textEditor);
1515
if (!textEditor) {
1616
return;
1717
}
1818

1919
const initialCursorPosition = textEditor?.selection.anchor;
20-
console.log('initialCursorPosition', initialCursorPosition);
20+
console.log("initialCursorPosition", initialCursorPosition);
2121

2222
const expandedCodeRange = getExpandedCodeRegion(
2323
textEditor,
2424
initialCursorPosition
2525
);
26-
console.log('expandedCodeRange', expandedCodeRange);
26+
console.log("expandedCodeRange", expandedCodeRange);
2727

2828
const text = textEditor.document.getText(expandedCodeRange);
29-
console.log('text', text);
29+
console.log("text", text);
3030
vscode.commands.executeCommand("jupyter.execSelectionInteractive", text);
3131

3232
// TODO: move cursor to end of range
3333
const endPosition = new Position(expandedCodeRange.end.line + 1, 0);
3434
const newSelection = new Selection(endPosition, endPosition);
3535
textEditor.selections = [newSelection];
36+
}
3637

38+
export function runInferredCodeBlockAndMoveDown(): void {
39+
runInferredCodeBlock();
3740
}
3841

3942
function getExpandedCodeRegion(
@@ -42,13 +45,13 @@ function getExpandedCodeRegion(
4245
): Range {
4346
// Assuming that no text is selected
4447
const beginRange = new Range(initialPosition, initialPosition);
45-
console.log('beginRange', beginRange);
48+
console.log("beginRange", beginRange);
4649

4750
const initialIndentText = getInitialIndentText(editor, initialPosition);
48-
console.log('initialIndentText', initialIndentText);
51+
console.log("initialIndentText", initialIndentText);
4952

5053
const finalRange = expandRangeDownward(editor, beginRange, initialIndentText);
51-
console.log('finalRange', finalRange);
54+
console.log("finalRange", finalRange);
5255
return finalRange;
5356
}
5457

@@ -89,7 +92,7 @@ function expandRangeDownward(
8992
document.lineAt(nextLineNum).text.match(expandRegex)
9093
) {
9194
nextLineNum += 1;
92-
console.log('adding a line number')
95+
console.log("adding a line number");
9396
}
9497

9598
const endPosition = document.lineAt(nextLineNum + 1).range.end;

src/test/run-test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import * as path from 'path';
22

3-
// @ts-expect-error not sure why ts can't find its types
4-
// It seems to be missing a types field in package.json?
53
import { runTests } from '@vscode/test-electron';
64

75
async function main() {

0 commit comments

Comments
 (0)