@@ -294,18 +294,6 @@ config_data! {
294294 /// This option does not take effect until rust-analyzer is restarted.
295295 rustc_source: Option <String > = None ,
296296
297- /// Additional arguments to `rustfmt`.
298- rustfmt_extraArgs: Vec <String > = vec![ ] ,
299- /// Advanced option, fully override the command rust-analyzer uses for
300- /// formatting. This should be the equivalent of `rustfmt` here, and
301- /// not that of `cargo fmt`. The file contents will be passed on the
302- /// standard input and the formatted result will be read from the
303- /// standard output.
304- rustfmt_overrideCommand: Option <Vec <String >> = None ,
305- /// Enables the use of rustfmt's unstable range formatting command for the
306- /// `textDocument/rangeFormatting` request. The rustfmt option is unstable and only
307- /// available on a nightly build.
308- rustfmt_rangeFormatting_enable: bool = false ,
309297
310298 /// Enables automatic discovery of projects using [`DiscoverWorkspaceConfig::command`].
311299 ///
@@ -439,6 +427,18 @@ config_data! {
439427config_data ! {
440428 workspace: struct WorkspaceDefaultConfigData <- WorkspaceConfigInput -> {
441429
430+ /// Additional arguments to `rustfmt`.
431+ rustfmt_extraArgs: Vec <String > = vec![ ] ,
432+ /// Advanced option, fully override the command rust-analyzer uses for
433+ /// formatting. This should be the equivalent of `rustfmt` here, and
434+ /// not that of `cargo fmt`. The file contents will be passed on the
435+ /// standard input and the formatted result will be read from the
436+ /// standard output.
437+ rustfmt_overrideCommand: Option <Vec <String >> = None ,
438+ /// Enables the use of rustfmt's unstable range formatting command for the
439+ /// `textDocument/rangeFormatting` request. The rustfmt option is unstable and only
440+ /// available on a nightly build.
441+ rustfmt_rangeFormatting_enable: bool = false ,
442442
443443 }
444444}
@@ -775,7 +775,7 @@ pub struct Config {
775775 user_config_path : VfsPath ,
776776
777777 /// Config node whose values apply to **every** Rust project.
778- user_config : Option < ( GlobalLocalConfigInput , ConfigErrors ) > ,
778+ user_config : Option < ( GlobalWorkspaceLocalConfigInput , ConfigErrors ) > ,
779779
780780 ratoml_file : FxHashMap < SourceRootId , ( RatomlFile , ConfigErrors ) > ,
781781
@@ -825,13 +825,13 @@ impl Config {
825825 if let Ok ( table) = toml:: from_str ( & change) {
826826 let mut toml_errors = vec ! [ ] ;
827827 validate_toml_table (
828- GlobalLocalConfigInput :: FIELDS ,
828+ GlobalWorkspaceLocalConfigInput :: FIELDS ,
829829 & table,
830830 & mut String :: new ( ) ,
831831 & mut toml_errors,
832832 ) ;
833833 config. user_config = Some ( (
834- GlobalLocalConfigInput :: from_toml ( table, & mut toml_errors) ,
834+ GlobalWorkspaceLocalConfigInput :: from_toml ( table, & mut toml_errors) ,
835835 ConfigErrors (
836836 toml_errors
837837 . into_iter ( )
@@ -960,7 +960,7 @@ impl Config {
960960 match toml:: from_str ( & text) {
961961 Ok ( table) => {
962962 validate_toml_table (
963- GlobalLocalConfigInput :: FIELDS ,
963+ WorkspaceLocalConfigInput :: FIELDS ,
964964 & table,
965965 & mut String :: new ( ) ,
966966 & mut toml_errors,
@@ -1863,16 +1863,16 @@ impl Config {
18631863 }
18641864 }
18651865
1866- pub fn rustfmt ( & self ) -> RustfmtConfig {
1867- match & self . rustfmt_overrideCommand ( ) {
1866+ pub fn rustfmt ( & self , source_root_id : Option < SourceRootId > ) -> RustfmtConfig {
1867+ match & self . rustfmt_overrideCommand ( source_root_id ) {
18681868 Some ( args) if !args. is_empty ( ) => {
18691869 let mut args = args. clone ( ) ;
18701870 let command = args. remove ( 0 ) ;
18711871 RustfmtConfig :: CustomCommand { command, args }
18721872 }
18731873 Some ( _) | None => RustfmtConfig :: Rustfmt {
1874- extra_args : self . rustfmt_extraArgs ( ) . clone ( ) ,
1875- enable_range_formatting : * self . rustfmt_rangeFormatting_enable ( ) ,
1874+ extra_args : self . rustfmt_extraArgs ( source_root_id ) . clone ( ) ,
1875+ enable_range_formatting : * self . rustfmt_rangeFormatting_enable ( source_root_id ) ,
18761876 } ,
18771877 }
18781878 }
@@ -2555,24 +2555,20 @@ macro_rules! _impl_for_config_data {
25552555 $vis fn $field( & self , source_root: Option <SourceRootId >) -> & $ty {
25562556 let mut source_root = source_root. as_ref( ) ;
25572557 while let Some ( sr) = source_root {
2558- if let Some ( ( file, _) ) = self . ratoml_file. get( & sr) {
2559- match file {
2560- RatomlFile :: Workspace ( config) => {
2561- if let Some ( v) = config. workspace. $field. as_ref( ) {
2562- return & v;
2563- }
2564- } ,
2558+ if let Some ( ( RatomlFile :: Workspace ( config) , _) ) = self . ratoml_file. get( & sr) {
2559+ if let Some ( v) = config. workspace. $field. as_ref( ) {
2560+ return & v;
25652561 }
25662562 }
25672563 source_root = self . source_root_parent_map. get( & sr) ;
25682564 }
25692565
2570- if let Some ( v) = self . client_config. 0 . local . $field. as_ref( ) {
2566+ if let Some ( v) = self . client_config. 0 . workspace . $field. as_ref( ) {
25712567 return & v;
25722568 }
25732569
25742570 if let Some ( ( user_config, _) ) = self . user_config. as_ref( ) {
2575- if let Some ( v) = user_config. local . $field. as_ref( ) {
2571+ if let Some ( v) = user_config. workspace . $field. as_ref( ) {
25762572 return & v;
25772573 }
25782574 }
@@ -2591,7 +2587,6 @@ macro_rules! _impl_for_config_data {
25912587 $(
25922588 $( $doc) *
25932589 #[ allow( non_snake_case) ]
2594- // TODO Remove source_root
25952590 $vis fn $field( & self ) -> & $ty {
25962591 if let Some ( v) = self . client_config. 0 . global. $field. as_ref( ) {
25972592 return & v;
@@ -2730,6 +2725,7 @@ use _config_data as config_data;
27302725#[ derive( Default , Debug , Clone ) ]
27312726struct DefaultConfigData {
27322727 global : GlobalDefaultConfigData ,
2728+ workspace : WorkspaceDefaultConfigData ,
27332729 local : LocalDefaultConfigData ,
27342730 client : ClientDefaultConfigData ,
27352731}
@@ -2740,6 +2736,7 @@ struct DefaultConfigData {
27402736#[ derive( Debug , Clone , Default ) ]
27412737struct FullConfigInput {
27422738 global : GlobalConfigInput ,
2739+ workspace : WorkspaceConfigInput ,
27432740 local : LocalConfigInput ,
27442741 client : ClientConfigInput ,
27452742}
@@ -2753,6 +2750,7 @@ impl FullConfigInput {
27532750 global : GlobalConfigInput :: from_json ( & mut json, error_sink) ,
27542751 local : LocalConfigInput :: from_json ( & mut json, error_sink) ,
27552752 client : ClientConfigInput :: from_json ( & mut json, error_sink) ,
2753+ workspace : WorkspaceConfigInput :: from_json ( & mut json, error_sink) ,
27562754 }
27572755 }
27582756
@@ -2783,26 +2781,28 @@ impl FullConfigInput {
27832781/// some rust-analyzer.toml file or JSON blob. An empty rust-analyzer.toml corresponds to
27842782/// all fields being None.
27852783#[ derive( Debug , Clone , Default ) ]
2786- struct GlobalLocalConfigInput {
2784+ struct GlobalWorkspaceLocalConfigInput {
27872785 global : GlobalConfigInput ,
27882786 local : LocalConfigInput ,
2787+ workspace : WorkspaceConfigInput ,
27892788}
27902789
2791- impl GlobalLocalConfigInput {
2790+ impl GlobalWorkspaceLocalConfigInput {
27922791 const FIELDS : & ' static [ & ' static [ & ' static str ] ] =
27932792 & [ GlobalConfigInput :: FIELDS , LocalConfigInput :: FIELDS ] ;
27942793 fn from_toml (
27952794 toml : toml:: Table ,
27962795 error_sink : & mut Vec < ( String , toml:: de:: Error ) > ,
2797- ) -> GlobalLocalConfigInput {
2798- GlobalLocalConfigInput {
2796+ ) -> GlobalWorkspaceLocalConfigInput {
2797+ GlobalWorkspaceLocalConfigInput {
27992798 global : GlobalConfigInput :: from_toml ( & toml, error_sink) ,
28002799 local : LocalConfigInput :: from_toml ( & toml, error_sink) ,
2800+ workspace : WorkspaceConfigInput :: from_toml ( & toml, error_sink) ,
28012801 }
28022802 }
28032803}
28042804
2805- /// All of the config levels, all fields `Option<T>`, to describe fields that are actually set by
2805+ /// Workspace and local config levels, all fields `Option<T>`, to describe fields that are actually set by
28062806/// some rust-analyzer.toml file or JSON blob. An empty rust-analyzer.toml corresponds to
28072807/// all fields being None.
28082808#[ derive( Debug , Clone , Default ) ]
0 commit comments