posit-dev / positron

Positron, a next-generation data science IDE
https://positron.posit.co
Other
2.82k stars 91 forks source link

Add RuntimeCodeExecutionMode to `runtime.executeCode()` in the API #5450

Open dhruvisompura opened 15 hours ago

dhruvisompura commented 15 hours ago

Description

This partially addresses the ask from #4856.

The ask is to make the positron API executeCode call respect the RuntimeCodeExecutionMode and RuntimeErrorBehavior values being passes in. This PR only handles RuntimeCodeExecutionMode. The work for RuntimeErrorBehavior will be done in a separate PR.

The runtime session execute is already setup to work with RuntimeCodeExecutionMode, see workbench.action.executeCode.silently (https://github.com/posit-dev/positron/pull/2684) for an example of silent code execution via the session directly.

For code execution to work as expected, some changes were made in the PositronConsoleService to prevent data from being rendered in the console or added to history based off the RuntimeCodeExecutionMode.

QA Notes

We will want to verify that the three different values for RuntimeCodeExecutionMode are respected when positron.runtime.executeCode() is called and verify there aren't any regressions:

The PositronZedLanguageRuntime has a new command exec silent that can execute a code snippet in the language silently. The exec command now explicitly passes a RuntimeCodeExecutionMode of Interactive to make it clear what is happening.

Screenshot

Silent Code Execution - Print

https://github.com/user-attachments/assets/ce57bb56-bf72-40be-bce0-d134d34d560b

Silent Code Execution - Variable Assignment

https://github.com/user-attachments/assets/f792a7a8-bd46-45af-a8e5-3acadd6a608a

Interactive Code Execution - Print

https://github.com/user-attachments/assets/ec46d151-1df4-4ab2-badb-b60a71fcc4db

Interactive Code Execution - Variable Assignment

https://github.com/user-attachments/assets/b4146441-a288-4897-803f-d71146ffcfaa