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

refactor: make RPC independent of infoview #226

Merged
merged 12 commits into from
Jul 22, 2022
Merged

refactor: make RPC independent of infoview #226

merged 12 commits into from
Jul 22, 2022

Conversation

gebner
Copy link
Member

@gebner gebner commented Jul 20, 2022

This PR refactors the RpcSessions class.

  • It is now independent of the infoview. (Currently in infoview-api because that's where we put all code shared between infoview and extension). This allows us to potentially use the RPC interface in the extension as well to make fancier hovers, etc. See Go-to-definition for types in hover lean4#1117
  • The "user"-facing RpcSession type now stores the position in the file (which is required for RPC calls). This greatly simplifies the API wrappers.
  • The RpcSession type also registers the RPC references automatically. This reduces the API surface of RpcSession and again greatly simplifies the wrappers.
  • I've added a React context for the current RpcSession. This removes a lot of pos props in the widget components. Addresses Infoview DocumentPosition should be a context #197.
  • The infos and messages components now properly keep track of the RpcSession associated with the retrieved diagnostics/goals. That is, if you pause an info and restart the file, we no longer send the now invalid(!) references from the old session to the newly restarted file worker.
  • I have removed the "refresh infoview by updating the RPC context when RPC sessions change" logic from the old WithRpcSessions component. The idea had a charm, but it was broken with paused infos anyhow, because they didn't (and shouldn't!) re-request the diagnostics/goals. Addresses Close RPC sessions on server restart. #66 (comment)
    What now happens when a file worker crashes or restarted is the following: Calls on RpcSessions from the old worker will fail, returning an appropriate error message (that is shown in the tooltip, and still needs to be made more user-friendly). Non-paused infos already listen on the server restarted event; they automatically update and pick up a new RpcSession to the new worker when they do that.
  • The RPC methods no longer have a spurious | undefined in the return type. If the RPC calls fail, then it throws an exception (with an informative error message) instead of returning undefined.

@gebner
Copy link
Member Author

gebner commented Jul 20, 2022

The test errors seem to be nondeterministic. The windows tests succeed more often than the linux tests, which often (but not always) fail at the "Bootstrap Test Suite" stage.

@gebner
Copy link
Member Author

gebner commented Jul 20, 2022

The test failure could be related to #227

@gebner
Copy link
Member Author

gebner commented Jul 20, 2022

Noticed a bug: if you delete a file, then apparently the session doesn't get closed.

Cannot send message to unknown document 'file:///home/gebner/quote4/comefrom.lean':
{"params":{"uri":"file:///home/gebner/quote4/comefrom.lean","sessionId":"5708447933963167614"},"method":"$/lean/rpc/keepAlive","jsonrpc":"2.0"}

This is most likely a bug in master as well, since it works fine if you close the file instead of deleting it.

@gebner gebner marked this pull request as draft July 20, 2022 12:11
@gebner
Copy link
Member Author

gebner commented Jul 20, 2022

Oops, I apparently broke the interactive diagnostics. Will look into this later.

@gebner
Copy link
Member Author

gebner commented Jul 20, 2022

Noticed a bug: if you delete a file, then apparently the session doesn't get closed.

Can't reproduce.

Oops, I apparently broke the interactive diagnostics.

Apparently we update goals and diagnostics on different schedules. I accidentally changed the code so that it only picks up the interactive diagnostics once the goals are updated, and they happen to be updated just before we get the interactive diagnostics. (We start out with the plain diagnostics, and only switch to the interactive ones when/if we get them.) Fixed now.

@gebner gebner marked this pull request as ready for review July 20, 2022 18:33
Copy link
Member

@Vtec234 Vtec234 left a comment

Choose a reason for hiding this comment

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

But my crazy reconnection code though :( Alas, #connecting: Map<DocumentUri, Promise<RpcSession | undefined>> will live on as a fond memory. I like the changes! I don't have time to test them, so the review is just about the codebase.

I've added a React context for the current RpcSession

Since the RpcSession now bundles positions, I am guessing you changed your mind about not using a context to store these since the linked issue?

lean4-infoview-api/src/rpcApi.ts Outdated Show resolved Hide resolved
lean4-infoview/src/infoview/info.tsx Outdated Show resolved Hide resolved
lean4-infoview-api/src/rpcSessions.ts Show resolved Hide resolved
lean4-infoview-api/src/rpcSessions.ts Outdated Show resolved Hide resolved
lean4-infoview-api/src/rpcSessions.ts Outdated Show resolved Hide resolved
lean4-infoview-api/src/rpcSessions.ts Show resolved Hide resolved
lean4-infoview-api/src/rpcSessions.ts Show resolved Hide resolved
lean4-infoview-api/src/rpcSessions.ts Show resolved Hide resolved
lean4-infoview/src/infoview/info.tsx Show resolved Hide resolved
lean4-infoview/src/infoview/rpcSessions.tsx Outdated Show resolved Hide resolved
@gebner
Copy link
Member Author

gebner commented Jul 21, 2022

Since the RpcSession now bundles positions, I am guessing you changed your mind about not using a context to store these since the linked issue?

I didn't like storing the position in the context because the position is ambiguous (does it refer to the position of the cursor, the message, etc.?). By contrast, the RpcSession is by necessity pretty much unique so it is a good fit for a context (since you shouldn't pass RpcRefs obtained from one RpcSession to an RPC call on another RpcSession).

Copy link
Member

@Vtec234 Vtec234 left a comment

Choose a reason for hiding this comment

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

LGTM, my only remaining question is here.

@gebner gebner merged commit 0e2b258 into master Jul 22, 2022
@gebner gebner mentioned this pull request Jul 22, 2022
3 tasks
@Vtec234 Vtec234 deleted the rpcrefactor branch July 23, 2022 20:19
@Vtec234 Vtec234 mentioned this pull request May 23, 2024
Vtec234 added a commit that referenced this pull request Jun 3, 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 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!
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