mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +00:00
fix: Join rustfmt overrideCommand with project root
When providing a custom rustfmt command, join it with the project root instead of the workspace root. This fixes rust-analyzer getting the wrong invocation path in projects containing subprojects. This makes the behaviour consistent with how a custom path provided in rust-analyzer.procMacro.server behaves already. Resolves issue #18222
This commit is contained in:
parent
e1a76671af
commit
6656460490
1 changed files with 3 additions and 3 deletions
|
@ -2201,14 +2201,14 @@ fn run_rustfmt(
|
||||||
let cmd = Utf8PathBuf::from(&command);
|
let cmd = Utf8PathBuf::from(&command);
|
||||||
let target_spec = TargetSpec::for_file(snap, file_id)?;
|
let target_spec = TargetSpec::for_file(snap, file_id)?;
|
||||||
let mut cmd = match target_spec {
|
let mut cmd = match target_spec {
|
||||||
Some(TargetSpec::Cargo(spec)) => {
|
Some(TargetSpec::Cargo(_)) => {
|
||||||
// approach: if the command name contains a path separator, join it with the workspace root.
|
// approach: if the command name contains a path separator, join it with the project root.
|
||||||
// however, if the path is absolute, joining will result in the absolute path being preserved.
|
// however, if the path is absolute, joining will result in the absolute path being preserved.
|
||||||
// as a fallback, rely on $PATH-based discovery.
|
// as a fallback, rely on $PATH-based discovery.
|
||||||
let cmd_path = if command.contains(std::path::MAIN_SEPARATOR)
|
let cmd_path = if command.contains(std::path::MAIN_SEPARATOR)
|
||||||
|| (cfg!(windows) && command.contains('/'))
|
|| (cfg!(windows) && command.contains('/'))
|
||||||
{
|
{
|
||||||
spec.workspace_root.join(cmd).into()
|
snap.config.root_path().join(cmd).into()
|
||||||
} else {
|
} else {
|
||||||
cmd
|
cmd
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue