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

In-server cargo check watching #2668

Merged
merged 20 commits into from
Dec 29, 2019
Merged

In-server cargo check watching #2668

merged 20 commits into from
Dec 29, 2019

Conversation

kiljacken
Copy link
Contributor

@kiljacken kiljacken commented Dec 25, 2019

Opening a draft now so people can follow the progress, and comment if they spot something stupid.

Things that need doing:

  • Running cargo check on save
  • Pipe through configuration options from client
  • Tests for parsing behavior
  • Remove existing cargo watch support from VSCode extension
  • Progress notification in VSCode extension using LSP 3.15 $/progress notification
  • Rework ra-ide diagnostics to support secondary messages
  • Make cargo-check watcher use ra-ide diagnostics

I'd love some input on whether to try to keep the status bar progress thingy for VSCode? It will require some plumbing, and maintaining yet another rust-analyzer specific LSP notification, which I'm not sure we want to.

Fixes #1894

@kiljacken kiljacken changed the title Initial implementation of cargo check watching In-server cargo check wathcing Dec 25, 2019
@kiljacken kiljacken changed the title In-server cargo check wathcing In-server cargo check watching Dec 25, 2019
@lnicola
Copy link
Member

lnicola commented Dec 25, 2019

I'd love some input on whether to try to keep the status bar progress thingy for VSCode? It will require some plumbing, and maintaining yet another rust-analyzer specific LSP notification, which I'm not sure we want to.

Does https://microsoft.github.io/language-server-protocol/specifications/specification-3-15/#progress help here?

@kiljacken
Copy link
Contributor Author

Does https://microsoft.github.io/language-server-protocol/specifications/specification-3-15/#progress help here?

Amazing, that seems to be just the kind of notification we'd need! They must be reading our collective minds.

@kiljacken
Copy link
Contributor Author

I decided against the changing anything with regard to ra-ide's diagnostic system for now, to keep the pull request at a manageable scope. If the CI passes, this should be ready for review.

@kiljacken kiljacken marked this pull request as ready for review December 25, 2019 19:02
@kiljacken
Copy link
Contributor Author

Okay, looks good to me, but this is large enough to need a couple eyes.

Key points:

  • cargo check (or another compatible output command) gets run on file save, as check needs up to date source on disk to do it's magic. This also means that no complex de-bouncing logic is needed currently.
  • Most of the diagnostic parsing code is ported directly from the Typescript implementation, so current behavior is maintained
  • It's currently enabled by default. I'm open to changing this, but until we have a broader set of diagnostics implemented by the server this is provides a better experience.
  • VSCode configuration remains mostly backwards compatible, with exception of arguments as we'd have to do full shell argument parsing to keep that compatible.
  • VSCode retains it's status display by using the new LSP 3.15 progress command, and adding a listener to the extension.

@@ -0,0 +1,1316 @@
//! cargo_check provides the functionality needed to run `cargo check` or
//! another compatible command (f.x. clippy) in a background thread and provide
//! LSP diagnostics based on the output of the command.
Copy link
Member

Choose a reason for hiding this comment

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

This module/crate would benefit from discussing our threading/scheduling/cancellation model. Like, how many threads do we use them, when we fire them up, how we make sure they are cleanly joined.

@matklad
Copy link
Member

matklad commented Dec 25, 2019

I've looked through this, and in general I like it! This is already big, so I am biased towards merging this sooner, rather than later, and fixing the fallout, rather than trying to do the perfect thing from the first try.

To do this, I think the main pre-requsite would be:

  • split into a separate crate
  • separate boring verbose code for parsing from complicated code that manages threads, processes and events (just move them to different modules)
  • move verbose tests to a separate file

It would also be nice, but not strictly necessary, to figure out the cancellation story from the start (as it might affect the overall design quite a bit).

@kiljacken
Copy link
Contributor Author

@matklad I've pushed some commits extracting the code into a ra_cargo_watch crate, splitting it into a few modules, and setting up a proper shutdown/cancellation strategy.

For shutdown or cancellation, dropping the corresponding struct always does "the right thing", e.g shutting down the thread and waiting for it to end. Hope that makes sense!

Even though this didn't error, it became clear to me that it was closing
the wrong channel, resulting in the child thread never finishing.
@flodiebold
Copy link
Member

I tried this out, and while it works great, I'm seeing some constant CPU usage from crossbeam select inside CheckWatcherState::run even while the server should be completely idle 😕

@kiljacken
Copy link
Contributor Author

@flodiebold I might know how to fix that. It's probably because the sub-process wrapper thread is ended, so one of the channels being selected from is always "ready", in that it always has a Err result ready. Shouldn't be hard to fix, give me a few minutes :)

@kiljacken
Copy link
Contributor Author

There we go, that solves the issue on my end.

@flodiebold Thanks for spotting it!

@flodiebold
Copy link
Member

That indeed fixes it! 👍

@matklad
Copy link
Member

matklad commented Dec 29, 2019

LGTM!

bors r+

bors bot added a commit that referenced this pull request Dec 29, 2019
2668: In-server cargo check watching r=matklad a=kiljacken

Opening a draft now so people can follow the progress, and comment if they spot something stupid.

Things that need doing:
- [x] Running cargo check on save
- [x] Pipe through configuration options from client
- [x] Tests for parsing behavior
- [x] Remove existing cargo watch support from VSCode extension
- [x] Progress notification in VSCode extension using LSP 3.15 `$/progress` notification
- [ ] ~~Rework ra-ide diagnostics to support secondary messages~~
- [ ] ~~Make cargo-check watcher use ra-ide diagnostics~~

~~I'd love some input on whether to try to keep the status bar progress thingy for VSCode? It will require some plumbing, and maintaining yet another rust-analyzer specific LSP notification, which I'm not sure we want to.~~

Fixes #1894 

Co-authored-by: Emil Lauridsen <mine809@gmail.com>
@bors
Copy link
Contributor

bors bot commented Dec 29, 2019

Build succeeded

  • Rust
  • TypeScript

@bors bors bot merged commit 899dbeb into rust-lang:master Dec 29, 2019
@kiljacken kiljacken deleted the cargo-watch branch December 29, 2019 13:09
fannheyward added a commit to fannheyward/coc-rust-analyzer that referenced this pull request Dec 30, 2019
keeneyetact added a commit to keeneyetact/rust-see that referenced this pull request May 9, 2023
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.

Move cargo watch support from typescript to rust
4 participants