-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feature: Create UnindexedProject
notification to be sent to the client
#15863
feature: Create UnindexedProject
notification to be sent to the client
#15863
Conversation
51d2ed8
to
29852bb
Compare
Did some profiling of this on my Mac and the profile below is generally representative:
13ms doesn't feel like the best, but is probably acceptable for an opt-in toggle. |
CI failed because of a timeout in receiving a notification, which doesn't feel great. |
Blocking in a notification handler is gonna end in a bad experience as notifications are handled on the main thread which means blocking there blocks processing anything else aside from thread pool tasks. It would probably make more sense to add a new |
243d25e
to
cdb7fc7
Compare
Moved over to a task-based approach. I'm not fully sure if this is the approach that you had in mind since |
cdb7fc7
to
4391d0a
Compare
let _p = profile::span("run_unindexed_project"); | ||
|
||
tracing::debug!(changes = self.process_changes(), "processes changes"); | ||
let snap = self.snapshot(); | ||
let id = | ||
crate::lsp::from_proto::file_id(&snap, &uri).expect("Unable to get file ID"); | ||
|
||
if let Ok(crates) = &snap.analysis.crates_for(id) { | ||
if crates.is_empty() { | ||
tracing::debug!(?uri, "rust-analyzer does not track this file"); | ||
self.send_notification::<ext::UnindexedProject>( | ||
ext::UnindexedProjectParams { | ||
text_documents: vec![lsp_types::TextDocumentIdentifier { uri }], | ||
}, | ||
); | ||
} else { | ||
tracing::warn!("was unable to get analysis for crate") | ||
} | ||
} |
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.
Now we are still processing it on the main thread :D All of this should be done in the spawned task on the thread pool, where as Task::FileIndexState
should be used to return the result of the computation here (the snap.analysis.crates_for(id)
result) and then have the task handler here just send the notification.
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.
After chatting about this over DMs, I'm not going to take the suggested approach and make this noop task more substantial since there is no way to ensure that this code runs after GlobalState::process_changes()
has been called without doing one of the following:
- Add a retry mechanism for tasks, which would make this a de-facto spin loop. This might be okay!
- Creating a mechanism of enqueuing a task, but deferring spawning them until after a turn of
GlobalState::handle_event
. This ensures thatGlobalState::process_changes()
has been called.
448eafb
to
26236ea
Compare
Right, I made two sets of changes that I would be completely happy with backing out on:
|
87f79ff
to
e568362
Compare
(Squashed commits; rebased against master. No meaningful change.) |
e568362
to
89057db
Compare
I've decided to back out of changes where I factored the Anyways, I've had this PR deployed in my employer's buck2-based monorepo and it has driven down instance of rust-analyzer not running for folks dramatically. |
d33ad25
to
aa7e33d
Compare
☔ The latest upstream changes (presumably #16182) made this pull request unmergeable. Please resolve the merge conflicts. |
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 is a similar thing I added for whether proc-macros have changed in #16247, we might be able to switch that to this approach as well. Will need to check
Having briefly looked over #16247, it's certainly a maybe. I considered using the request queue system, but that only really is able to handle a single event at a time. The task-based approach I did here can handle multiple events, which can happen with both |
73f8fad
to
3202c35
Compare
☔ The latest upstream changes (presumably #16470) made this pull request unmergeable. Please resolve the merge conflicts. |
b6155f0
to
79503ba
Compare
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.
clippy is complaining on CI
@bors delegate+ |
✌️ @davidbarsky, you can now approve this pull request! If @Veykril told you to " |
79503ba
to
c3db016
Compare
c3db016
to
6330b02
Compare
☀️ Test successful - checks-actions |
(Note that this branch contains commits from #15830, which I'll rebase atop of as needed.)
Based on the discussion in #15837, I've added a notification and off-by-default toggle to send that notification from
handle_did_open_text_document
. I'm happy to rename/tweak this as needed.I've been using this for a little bit, and it does seem to cause a little bit more indexing/work in rust-analyzer, but it's something that I'll profile as needed, I think.