Skip to content

refactor: preparing for user-widgets and context suggestions#193

Merged
gebner merged 10 commits intoleanprover:masterfrom
Vtec234:widget-refactor-pr
Jun 15, 2022
Merged

refactor: preparing for user-widgets and context suggestions#193
gebner merged 10 commits intoleanprover:masterfrom
Vtec234:widget-refactor-pr

Conversation

@EdAyers
Copy link
Contributor

@EdAyers EdAyers commented Jun 14, 2022

This is a set of refactors that me and @Vtec234 made while working on user widgets and context suggestions.

  • some docstrings
  • refactor InteractiveHypothesis => InteractiveHypothesisBundle
  • refactor: extract HypothesisBundle render to own component.
  • introduce a useAsync hook for use with rpcs
  • refactor TypePopupContents
  • InteractiveGoal and InteractiveHypothesisBundle have mvarId? and fvarIds? fields
  • helper function mapRpcError
  • helper enum RpcErrorCode
  • new override of useEventResult
  • fix a bug in handleInsertText where it was doing reference eq instead of string eq.

Co-authored-by: @Vtec234

This is a set of refactors that me and @Vtec234 made while working on user widgets and context suggestions.

- some docstrings
- refactor InteractiveHypothesis => InteractiveHypothesisBundle
- refactor: extract HypothesisBundle render to own component.
- introduce a `useAsync` hook for use with rpcs
- refactor TypePopupContents
- InteractiveGoal and InteractiveHypothesisBundle have mvarId? and fvarIds? fields
- helper function mapRpcError
- helper enum RpcErrorCode
- new override of useEventResult
- fix a bug in handleInsertText where it was doing reference eq instead of string eq.

Co-authored-by: Wojciech Nawrocki <wjnawrocki@protonmail.com>
@EdAyers EdAyers force-pushed the widget-refactor-pr branch from d49ab07 to 74bacc8 Compare June 14, 2022 17:57
@EdAyers EdAyers mentioned this pull request Jun 14, 2022
3 tasks
}, [pos.character, pos.line, pos.uri, msg])

if (tt) return <InteractiveMessage pos={pos} fmt={tt} />
else return <></>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
else return <></>
else return <>...</>

// Update state so the next render will show the fallback UI.
return { error: error.toString() };
}

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure how this component is going to be used (it's still unused). The Lean 3 version had a componentDidCatch handler, should we add this here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

componentDidCatch is needed if you want to log errors. I added a stub that does nothing in case react is looking for that method.

private async sessionAt(uri: DocumentUri): Promise<RpcSession | undefined> {
if (this.#connected.has(uri)) return this.#connected.get(uri)
else if (this.#connecting.has(uri)) return this.#connecting.get(uri)
else if (this.#connecting.has(uri)) return await this.#connecting.get(uri)
Copy link
Member

Choose a reason for hiding this comment

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

The await shouldn't be required here, or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I'm not sure. If you do return p where p : Promise<T> in an async function does the compiler automatically squash the Promise<Promise<T>> to a Promise<T>? I guess it must do.

Copy link
Member

Choose a reason for hiding this comment

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

It's not required, I just put it in for clarity.

/** This hook will run the given promise function whenever the deps change.
* There will only ever be one in-flight promise at a time. If the deps
* change while a promise is still in-flight, then the function will be run
* again after the first promise has resolved.
Copy link
Member

Choose a reason for hiding this comment

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

The purpose of this function is to prevent race conditions where the RPC requests return in a different order than they were sent, right?

  1. Request 1 is sent with, say, line=42.
  2. Request 2 is sent with line=90.
  3. Request 2 returns with diags=[].
  4. Request 1 returns with diags=['error'].
    And without useAsync we would now return the diagnostics for line 42 even though we're at line 90.

If that's the case, then that should be written in the docstring.

Is there a reason for "only ever be one in-flight promise at a time"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason for only having one at a time is so that you don't spam server with requests but maybe the server can handle it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of the 'one at a time' model we could instead have the callback of the promise check whether it has been superceded by a later rpc call and discard its result. That would also work.

Copy link
Member

Choose a reason for hiding this comment

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

It might be worth it to check if the more eager (multiple requests) approach increases responsiveness or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added an unthrottled version, not sure what the best way to test is. They both seem to work.

Copy link
Member

Choose a reason for hiding this comment

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

Let's just stick with the unthrottled one for now.

@gebner gebner merged commit 6f81ca8 into leanprover:master Jun 15, 2022
@Vtec234 Vtec234 deleted the widget-refactor-pr branch June 15, 2022 16:27
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.

3 participants