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