Skip to content

Conversation

@vezwork
Copy link
Collaborator

@vezwork vezwork commented Nov 14, 2025

In #825 I ended up re-implementing Positron internal code (that is used in the source editor) for finding a statement range at the cursor, executing the code in that range, and then finding the next statement range. As @juliasilge brought up, this doesn't seem ideal. Ideally we could use Positron to do the work for us.

At the core, this PR modifies #825 to execute the "workbench.action.positronConsole.executeCode" command with extra position and uri arguments, so that it is suitable for use in a vdoc. It also expects this command to return the position of the next statement range. The result of the code changes are to support the use of this functionality. This is not how this command actually works in Positron today, but let this PR serve as a proposal for how to modify this command to support this functionality (@juliasilge suggested putting up a PR with how I want to use the command so that she can do the work on the Positron side).

With this modification, we are able to remove the code that re-implements Positron's internals.

@vezwork vezwork requested a review from juliasilge November 14, 2025 16:22
@vezwork vezwork changed the base branch from main to fix/run-statement-at-cursor-positron November 14, 2025 16:23
Comment on lines 88 to 93
},
executeSelectionAtPosition: async (uri: Uri, position: Position): Promise<Position> => {
return await vscode.commands.executeCommand(
'workbench.action.positronConsole.executeCode',
{ languageId: language, uri, position }
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the core change of this PR.

I propose that the 'workbench.action.positronConsole.executeCode' command takes two new properties in its argument object alongside languageId: uri and position. This would make the command suitable for calling in a vdoc.

I also propose that this command returns the position of the next statement after the one being executed (perhaps it may have to return undefined or the same position that was passed in if there is no next statement). This would make it so we do not have to re-implement Positron internal logic for finding the next statement like we were in #825.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I've got a proposal up in posit-dev/positron#10580, if you want to take a look and see what you think!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants