quantified-uncertainty / squiggle

An estimation language
https://squiggle-language.com
MIT License
148 stars 22 forks source link

More flexible "External viewer actions" #3262

Closed berekuk closed 1 month ago

berekuk commented 1 month ago

We now pass externalViewerActions to ViewerProvider instead of an editor object, because editor.scrollTo doesn't make sense in some non-playground contexts, e.g. GUCEM.

To avoid boilerplate, there's a useExternalViewerActionsForEditor hook which converts the editor handle to the externalViewerActions.

Also, the viewer behavior regarding these actions is now more flexible and has a better support for imports, thanks to the two new methods: isFocusable and isDefaultSourceId.

Example screenshot from the modified story; the error here comes from the function defined in an import, and the line in imported file is not clickable (for now), but the top-level call location is clickable.

Screenshot 2024-05-11 at 15 00 53

I didn't commit this story to the repo, but I did implemented some basic tests.

vercel[bot] commented 1 month ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
quri-hub ✅ Ready (Inspect) Visit Preview May 12, 2024 1:56am
squiggle-components ✅ Ready (Inspect) Visit Preview May 12, 2024 1:56am
squiggle-website ✅ Ready (Inspect) Visit Preview May 12, 2024 1:56am
1 Ignored Deployment | Name | Status | Preview | Updated (UTC) | | :--- | :----- | :------ | :------ | | **quri-ui** | ⬜️ Ignored ([Inspect](https://vercel.com/quantified-uncertainty/quri-ui/ECeudFaf9nA5JJaxUTgRk3BhHjtD)) | [Visit Preview](https://quri-ui-git-viewer-improvements-quantified-uncertainty.vercel.app) | May 12, 2024 1:56am |
changeset-bot[bot] commented 1 month ago

🦋 Changeset detected

Latest commit: e145e9302fce5eb4f9c1e43a202aceb25084d086

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages | Name | Type | | ----------------------------------- | ----- | | @quri/squiggle-components | Patch | | @quri/versioned-squiggle-components | Patch | | vscode-squiggle | Patch | | @quri/squiggle-lang | Patch | | @quri/prettier-plugin-squiggle | Patch | | @quri/squiggle-textmate-grammar | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

berekuk commented 1 month ago

show action now select the range in editor instead of just a starting position.

This seems better in most cases, e.g. long dicts that are below the current viewport in editor will scroll into range:

Screenshot 2024-05-11 at 22 42 02

One awkward corner case here is that if the dict or a function is very long, and won't fit in the viewport, Codemirror will scroll to the end of it even if this means that the beginning of the selection won't be in the viewport. This is a consequence of selection "head" (cursor position) being at the end. But this is probably fine.

OAGr commented 1 month ago

This seems very reasonable, let's go with it for now.