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.

@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
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.

2 participants