rust-lang / rust-mode

Emacs configuration for Rust
Apache License 2.0
1.1k stars 176 forks source link

locate workspace rather than member crate #424

Closed rich-murphey closed 2 years ago

rich-murphey commented 2 years ago

This fixes a failure in next-error after compiling a member of a workspace.

When invoking rust-check from rust source code file that is a member of a workspace, next-error fails because the compilation buffer lists source code paths relative to the workspace root, not the member crate.

rust-cargo.el uses cargo-locate to determine the root of the path to the source files, and this provides the location of the member crate rather than the workspace. The compilation buffer which contains paths relative to the workspace root, not the member project.

This patch searches for a Cargo.toml in the parent and the parent's parent directories, and if present, uses that directory as the workspace root.

rich-murphey commented 2 years ago

After further testing, this has an additional issue. With the above patch, cargo check will run in the workspace root rather than the member crate. So, next-error works, but this causes the whole workspace to be compiled.

rich-murphey commented 2 years ago

I'm closing this because rustic has a feature that seems to cover this use case. rustic-buffer-workspace seems to support compiling in workspaces.