@@ -63,6 +63,13 @@ mod patch_old_style;
63
63
// To deprecate an option by replacing it with another name use `new_name | `old_name` so that we keep
64
64
// parsing the old name.
65
65
config_data ! {
66
+ /// Configs that apply on a workspace-wide scope. There are 3 levels on which a global configuration can be configured
67
+ ///
68
+ /// 1. `rust-analyzer.toml` file under user's config directory (e.g ~/.config/rust-analyzer.toml)
69
+ /// 2. Client's own configurations (e.g `settings.json` on VS Code)
70
+ /// 3. `rust-analyzer.toml` file located at the workspace root
71
+ ///
72
+ /// A config is searched for by traversing a "config tree" in a bottom up fashion. It is chosen by the nearest first principle.
66
73
global: struct GlobalConfigData <- GlobalConfigInput -> {
67
74
/// Whether to insert #[must_use] when generating `as_` methods
68
75
/// for enum variants.
@@ -270,16 +277,51 @@ config_data! {
270
277
/// Controls file watching implementation.
271
278
files_watcher: FilesWatcherDef = FilesWatcherDef :: Client ,
272
279
280
+ /// Whether to show `Debug` action. Only applies when
281
+ /// `#rust-analyzer.hover.actions.enable#` is set.
282
+ hover_actions_debug_enable: bool = true ,
283
+ /// Whether to show HoverActions in Rust files.
284
+ hover_actions_enable: bool = true ,
285
+ /// Whether to show `Go to Type Definition` action. Only applies when
286
+ /// `#rust-analyzer.hover.actions.enable#` is set.
287
+ hover_actions_gotoTypeDef_enable: bool = true ,
288
+ /// Whether to show `Implementations` action. Only applies when
289
+ /// `#rust-analyzer.hover.actions.enable#` is set.
290
+ hover_actions_implementations_enable: bool = true ,
291
+ /// Whether to show `References` action. Only applies when
292
+ /// `#rust-analyzer.hover.actions.enable#` is set.
293
+ hover_actions_references_enable: bool = false ,
294
+ /// Whether to show `Run` action. Only applies when
295
+ /// `#rust-analyzer.hover.actions.enable#` is set.
296
+ hover_actions_run_enable: bool = true ,
297
+
298
+ /// Whether to show documentation on hover.
299
+ hover_documentation_enable: bool = true ,
300
+ /// Whether to show keyword hover popups. Only applies when
301
+ /// `#rust-analyzer.hover.documentation.enable#` is set.
302
+ hover_documentation_keywords_enable: bool = true ,
303
+ /// Use markdown syntax for links on hover.
304
+ hover_links_enable: bool = true ,
305
+ /// How to render the align information in a memory layout hover.
306
+ hover_memoryLayout_alignment: Option <MemoryLayoutHoverRenderKindDef > = Some ( MemoryLayoutHoverRenderKindDef :: Hexadecimal ) ,
307
+ /// Whether to show memory layout data on hover.
308
+ hover_memoryLayout_enable: bool = true ,
309
+ /// How to render the niche information in a memory layout hover.
310
+ hover_memoryLayout_niches: Option <bool > = Some ( false ) ,
311
+ /// How to render the offset information in a memory layout hover.
312
+ hover_memoryLayout_offset: Option <MemoryLayoutHoverRenderKindDef > = Some ( MemoryLayoutHoverRenderKindDef :: Hexadecimal ) ,
313
+ /// How to render the size information in a memory layout hover.
314
+ hover_memoryLayout_size: Option <MemoryLayoutHoverRenderKindDef > = Some ( MemoryLayoutHoverRenderKindDef :: Both ) ,
315
+ /// How many associated items of a trait to display when hovering a trait.
316
+ hover_show_traitAssocItems: Option <usize > = None ,
273
317
274
318
/// Enables the experimental support for interpreting tests.
275
319
interpret_tests: bool = false ,
276
320
277
-
278
-
279
321
/// Whether to show `Debug` lens. Only applies when
280
322
/// `#rust-analyzer.lens.enable#` is set.
281
323
lens_debug_enable: bool = true ,
282
- /// Whether to show CodeLens in Rust files.
324
+ /// Whether to show CodeLens in Rust files.
283
325
lens_enable: bool = true ,
284
326
/// Internal config: use custom client-side commands even when the
285
327
/// client doesn't set the corresponding capability.
@@ -393,6 +435,8 @@ config_data! {
393
435
}
394
436
395
437
config_data ! {
438
+ /// Local configurations can be overridden for every crate by placing a `rust-analyzer.toml` on crate root.
439
+ /// A config is searched for by traversing a "config tree" in a bottom up fashion. It is chosen by the nearest first principle.
396
440
local: struct LocalConfigData <- LocalConfigInput -> {
397
441
/// Toggles the additional completions that automatically add imports when completed.
398
442
/// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
@@ -467,45 +511,6 @@ config_data! {
467
511
/// Enables highlighting of all break points for a loop or block context while the cursor is on any `async` or `await` keywords.
468
512
highlightRelated_yieldPoints_enable: bool = true ,
469
513
470
- /// Whether to show `Debug` action. Only applies when
471
- /// `#rust-analyzer.hover.actions.enable#` is set.
472
- hover_actions_debug_enable: bool = true ,
473
- /// Whether to show HoverActions in Rust files.
474
- hover_actions_enable: bool = true ,
475
- /// Whether to show `Go to Type Definition` action. Only applies when
476
- /// `#rust-analyzer.hover.actions.enable#` is set.
477
- hover_actions_gotoTypeDef_enable: bool = true ,
478
- /// Whether to show `Implementations` action. Only applies when
479
- /// `#rust-analyzer.hover.actions.enable#` is set.
480
- hover_actions_implementations_enable: bool = true ,
481
- /// Whether to show `References` action. Only applies when
482
- /// `#rust-analyzer.hover.actions.enable#` is set.
483
- hover_actions_references_enable: bool = false ,
484
- /// Whether to show `Run` action. Only applies when
485
- /// `#rust-analyzer.hover.actions.enable#` is set.
486
- hover_actions_run_enable: bool = true ,
487
-
488
- /// Whether to show documentation on hover.
489
- hover_documentation_enable: bool = true ,
490
- /// Whether to show keyword hover popups. Only applies when
491
- /// `#rust-analyzer.hover.documentation.enable#` is set.
492
- hover_documentation_keywords_enable: bool = true ,
493
- /// Use markdown syntax for links on hover.
494
- hover_links_enable: bool = true ,
495
- /// How to render the align information in a memory layout hover.
496
- hover_memoryLayout_alignment: Option <MemoryLayoutHoverRenderKindDef > = Some ( MemoryLayoutHoverRenderKindDef :: Hexadecimal ) ,
497
- /// Whether to show memory layout data on hover.
498
- hover_memoryLayout_enable: bool = true ,
499
- /// How to render the niche information in a memory layout hover.
500
- hover_memoryLayout_niches: Option <bool > = Some ( false ) ,
501
- /// How to render the offset information in a memory layout hover.
502
- hover_memoryLayout_offset: Option <MemoryLayoutHoverRenderKindDef > = Some ( MemoryLayoutHoverRenderKindDef :: Hexadecimal ) ,
503
- /// How to render the size information in a memory layout hover.
504
- hover_memoryLayout_size: Option <MemoryLayoutHoverRenderKindDef > = Some ( MemoryLayoutHoverRenderKindDef :: Both ) ,
505
-
506
- /// How many associated items of a trait to display when hovering a trait.
507
- hover_show_traitAssocItems: Option <usize > = Option :: <usize >:: None ,
508
-
509
514
/// Whether to enforce the import granularity setting for all files. If set to false rust-analyzer will try to keep import styles consistent per file.
510
515
imports_granularity_enforce: bool = false ,
511
516
/// How imports should be grouped into use statements.
@@ -621,6 +626,8 @@ config_data! {
621
626
}
622
627
623
628
config_data ! {
629
+ /// Configs that only make sense when they are set by a client. As such they can only be defined
630
+ /// by setting them using client's settings (e.g `settings.json` on VS Code).
624
631
client: struct ClientConfigData <- ClientConfigInput -> { }
625
632
}
626
633
@@ -637,8 +644,8 @@ pub struct Config {
637
644
638
645
default_config : ConfigData ,
639
646
client_config : ConfigInput ,
640
- xdg_config : ConfigInput ,
641
- ratoml_arena : FxHashMap < SourceRootId , RatomlNode > ,
647
+ user_config : ConfigInput ,
648
+ ratoml_files : FxHashMap < SourceRootId , RatomlNode > ,
642
649
}
643
650
644
651
#[ derive( Clone , Debug ) ]
@@ -871,8 +878,8 @@ impl Config {
871
878
workspace_roots,
872
879
visual_studio_code_version,
873
880
client_config : ConfigInput :: default ( ) ,
874
- xdg_config : ConfigInput :: default ( ) ,
875
- ratoml_arena : FxHashMap :: default ( ) ,
881
+ user_config : ConfigInput :: default ( ) ,
882
+ ratoml_files : FxHashMap :: default ( ) ,
876
883
default_config : ConfigData :: default ( ) ,
877
884
}
878
885
}
@@ -909,9 +916,8 @@ impl Config {
909
916
. map ( AbsPathBuf :: assert)
910
917
. collect ( ) ;
911
918
patch_old_style:: patch_json_for_outdated_configs ( & mut json) ;
912
- let input = ConfigInput :: from_json ( json, & mut errors) ;
913
- self . client_config = input;
914
- tracing:: debug!( "deserialized config data: {:#?}" , self . client_config) ;
919
+ self . client_config = ConfigInput :: from_json ( json, & mut errors) ;
920
+ tracing:: debug!( ?self . client_config, "deserialized config data" ) ;
915
921
self . snippets . clear ( ) ;
916
922
917
923
let snips = self . completion_snippets_custom ( None ) . to_owned ( ) ;
@@ -1056,36 +1062,32 @@ impl Config {
1056
1062
}
1057
1063
}
1058
1064
1059
- pub fn hover_actions ( & self , source_root : Option < SourceRootId > ) -> HoverActionsConfig {
1060
- let enable =
1061
- self . experimental ( "hoverActions" ) && self . hover_actions_enable ( source_root) . to_owned ( ) ;
1065
+ pub fn hover_actions ( & self ) -> HoverActionsConfig {
1066
+ let enable = self . experimental ( "hoverActions" ) && self . hover_actions_enable ( ) . to_owned ( ) ;
1062
1067
HoverActionsConfig {
1063
- implementations : enable
1064
- && self . hover_actions_implementations_enable ( source_root) . to_owned ( ) ,
1065
- references : enable && self . hover_actions_references_enable ( source_root) . to_owned ( ) ,
1066
- run : enable && self . hover_actions_run_enable ( source_root) . to_owned ( ) ,
1067
- debug : enable && self . hover_actions_debug_enable ( source_root) . to_owned ( ) ,
1068
- goto_type_def : enable && self . hover_actions_gotoTypeDef_enable ( source_root) . to_owned ( ) ,
1068
+ implementations : enable && self . hover_actions_implementations_enable ( ) . to_owned ( ) ,
1069
+ references : enable && self . hover_actions_references_enable ( ) . to_owned ( ) ,
1070
+ run : enable && self . hover_actions_run_enable ( ) . to_owned ( ) ,
1071
+ debug : enable && self . hover_actions_debug_enable ( ) . to_owned ( ) ,
1072
+ goto_type_def : enable && self . hover_actions_gotoTypeDef_enable ( ) . to_owned ( ) ,
1069
1073
}
1070
1074
}
1071
1075
1072
- pub fn hover ( & self , source_root : Option < SourceRootId > ) -> HoverConfig {
1076
+ pub fn hover ( & self ) -> HoverConfig {
1073
1077
let mem_kind = |kind| match kind {
1074
1078
MemoryLayoutHoverRenderKindDef :: Both => MemoryLayoutHoverRenderKind :: Both ,
1075
1079
MemoryLayoutHoverRenderKindDef :: Decimal => MemoryLayoutHoverRenderKind :: Decimal ,
1076
1080
MemoryLayoutHoverRenderKindDef :: Hexadecimal => MemoryLayoutHoverRenderKind :: Hexadecimal ,
1077
1081
} ;
1078
1082
HoverConfig {
1079
- links_in_hover : self . hover_links_enable ( source_root) . to_owned ( ) ,
1080
- memory_layout : self . hover_memoryLayout_enable ( source_root) . then_some (
1081
- MemoryLayoutHoverConfig {
1082
- size : self . hover_memoryLayout_size ( source_root) . map ( mem_kind) ,
1083
- offset : self . hover_memoryLayout_offset ( source_root) . map ( mem_kind) ,
1084
- alignment : self . hover_memoryLayout_alignment ( source_root) . map ( mem_kind) ,
1085
- niches : self . hover_memoryLayout_niches ( source_root) . unwrap_or_default ( ) ,
1086
- } ,
1087
- ) ,
1088
- documentation : self . hover_documentation_enable ( source_root) . to_owned ( ) ,
1083
+ links_in_hover : self . hover_links_enable ( ) . to_owned ( ) ,
1084
+ memory_layout : self . hover_memoryLayout_enable ( ) . then_some ( MemoryLayoutHoverConfig {
1085
+ size : self . hover_memoryLayout_size ( ) . map ( mem_kind) ,
1086
+ offset : self . hover_memoryLayout_offset ( ) . map ( mem_kind) ,
1087
+ alignment : self . hover_memoryLayout_alignment ( ) . map ( mem_kind) ,
1088
+ niches : self . hover_memoryLayout_niches ( ) . unwrap_or_default ( ) ,
1089
+ } ) ,
1090
+ documentation : self . hover_documentation_enable ( ) . to_owned ( ) ,
1089
1091
format : {
1090
1092
let is_markdown = try_or_def ! ( self
1091
1093
. caps
@@ -1103,8 +1105,8 @@ impl Config {
1103
1105
HoverDocFormat :: PlainText
1104
1106
}
1105
1107
} ,
1106
- keywords : self . hover_documentation_keywords_enable ( source_root ) . to_owned ( ) ,
1107
- max_trait_assoc_items_count : self . hover_show_traitAssocItems ( source_root ) . to_owned ( ) ,
1108
+ keywords : self . hover_documentation_keywords_enable ( ) . to_owned ( ) ,
1109
+ max_trait_assoc_items_count : self . hover_show_traitAssocItems ( ) . to_owned ( ) ,
1108
1110
}
1109
1111
}
1110
1112
@@ -2206,7 +2208,7 @@ pub(crate) enum WorkspaceSymbolSearchKindDef {
2206
2208
#[ derive( Serialize , Deserialize , Debug , Copy , Clone , PartialEq ) ]
2207
2209
#[ serde( rename_all = "snake_case" ) ]
2208
2210
#[ serde( untagged) ]
2209
- enum MemoryLayoutHoverRenderKindDef {
2211
+ pub ( crate ) enum MemoryLayoutHoverRenderKindDef {
2210
2212
#[ serde( with = "unit_v::decimal" ) ]
2211
2213
Decimal ,
2212
2214
#[ serde( with = "unit_v::hexadecimal" ) ]
@@ -2270,7 +2272,7 @@ macro_rules! _impl_for_config_data {
2270
2272
return & v;
2271
2273
}
2272
2274
2273
- if let Some ( v) = self . xdg_config . local. $field. as_ref( ) {
2275
+ if let Some ( v) = self . user_config . local. $field. as_ref( ) {
2274
2276
return & v;
2275
2277
}
2276
2278
@@ -2293,7 +2295,7 @@ macro_rules! _impl_for_config_data {
2293
2295
return & v;
2294
2296
}
2295
2297
2296
- if let Some ( v) = self . xdg_config . global. $field. as_ref( ) {
2298
+ if let Some ( v) = self . user_config . global. $field. as_ref( ) {
2297
2299
return & v;
2298
2300
}
2299
2301
@@ -2325,7 +2327,7 @@ macro_rules! _impl_for_config_data {
2325
2327
2326
2328
macro_rules! _config_data {
2327
2329
// modname is for the tests
2328
- ( $modname: ident: struct $name: ident <- $input: ident -> {
2330
+ ( $( # [ doc=$dox : literal ] ) * $ modname: ident: struct $name: ident <- $input: ident -> {
2329
2331
$(
2330
2332
$( #[ doc=$doc: literal] ) *
2331
2333
$field: ident $( | $alias: ident) * : $ty: ty = $( @$marker: ident: ) ? $default: expr,
@@ -2392,7 +2394,7 @@ macro_rules! _config_data {
2392
2394
}
2393
2395
2394
2396
impl $input {
2395
- #[ allow( unused) ]
2397
+ #[ allow( unused, clippy :: ptr_arg ) ]
2396
2398
fn from_json( json: & mut serde_json:: Value , error_sink: & mut Vec <( String , serde_json:: Error ) >) -> Self {
2397
2399
Self { $(
2398
2400
$field: get_field(
@@ -2404,7 +2406,7 @@ macro_rules! _config_data {
2404
2406
) * }
2405
2407
}
2406
2408
2407
- #[ allow( unused) ]
2409
+ #[ allow( unused, clippy :: ptr_arg ) ]
2408
2410
fn from_toml( toml: & mut toml:: Table , error_sink: & mut Vec <( String , toml:: de:: Error ) >) -> Self {
2409
2411
Self { $(
2410
2412
$field: get_field_toml:: <$ty>(
0 commit comments