@@ -1997,41 +1997,13 @@ fn run_rustfmt(
1997
1997
}
1998
1998
RustfmtConfig :: CustomCommand { command, args } => {
1999
1999
let cmd = PathBuf :: from ( & command) ;
2000
- let mut components = cmd. components ( ) ;
2001
-
2002
- // to support rustc's suggested, default configuration
2003
- let mut cmd = match components. next ( ) {
2004
- Some ( std:: path:: Component :: CurDir ) => {
2005
- let rest = components. as_path ( ) ;
2006
-
2007
- let roots = snap
2008
- . workspaces
2009
- . iter ( )
2010
- . flat_map ( |ws| ws. workspace_definition_path ( ) )
2011
- . collect :: < Vec < & AbsPath > > ( ) ;
2012
-
2013
- let abs: Option < AbsPathBuf > = roots. into_iter ( ) . find_map ( |base| {
2014
- let abs = base. join ( rest) ;
2015
- std:: fs:: metadata ( & abs) . ok ( ) . map ( |_| abs)
2016
- } ) ;
2017
-
2018
- let command = match abs {
2019
- Some ( cmd) => cmd,
2020
- None => {
2021
- tracing:: error!(
2022
- rustfmt = ?command,
2023
- "Unable to make the format command an absolute path"
2024
- ) ;
2025
- anyhow:: bail!(
2026
- "Unable to make the format command an absolute path: {}" ,
2027
- command
2028
- ) ;
2029
- }
2030
- } ;
2031
-
2032
- process:: Command :: new ( & command. as_os_str ( ) )
2000
+ let workspace = CargoTargetSpec :: for_file ( & snap, file_id) ?;
2001
+ let mut cmd = match workspace {
2002
+ Some ( spec) => {
2003
+ let cmd = spec. workspace_root . join ( cmd) ;
2004
+ process:: Command :: new ( cmd. as_os_str ( ) )
2033
2005
}
2034
- _ => process:: Command :: new ( command ) ,
2006
+ None => process:: Command :: new ( cmd ) ,
2035
2007
} ;
2036
2008
2037
2009
cmd. envs ( snap. config . extra_env ( ) ) ;
0 commit comments