@@ -294,18 +294,6 @@ config_data! {
294
294
/// This option does not take effect until rust-analyzer is restarted.
295
295
rustc_source: Option <String > = None ,
296
296
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 ,
309
297
310
298
/// Enables automatic discovery of projects using [`DiscoverWorkspaceConfig::command`].
311
299
///
@@ -439,6 +427,18 @@ config_data! {
439
427
config_data ! {
440
428
workspace: struct WorkspaceDefaultConfigData <- WorkspaceConfigInput -> {
441
429
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 ,
442
442
443
443
}
444
444
}
@@ -775,7 +775,7 @@ pub struct Config {
775
775
user_config_path : VfsPath ,
776
776
777
777
/// Config node whose values apply to **every** Rust project.
778
- user_config : Option < ( GlobalLocalConfigInput , ConfigErrors ) > ,
778
+ user_config : Option < ( GlobalWorkspaceLocalConfigInput , ConfigErrors ) > ,
779
779
780
780
ratoml_file : FxHashMap < SourceRootId , ( RatomlFile , ConfigErrors ) > ,
781
781
@@ -825,13 +825,13 @@ impl Config {
825
825
if let Ok ( table) = toml:: from_str ( & change) {
826
826
let mut toml_errors = vec ! [ ] ;
827
827
validate_toml_table (
828
- GlobalLocalConfigInput :: FIELDS ,
828
+ GlobalWorkspaceLocalConfigInput :: FIELDS ,
829
829
& table,
830
830
& mut String :: new ( ) ,
831
831
& mut toml_errors,
832
832
) ;
833
833
config. user_config = Some ( (
834
- GlobalLocalConfigInput :: from_toml ( table, & mut toml_errors) ,
834
+ GlobalWorkspaceLocalConfigInput :: from_toml ( table, & mut toml_errors) ,
835
835
ConfigErrors (
836
836
toml_errors
837
837
. into_iter ( )
@@ -960,7 +960,7 @@ impl Config {
960
960
match toml:: from_str ( & text) {
961
961
Ok ( table) => {
962
962
validate_toml_table (
963
- GlobalLocalConfigInput :: FIELDS ,
963
+ WorkspaceLocalConfigInput :: FIELDS ,
964
964
& table,
965
965
& mut String :: new ( ) ,
966
966
& mut toml_errors,
@@ -1863,16 +1863,16 @@ impl Config {
1863
1863
}
1864
1864
}
1865
1865
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 ) {
1868
1868
Some ( args) if !args. is_empty ( ) => {
1869
1869
let mut args = args. clone ( ) ;
1870
1870
let command = args. remove ( 0 ) ;
1871
1871
RustfmtConfig :: CustomCommand { command, args }
1872
1872
}
1873
1873
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 ) ,
1876
1876
} ,
1877
1877
}
1878
1878
}
@@ -2555,24 +2555,20 @@ macro_rules! _impl_for_config_data {
2555
2555
$vis fn $field( & self , source_root: Option <SourceRootId >) -> & $ty {
2556
2556
let mut source_root = source_root. as_ref( ) ;
2557
2557
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;
2565
2561
}
2566
2562
}
2567
2563
source_root = self . source_root_parent_map. get( & sr) ;
2568
2564
}
2569
2565
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( ) {
2571
2567
return & v;
2572
2568
}
2573
2569
2574
2570
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( ) {
2576
2572
return & v;
2577
2573
}
2578
2574
}
@@ -2591,7 +2587,6 @@ macro_rules! _impl_for_config_data {
2591
2587
$(
2592
2588
$( $doc) *
2593
2589
#[ allow( non_snake_case) ]
2594
- // TODO Remove source_root
2595
2590
$vis fn $field( & self ) -> & $ty {
2596
2591
if let Some ( v) = self . client_config. 0 . global. $field. as_ref( ) {
2597
2592
return & v;
@@ -2730,6 +2725,7 @@ use _config_data as config_data;
2730
2725
#[ derive( Default , Debug , Clone ) ]
2731
2726
struct DefaultConfigData {
2732
2727
global : GlobalDefaultConfigData ,
2728
+ workspace : WorkspaceDefaultConfigData ,
2733
2729
local : LocalDefaultConfigData ,
2734
2730
client : ClientDefaultConfigData ,
2735
2731
}
@@ -2740,6 +2736,7 @@ struct DefaultConfigData {
2740
2736
#[ derive( Debug , Clone , Default ) ]
2741
2737
struct FullConfigInput {
2742
2738
global : GlobalConfigInput ,
2739
+ workspace : WorkspaceConfigInput ,
2743
2740
local : LocalConfigInput ,
2744
2741
client : ClientConfigInput ,
2745
2742
}
@@ -2753,6 +2750,7 @@ impl FullConfigInput {
2753
2750
global : GlobalConfigInput :: from_json ( & mut json, error_sink) ,
2754
2751
local : LocalConfigInput :: from_json ( & mut json, error_sink) ,
2755
2752
client : ClientConfigInput :: from_json ( & mut json, error_sink) ,
2753
+ workspace : WorkspaceConfigInput :: from_json ( & mut json, error_sink) ,
2756
2754
}
2757
2755
}
2758
2756
@@ -2783,26 +2781,28 @@ impl FullConfigInput {
2783
2781
/// some rust-analyzer.toml file or JSON blob. An empty rust-analyzer.toml corresponds to
2784
2782
/// all fields being None.
2785
2783
#[ derive( Debug , Clone , Default ) ]
2786
- struct GlobalLocalConfigInput {
2784
+ struct GlobalWorkspaceLocalConfigInput {
2787
2785
global : GlobalConfigInput ,
2788
2786
local : LocalConfigInput ,
2787
+ workspace : WorkspaceConfigInput ,
2789
2788
}
2790
2789
2791
- impl GlobalLocalConfigInput {
2790
+ impl GlobalWorkspaceLocalConfigInput {
2792
2791
const FIELDS : & ' static [ & ' static [ & ' static str ] ] =
2793
2792
& [ GlobalConfigInput :: FIELDS , LocalConfigInput :: FIELDS ] ;
2794
2793
fn from_toml (
2795
2794
toml : toml:: Table ,
2796
2795
error_sink : & mut Vec < ( String , toml:: de:: Error ) > ,
2797
- ) -> GlobalLocalConfigInput {
2798
- GlobalLocalConfigInput {
2796
+ ) -> GlobalWorkspaceLocalConfigInput {
2797
+ GlobalWorkspaceLocalConfigInput {
2799
2798
global : GlobalConfigInput :: from_toml ( & toml, error_sink) ,
2800
2799
local : LocalConfigInput :: from_toml ( & toml, error_sink) ,
2800
+ workspace : WorkspaceConfigInput :: from_toml ( & toml, error_sink) ,
2801
2801
}
2802
2802
}
2803
2803
}
2804
2804
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
2806
2806
/// some rust-analyzer.toml file or JSON blob. An empty rust-analyzer.toml corresponds to
2807
2807
/// all fields being None.
2808
2808
#[ derive( Debug , Clone , Default ) ]
0 commit comments