Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widget messages #449

Merged
merged 19 commits into from
Jun 3, 2024
Merged

Widget messages #449

merged 19 commits into from
Jun 3, 2024

Conversation

Vtec234
Copy link
Member

@Vtec234 Vtec234 commented May 22, 2024

Implementation of leanprover/lean4#2064.

Besides adding support for widget messages, this adds an EnvPosContext that stores the position that a component is "about" (see the docstring for more detail). This was originally proposed in #197 and eventually dismissed (see #226 for a detailed discussion), but I think it warrants a reconsideration. While Gabriel's point that there are many positions around remains true, the EnvPosContext stores a very specific one. This position is only used to retrieve a snapshot, and from that a Lean.Environment, on the server-side. Widgets currently have to pass this position around manually; this has led to errors in user code. Furthermore, so far I have not encountered any situation where it makes sense to modify the position; thus a context seems like a preferable approach. If needed, the context can still be set by users.

I also had to update some package versions to have tests building again. I hope that didn't break anything!

@Vtec234 Vtec234 requested a review from mhuisi May 23, 2024 02:00
@Vtec234 Vtec234 marked this pull request as ready for review May 23, 2024 02:00
vscode-lean4/src/projectoperations.ts Outdated Show resolved Hide resolved
vscode-lean4/test/suite/index/index.ts Outdated Show resolved Hide resolved
lean4-infoview/src/infoview/infos.tsx Show resolved Hide resolved
vscode-lean4/package.json Outdated Show resolved Hide resolved
package-lock.json Show resolved Hide resolved
lean4-infoview-api/src/rpcSessions.ts Outdated Show resolved Hide resolved
lean4-infoview/src/infoview/rpcSessions.tsx Show resolved Hide resolved
Copy link
Collaborator

@mhuisi mhuisi left a comment

Choose a reason for hiding this comment

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

Over all, these changes look good to me now. I wasn't involved in the original conversation, but I do wonder whether it would make sense to have separate contexts for the different use cases of PosContext in case these won't overlap as nicely as they currently do in the future, or just to make the type name better describe which position is actually provided by the context.

@Vtec234
Copy link
Member Author

Vtec234 commented May 29, 2024

I do wonder whether it would make sense to have separate contexts for the different use cases of PosContext in case these won't overlap as nicely as they currently do in the future

PosContext is supposed to store positions used for the specific purpose of resolving a server snapshot, from which an environment, from which an RPC method/widget module/any other kind of annotated global constant. The context is not meant to store positions aimed to be used for anything else (e.g. editor positions at which we insert a tactic script in "Try this"). My reason for introducing PosContext is that those environment-resolving positions do not tend to vary across component hierarchies in widgets (they do vary in the infoview itself), don't have to be super precise (in contrast to editor positions at which we insert a tactic script, say), and having to manage them manually has led to user error.

make the type name better describe which position is actually provided by the context

This could be a good idea; any suggestions?

github-merge-queue bot pushed a commit to leanprover/lean4 that referenced this pull request May 29, 2024
Allows embedding user widgets in structured messages. Companion PR is
leanprover/vscode-lean4#449.

Some technical choices:
- The `MessageData.ofWidget` constructor might not be strictly necessary
as we already have `MessageData.ofFormatWithInfos`, and there is
`Info.ofUserWidget`. However, `.ofUserWidget` also requires a `Syntax`
object (as it is normally produced when widgets are saved at a piece of
syntax during elaboration) which we do not have in this case. More
generally, it continues to be a bit cursed that `Elab.Info` nodes are
used both for elaboration and delaboration (pretty-printing), so
entrenching that approach seems wrong. The better approach would be to
have a separate notion of pretty-printer annotation; but such a refactor
would not be clearly beneficial right now.
- To support non-JS-based environments such as
https://github.com/Julian/lean.nvim, `.ofWidget` requires also providing
another message which approximates the widget in a textual form.
However, in practice these environments might still want to support a
few specific user widgets such as "Try this".

---

Closes #2064.
@mhuisi
Copy link
Collaborator

mhuisi commented May 29, 2024

Hmm, the only reasonable name I can think of is something like AnchorPosContext since the position describes where a specific component is anchored in the source code.

@Vtec234
Copy link
Member Author

Vtec234 commented Jun 3, 2024

Okay, renamed to EnvPosContext and simplified docstring.

@Vtec234 Vtec234 merged commit 5a56e3a into master Jun 3, 2024
4 checks passed
@Vtec234 Vtec234 deleted the widget-messages branch June 3, 2024 21:23
mhuisi added a commit that referenced this pull request Jun 5, 2024
mhuisi added a commit that referenced this pull request Jun 5, 2024
Vtec234 added a commit that referenced this pull request Jun 5, 2024
Implementation of leanprover/lean4#2064.

Besides adding support for widget messages, this adds an `EnvPosContext`
that stores the position that a component is "about" (see the docstring
for more detail). This was originally proposed in #197 and eventually
dismissed (see #226 for a detailed discussion), but I think it warrants
a reconsideration. While Gabriel's point that there are many positions
around remains true, the `EnvPosContext` stores a very specific one.
This position is only used to retrieve a snapshot, and from that a
`Lean.Environment`, on the server-side. Widgets currently have to pass
this position around manually; this has led to
[errors](leanprover-community/ProofWidgets4@ca66ebb)
in user code. Furthermore, so far I have not encountered any situation
where it makes sense to modify the position; thus a context seems like a
preferable approach. If needed, the context can still be set by users.

I also had to update some package versions to have tests building again.
I hope that didn't break anything!
Vtec234 added a commit that referenced this pull request Jun 16, 2024
Implementation of leanprover/lean4#2064.

Besides adding support for widget messages, this adds an `EnvPosContext`
that stores the position that a component is "about" (see the docstring
for more detail). This was originally proposed in #197 and eventually
dismissed (see #226 for a detailed discussion), but I think it warrants
a reconsideration. While Gabriel's point that there are many positions
around remains true, the `EnvPosContext` stores a very specific one.
This position is only used to retrieve a snapshot, and from that a
`Lean.Environment`, on the server-side. Widgets currently have to pass
this position around manually; this has led to
[errors](leanprover-community/ProofWidgets4@ca66ebb)
in user code. Furthermore, so far I have not encountered any situation
where it makes sense to modify the position; thus a context seems like a
preferable approach. If needed, the context can still be set by users.

I also had to update some package versions to have tests building again.
I hope that didn't break anything!
Vtec234 added a commit that referenced this pull request Jun 16, 2024
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.

None yet

2 participants