File tree 1 file changed +12
-2
lines changed
crates/rust-analyzer/src/handlers
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -2000,8 +2000,18 @@ fn run_rustfmt(
2000
2000
let workspace = CargoTargetSpec :: for_file ( & snap, file_id) ?;
2001
2001
let mut cmd = match workspace {
2002
2002
Some ( spec) => {
2003
- let cmd = spec. workspace_root . join ( cmd) ;
2004
- process:: Command :: new ( cmd. as_os_str ( ) )
2003
+ // approach: if the command name contains a path seperator, join it with the workspace root.
2004
+ // however, if the path is absolute, joining will result in the absolute path being preserved.
2005
+ // as a fallback, rely on $PATH-based discovery.
2006
+ let cmd_path =
2007
+ if cfg ! ( windows) && command. contains ( & [ std:: path:: MAIN_SEPARATOR , '/' ] ) {
2008
+ spec. workspace_root . join ( cmd) . into ( )
2009
+ } else if command. contains ( std:: path:: MAIN_SEPARATOR ) {
2010
+ spec. workspace_root . join ( cmd) . into ( )
2011
+ } else {
2012
+ cmd
2013
+ } ;
2014
+ process:: Command :: new ( cmd_path)
2005
2015
}
2006
2016
None => process:: Command :: new ( cmd) ,
2007
2017
} ;
You can’t perform that action at this time.
0 commit comments