Fix running and debugging Shiny apps that are not the active editor - #119
Merged
Merged
Conversation
The run and debug commands now take an optional uri and act on that document, falling back to the active editor when called without one.
seeM
force-pushed
the
fix/run-app-uri-argument
branch
from
September 4, 2026 14:01
cb686b3 to
969ff14
Compare
seeM
added a commit
to posit-dev/positron
that referenced
this pull request
Sep 4, 2026
) Stacked on #15898. The `positron-python` part of #15897. Shiny part: posit-dev/shiny-vscode#119. Clicking Run App or Debug App above a Python app now runs that editor's file, even when a different editor is focused. The commands also take an optional uri, so an agent or custom keybinding's args can run a file without first opening and focusing it. https://github.com/user-attachments/assets/2b8f7a08-8a81-4841-ac8c-d7268cae3fb6 ### Release Notes #### New Features - N/A #### Bug Fixes - Run App and Debug App now run the file whose button was clicked rather than the focused editor's file (#15897) #### Validation Steps @:apps The Python Applications e2e suite already runs each app from its editor title button, which is the URI path. New unit tests in `extensions/positron-python/src/test/positron/webAppCommands.unit.test.ts` cover a Uri argument, its string form, the debug commands, an empty string, and an omitted argument: from extensions/positron-python, run `npm run test:unittests -- --grep "Web app commands"`. Manual steps: 1. In the `qa-example-content` workspace, open `workspaces/python-apps/streamlit_example/streamlit_example.py` and click Run App in the editor title bar. Confirm Streamlit runs and appears in the Viewer, as before. 2. Open `workspaces/python-apps/dash_example/dash_example.py` in a split group beside it. 3. Click into the Streamlit editor so it is the active editor, then click Run App in the Dash group's title bar. 4. Confirm the Dash app runs (the terminal command, the progress notification, and the Viewer all name `dash_example.py`), and that focus stays in the Streamlit editor. 5. Repeat step 2 with the Debug App button in the Dash group's title bar and confirm the debug session starts on `dash_example.py`. 6. The negative case: with both files still open and the Streamlit editor active, run "Python: Run Dash App in Terminal" from the Command Palette. The palette passes no URI, so this should still fall back to the active editor and fail to run Dash from `streamlit_example.py`.
gadenbuie
approved these changes
Sep 4, 2026
gadenbuie
left a comment
Collaborator
There was a problem hiding this comment.
Looks great, thank you! Just one small nitpicky comment
Comment on lines
+548
to
+552
| // Parse rather than `Uri.file` so a scheme without slashes (untitled:, | ||
| // vscode-notebook-cell:) survives the round trip through a string. | ||
| return vscode.workspace.openTextDocument( | ||
| typeof uri === "string" ? vscode.Uri.parse(uri) : uri | ||
| ); |
Collaborator
There was a problem hiding this comment.
The tiniest nit-pick, but do you think it'd be a good idea to catch and handle errors here? I guess it'd only come up if a bad/invalid/stale Uri made it this far, which seems unlikely. But thought I'd mention it to see what you think.
Contributor
Author
There was a problem hiding this comment.
Ah yeah, good point. Fixed in 781179d. I'm still throwing, just a more helpful error message mentioning that we were trying to start a Shiny app and including the original error message at the end.
I went with a throw rather than directly showing an error notification because it will work well for both humans and agents:
- An agent using the
positronCommandtool will see the error in the tool result. - A human will see the error in a notification - VSCode already does this for errors in commands when invoked via the command palette and the editor toolbar.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Shiny part of posit-dev/positron#15897. Positron Python part is in posit-dev/positron#15912.
Clicking Run Shiny App or Debug Shiny App above an app now runs that editor's file, even when a different editor is focused. The commands also take an optional uri, so an agent or a custom keybinding's
argscan run a file without first opening and focusing it.In Positron, R apps run through the Run App API's new
documentoption, so that half only takes effect once posit-dev/positron#15898 ships; the Python commands, which launch the terminal themselves, work today in both VS Code and Positron.Python:
Screen.Recording.2026-09-03.at.16.53.23.mov
R:
Screen.Recording.2026-09-03.at.16.48.43.mov
Validation steps
Python (VS Code or Positron):
app.pyfrom a Shiny for Python app and click Run Shiny App in the editor title bar. Confirm the app runs and previews, as before.other-app.py, in a split group beside it.app.pyeditor so it is the active editor, then click Run Shiny App in theother-app.pygroup's title bar.other-app.py, and that focus stays in theapp.pyeditor.other-app.py.app.pyactive, run "Shiny: Run Shiny App" from the Command Palette. The palette passes no URI, so this should still runapp.py.R (needs a Positron build with posit-dev/positron#15898):
shiny::runApp()call in the console names the file whose button was clicked.