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