-
Notifications
You must be signed in to change notification settings - Fork 582
Implement hover and (stubbed) codeAction on stale state #5469
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
Conversation
f550e68 to
99cb8dd
Compare
|
|
||
| public: | ||
| LSPStaleTypechecker(UndoState &undoState) : undoState(undoState), pf(nullptr) {} | ||
| LSPStaleTypechecker(std::shared_ptr<const LSPConfiguration> config, UndoState &undoState); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like there's an asymmetry between LSPStaleTypechecker and LSPTypecheckerDelegate here.
Why doesn't LSPTypecheckerDelegate take an LSPConfiguration or a WorkerPool?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The config is used inside LSPStaleTypechecker::query directly because LSPStaleTypechecker::query largely duplicates the implementation of LSPTypechecker::query, while LSPTypecheckerDelegate can just delegate LSPTypechecker::query, where config is a field on LSPTypechecker.
The WorkerPool we create here exists for similar reasons: LSPTypechecker has a private WorkerPool. (Note that here we create an empty, i.e., zero-thread, WorkerPool, which actually causes work to run on the indexing thread itself.)
| if (typechecker.isStale()) { | ||
| config.logger->debug("HoverTask running on stale data"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way we can force the implementation of each LSPMethod to declare whether it's ok to be called with a stale state? I'd love to force opt-in, not opt-out.
(If that was already implemented in a previous PR I'd love to be pointed to the implementation.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a virtual method on LSPTask that defaults to return false, and we'll only feed an LSPStaleTypechecker
if it returns true. Currently only hover and codeAction opt in.
Lines 114 to 115 in db69c5c
| // Returns true if the task can operate on typechecker stale state. | |
| virtual bool canUseStaleData() const; |
|
🚦 We're going to hold off on merging this til non-mutating namer/resolver are in place, so I've slapped a Meanwhile I'm going to be working on getting some decent tests for this change. |
|
b9cd06d adds a simple test for a hover query in stale mode. |
a4b9dbb to
a338c90
Compare
|
Pulling this out of Flipped a coin to pick a reviewer and jez was the lucky winner. :) |
|
I should also point out that this PR can only access indexed files that were saved into the |
| // Reset the options to enable stale state and sleep-in-slow-path. | ||
| auto opts = make_shared<realmain::options::Options>(); | ||
| opts->lspStaleStateEnabled = true; | ||
| opts->sleepInSlowPath = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this required? This makes this test even slower than it currently is, right? (iiuc, this makes every slow path operation take 3 seconds artificially)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe a pause is the best option we have, but the slowness is honestly kind of nasty. (Let me get some numbers for you, but I believe that multithreaded_protocol_test takes substantially more time than on master.)
What we might be able to do is make the wait time configurable and set it to something much quicker than 3 seconds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there no option to use something like what we do for other tests with the sorbet fence messages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we're looking at:
master 32.18s
PR 78.06s
So we'll need some solution here. Turning down the sleep time in runSlowPath might be a good one; maybe some sort of backdoor "sleep until the test harness tells you to wake up" is a better one, though I'm not sure how complicated that'd be off the top of my head.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Integrating the mechanism implemented in #5539 gives us:
master 32.18s
#5539 34.16s (note: adds test of slow path blocking mechanism, which sleeps for 2s)
PR 39.37s
Taking a 7-second hit here is still not wonderful, but I'm thinking it's probably acceptable since we're not planning on adding a huge pile of protocol tests anyway.
(Haven't pushed this to this branch yet, but will do so once #5539 hits donemaster.)
a338c90 to
d8aa8f7
Compare
1fee8c8 to
15fd3ff
Compare
|
I think that since we now use non-mutating namer/resolver, this PR is probably ready for a proper review, is that right @aprocter ? |
af3f14a to
2d90865
Compare
froydnj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks reasonable; I think there are some type issues around pipeline::typecheck and getEvictedGs, but we can fix those up after the fact.
Motivation
This implements a (beta, or let's even call it alpha) feature that allows
hoverqueries to proceed even when slow-path typechecking is in progress. You have to opt into the feature with--enable-experimental-lsp-stale-state.Test plan
See included automated tests.