kilbd / nova-rust

A Rust extension for the Nova text editor, using the Rust Analyzer language server.
MIT License
29 stars 5 forks source link

[BUG] `target/` gets flushed when a background syntax check is running (on save) #31

Open valeriansaliou opened 2 years ago

valeriansaliou commented 2 years ago

Describe the bug

Whenever I save a Rust file from Nova, nova-rust performs a background check of the syntax and errors, which works perfectly fine. However, whenever this runs, I lose my target/ cache from the previous build in my terminal (manual build using eg. cargo build), which makes the next build slow.

Also, when the background syntax check operation runs, and is still running while I attempt to call: cargo build in my terminal, I also see:

Blocking waiting for file lock on build directory

This shows that something is sharing the same target/ directory in my local project, and I'm not sure this used to happen in the previous nova-rust versions.

My options are as follow in the screenshot:

image

To Reproduce

  1. Build your Rust project using cargo build
  2. Re-build your Rust project using cargo build (the target/ cache is used)
  3. Change a file, save it in Nova
  4. Try running cargo build (slow!), the cache was purged by the extension

Expected behavior

My target/ build cache would stay populated, and I wouldnt have to compete w/ another build lockfile.

Versions (please complete the following information):

kilbd commented 2 years ago

Rust Analyzer uses Cargo for issue checks on save (cargo check or cargo clippy depending on the preference you set as shown above), which is why your target directory is being shared.

Your best bet to prevent sharing is probably to add --target-dir ./target-check to the Additional Arguments preference in the Issues section (see your screenshot above). You can of course use whatever directory name suits you, but you'd need to add it to your .gitignore. I'll note that you can set this preference per-project if it doesn't make sense as a global preference. (Project -> Project Settings... -> Rust extension)

valeriansaliou commented 2 years ago

Thank you, this worked perfect to fix the issue!

In terms of developer UX, I'd advise adding this to the README, or maybe even auto-configuring the default --target-dir to be some temporary folder owned by Nova (possibly w/ a permanent cache), outside of the Rust project. Even if I know the standard Rust tools share the target/ folder between commands, something definitely collides here.