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

feature: teach rust-analyzer to discover linked_projects #17246

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

davidbarsky
Copy link
Contributor

@davidbarsky davidbarsky commented May 16, 2024

This PR's been a long-time coming, but like the title says, it introduces server-side project discovery and removes the extension hooks I previously introduced. I don't think this PR is ready to land, but here are the things I'm feeling squishy about:

  • I don't think I like the idea of introducing the cargo-metadata command-but-for-everything-else in the flycheck module, but the progress reporting infrastructure was too convenient to pass up. Happy to move it elsewhere.

Here are the things I know I need to change:

  • For progress reporting, I'm extracting from a serde_json::Value that corresponds to tracing_subsciber::fmt::Layer's JSON output. I'd like to make this a bit more structured/documented than the current nonsense I wrote.
  • The progress reporting currently hardcodes "Buck"; it should be deriving that from the previously mentioned more-structured-output.
  • This doesn't handle reloading when a corresponding buildfile is changed. It should be doing that.
Anyway, here's a video of rust-analyzer discovering a Buck target.
rust-project.mov

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 16, 2024
@davidbarsky davidbarsky force-pushed the david/move-rust-project-generation-to-server branch 4 times, most recently from 378ef57 to e62932f Compare May 22, 2024 16:26
Copy link
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

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

Haven't looked at the main_loop.rs and reload.rs changes yet, will do that tomorrow

if self.config.linked_or_discovered_projects() != old_config.linked_or_discovered_projects()
{
self.fetch_workspaces_queue.request_op("discovered projects changed".to_owned(), false)
self.fetch_workspaces_queue.request_op("discovered projects changed".to_owned(), true)
Copy link
Member

Choose a reason for hiding this comment

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

Seeing this we should probably make this an enum (I'm at fault for introducing a bool here and being lazy)

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 can change this to an enum, since I'm doing a bunch of surgery here anyways: would something like (bad namesincoming!) ReloadBehavior { Force, Done } be a decent starting point?

crates/project-model/Cargo.toml Outdated Show resolved Hide resolved
crates/rust-analyzer/src/config.rs Outdated Show resolved Hide resolved
crates/rust-analyzer/src/config.rs Outdated Show resolved Hide resolved
crates/rust-analyzer/src/config.rs Outdated Show resolved Hide resolved
Comment on lines 84 to 92
self.show_message(
lsp_types::MessageType::ERROR,
message,
tracing::enabled!(tracing::Level::ERROR),
);
}
None => {
tracing::error!("{}", &message);
self.send_notification::<lsp_types::notification::ShowMessage>(
lsp_types::ShowMessageParams { typ: lsp_types::MessageType::ERROR, message },
);
}
}
self.show_message(
lsp_types::MessageType::ERROR,
message,
tracing::enabled!(tracing::Level::ERROR),
);
Copy link
Member

Choose a reason for hiding this comment

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

This unnecessarily opens the log button notification now when there is no additional info in the logs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

where should error messages from flycheck be printed? flycheck eagerly gets that, but printing with additional information interrupts the error message.

that's probably a sign that the the stuff in flycheck isn't sufficient here, huh

Copy link
Member

Choose a reason for hiding this comment

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

I don't think I understand, why is flycheck relevant here? This is just for logging errors, if the error has no extra information we show all the info in the popup, if it has additional info we log that and tell the user to check the logs by giving the pop up a button. I'm a bit confused as to why you need to make changes here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right, sorry: it's the interaction of several different features.

  • tracing::enabled!(tracing::Level::ERROR) is almost always true (since it's the default level for tracing-subscriber)
  • CargoActor in flycheck will be printing out the lines it couldn't parse as JSON (which will often contain the error itself...), but that's interleaved with the additional_info.

If I'm not make this change, the end result is the following (where the additional_info is "unable to do the things"):

Screenshot of mangled logs Screenshot 2024-05-23 at 11 18 14 AM

that's probably a sign that the the stuff in flycheck isn't sufficient here, huh

This is what I meant when I said "that's probably a sign that the the stuff in flycheck isn't sufficient here, huh". However, having thought about it, it's not that flycheck is incorrect! It's that the CLI that i'm calling here, rust-project, that's wrong. It should communicate the underlying error in a more structured matter.

I'll hack on something today and propose something in this PR, which would let me undo the change here.

@Veykril
Copy link
Member

Veykril commented May 22, 2024

I don't think I like the idea of introducing the cargo-metadata command-but-for-everything-else in the flycheck module, but the progress reporting infrastructure was too convenient to pass up. Happy to move it elsewhere.

The flycheck crate is a mess now (at least name wise) anyways as it also does stuff for the test explorer, so that doesn't really make things a lot worse now...

@davidbarsky davidbarsky force-pushed the david/move-rust-project-generation-to-server branch 2 times, most recently from ace6d7d to 1003808 Compare May 22, 2024 21:22
@bors
Copy link
Collaborator

bors commented May 23, 2024

☔ The latest upstream changes (presumably #17287) made this pull request unmergeable. Please resolve the merge conflicts.

@davidbarsky davidbarsky force-pushed the david/move-rust-project-generation-to-server branch from 1003808 to 57fa458 Compare May 23, 2024 22:35
@bors
Copy link
Collaborator

bors commented May 24, 2024

☔ The latest upstream changes (presumably #17275) made this pull request unmergeable. Please resolve the merge conflicts.

@Veykril Veykril added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 27, 2024
@davidbarsky davidbarsky force-pushed the david/move-rust-project-generation-to-server branch from 57fa458 to 1404d02 Compare May 29, 2024 20:58
@davidbarsky davidbarsky force-pushed the david/move-rust-project-generation-to-server branch from 1404d02 to ce2c55c Compare May 30, 2024 23:08
@bors
Copy link
Collaborator

bors commented Jun 1, 2024

☔ The latest upstream changes (presumably #17278) made this pull request unmergeable. Please resolve the merge conflicts.

@davidbarsky davidbarsky force-pushed the david/move-rust-project-generation-to-server branch from ce2c55c to be92e74 Compare June 5, 2024 15:00
@davidbarsky
Copy link
Contributor Author

For "reload rust-analyzer reasons when a TARGETS/BUCK file changes"; this PR is based atop of #16840.

facebook-github-bot pushed a commit to facebook/buck2 that referenced this pull request Jun 6, 2024
Summary: To support rust-lang/rust-analyzer#17246, I've added an argument for logging using JSON to that rust-analyzer can use these fields for progress reporting.

Reviewed By: Wilfred

Differential Revision: D57924551

fbshipit-source-id: 992e9e096fdea1eefe2b199d8dd84be7b247a732
@bors
Copy link
Collaborator

bors commented Jun 6, 2024

☔ The latest upstream changes (presumably #17346) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants