Skip to content

Conversation

@juliasilge
Copy link
Contributor

I've been collaborating with @vezwork on how to get more language features hooked up in Quarto's visual editor, and we think this is what we need for the Quarto custom editor interface to be able to send code statement-by-statement to the console. Over in the Quarto extension, we can now do something like:

  const nextPosition = await vscode.commands.executeCommand(
      'positron.executeCodeInConsole',
      'python',                              // language ID
      vscode.Uri.file('/path/to/script.py'), // document URI
      new vscode.Position(5, 0)              // position
  ) as vscode.Position | undefined;

What we get back is the next position to move the cursor to, in Quarto's case for the virtual doc underlying the visual editor.

It's a little weird to now have two commands, both the old workbench.action.positronConsole.executeCode and the new positron.executeCodeInConsole, but now that we're dealing with positions (and less so, URIs) we need to use the converters that we have access to in src/vs/workbench/api/common/extHostApiCommands.ts. I think I'd argue they do different enough things that this is OK? Although you can now technically call workbench.action.positronConsole.executeCode with a uri and position, but they would have to be the internal main process versions of those; this feels somewhat weird. Is it worth doing more refactoring here to make this nicer?

@:sessions
@:console

Release Notes

New Features

  • Added new command positron.executeCodeInConsole for extensions to execute code for a given language, URI, and position (such as for the Quarto visual editor)

Bug Fixes

  • N/A

QA Notes

Once we get changes merged on both the Positron and Quarto sides, you should be able to execute multi-line statements in the console from the visual editor. Once we get further along, I can share more detailed examples

@github-actions
Copy link

github-actions bot commented Nov 14, 2025

E2E Tests 🚀
This PR will run tests tagged with: @:critical @:sessions @:console

readme  valid tags

),
// -- execute code in console
new ApiCommand(
'positron.executeCodeInConsole', '_executeCodeInConsole', 'Execute code in the Positron console.',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason we need a new command over here is to use the type converters for position, to get the position type that extensions can use.

// Use the provided position (guaranteed to exist when uri is provided)
position = opts.position;
// No editor context when URI is provided
editor = undefined;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're dealing with URIs for the visual editor, and don't want to mess with the editor itself.

mode: opts.mode,
errorBehavior: opts.errorBehavior
});
return nextPosition;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The visual editor needs to know the next position directly, because it manages its own cursor and selection and such.

* Register the internal command for executing code in console from the extension API.
* This command is called by the positron.executeCodeInConsole API command.
*/
CommandsRegistry.registerCommand('_executeCodeInConsole', async (accessor, ...args: [string, URI, IPosition]) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This command is registered here so we can make one in extHostApiCommands.ts. I want to note that right now these are not optional arguments for using with this command. Good? Bad? We could do these arguments like URI | undefined if we want.

Copy link

Choose a reason for hiding this comment

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

I believe I'm happy with the arguments being required. The visual editor will always want to pass both URI and position.

@juliasilge juliasilge marked this pull request as ready for review November 14, 2025 21:10
@juliasilge juliasilge changed the title Add new command for positron.executeCodeInConsole extensions that handles uri, position, next position Add new command for positron.executeCodeInConsole to be used by extensions that handles uri, position, next position Nov 14, 2025
Copy link

@vezwork vezwork left a comment

Choose a reason for hiding this comment

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

This would work well for #867 !

@juliasilge juliasilge requested a review from jmcphers November 18, 2025 17:54
@juliasilge
Copy link
Contributor Author

@jmcphers I chatted with @vezwork more and we think this is the way we want to go. Can you now review this from the Positron perspective, and dig into the details of how I have implemented this? You'll notice I've outlined some questions about the approach I took.

vezwork added a commit to quarto-dev/quarto that referenced this pull request Nov 18, 2025
jmcphers
jmcphers previously approved these changes Nov 18, 2025
Copy link
Collaborator

@jmcphers jmcphers left a comment

Choose a reason for hiding this comment

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

Nice! I would suggest naming this something like executeCodeFromPosition as executeCodeInConsole is pretty easy to confuse with other use cases.

@juliasilge
Copy link
Contributor Author

This is working! 🎉

I made the suggested name change here (very good idea, thanks!) and then pulled down quarto-dev/quarto#867 and made the same change there. I made a dev build of the extension and opened up a .qmd in visual mode, and I can execute statements!

Screenshot 2025-11-18 at 5 01 44 PM

I confirmed that I can run multi-line statements via Cmd+Enter in both R and Python .qmd files in visual mode.

@vezwork I'll add a bit more detail over on the Quarto PR but I think we need to improve the behavior of where the cursor goes after executing the last statement in a cell.

@juliasilge juliasilge merged commit dd39e57 into main Nov 19, 2025
19 of 20 checks passed
@juliasilge juliasilge deleted the execute-code-uri-position branch November 19, 2025 14:54
@github-actions github-actions bot locked and limited conversation to collaborators Nov 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants