@@ -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 workspace-wide level. 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 in the reversed order. First found declaration is chosen.
66
72
global: struct GlobalConfigData <- GlobalConfigInput -> {
67
73
/// Whether to insert #[must_use] when generating `as_` methods
68
74
/// for enum variants.
@@ -268,6 +274,41 @@ config_data! {
268
274
/// Controls file watching implementation.
269
275
files_watcher: FilesWatcherDef = FilesWatcherDef :: Client ,
270
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 ) ,
271
312
272
313
/// Enables the experimental support for interpreting tests.
273
314
interpret_tests: bool = false ,
@@ -392,6 +433,9 @@ config_data! {
392
433
}
393
434
394
435
config_data ! {
436
+ /// Local configurations can be overridden for every crate by placing a `rust-analyzer.toml` on crate root.
437
+ /// Starting from the nearest `SourceRoot` (i.e the crate itself for which a configuration is called.) a tree of configuration files is traversed and
438
+ /// first occurrence is used.
395
439
local: struct LocalConfigData <- LocalConfigInput -> {
396
440
/// Toggles the additional completions that automatically add imports when completed.
397
441
/// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
@@ -466,42 +510,6 @@ config_data! {
466
510
/// Enables highlighting of all break points for a loop or block context while the cursor is on any `async` or `await` keywords.
467
511
highlightRelated_yieldPoints_enable: bool = true ,
468
512
469
- /// Whether to show `Debug` action. Only applies when
470
- /// `#rust-analyzer.hover.actions.enable#` is set.
471
- hover_actions_debug_enable: bool = true ,
472
- /// Whether to show HoverActions in Rust files.
473
- hover_actions_enable: bool = true ,
474
- /// Whether to show `Go to Type Definition` action. Only applies when
475
- /// `#rust-analyzer.hover.actions.enable#` is set.
476
- hover_actions_gotoTypeDef_enable: bool = true ,
477
- /// Whether to show `Implementations` action. Only applies when
478
- /// `#rust-analyzer.hover.actions.enable#` is set.
479
- hover_actions_implementations_enable: bool = true ,
480
- /// Whether to show `References` action. Only applies when
481
- /// `#rust-analyzer.hover.actions.enable#` is set.
482
- hover_actions_references_enable: bool = false ,
483
- /// Whether to show `Run` action. Only applies when
484
- /// `#rust-analyzer.hover.actions.enable#` is set.
485
- hover_actions_run_enable: bool = true ,
486
-
487
- /// Whether to show documentation on hover.
488
- hover_documentation_enable: bool = true ,
489
- /// Whether to show keyword hover popups. Only applies when
490
- /// `#rust-analyzer.hover.documentation.enable#` is set.
491
- hover_documentation_keywords_enable: bool = true ,
492
- /// Use markdown syntax for links on hover.
493
- hover_links_enable: bool = true ,
494
- /// How to render the align information in a memory layout hover.
495
- hover_memoryLayout_alignment: Option <MemoryLayoutHoverRenderKindDef > = Some ( MemoryLayoutHoverRenderKindDef :: Hexadecimal ) ,
496
- /// Whether to show memory layout data on hover.
497
- hover_memoryLayout_enable: bool = true ,
498
- /// How to render the niche information in a memory layout hover.
499
- hover_memoryLayout_niches: Option <bool > = Some ( false ) ,
500
- /// How to render the offset information in a memory layout hover.
501
- hover_memoryLayout_offset: Option <MemoryLayoutHoverRenderKindDef > = Some ( MemoryLayoutHoverRenderKindDef :: Hexadecimal ) ,
502
- /// How to render the size information in a memory layout hover.
503
- hover_memoryLayout_size: Option <MemoryLayoutHoverRenderKindDef > = Some ( MemoryLayoutHoverRenderKindDef :: Both ) ,
504
-
505
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.
506
514
imports_granularity_enforce: bool = false ,
507
515
/// How imports should be grouped into use statements.
@@ -617,6 +625,8 @@ config_data! {
617
625
}
618
626
619
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).
620
630
client: struct ClientConfigData <- ClientConfigInput -> { }
621
631
}
622
632
@@ -633,8 +643,8 @@ pub struct Config {
633
643
634
644
default_config : ConfigData ,
635
645
client_config : ConfigInput ,
636
- xdg_config : ConfigInput ,
637
- ratoml_arena : FxHashMap < SourceRootId , RatomlNode > ,
646
+ user_config : ConfigInput ,
647
+ ratoml_files : FxHashMap < SourceRootId , RatomlNode > ,
638
648
}
639
649
640
650
#[ derive( Clone , Debug ) ]
@@ -867,8 +877,8 @@ impl Config {
867
877
workspace_roots,
868
878
is_visual_studio_code,
869
879
client_config : ConfigInput :: default ( ) ,
870
- xdg_config : ConfigInput :: default ( ) ,
871
- ratoml_arena : FxHashMap :: default ( ) ,
880
+ user_config : ConfigInput :: default ( ) ,
881
+ ratoml_files : FxHashMap :: default ( ) ,
872
882
default_config : ConfigData :: default ( ) ,
873
883
}
874
884
}
@@ -905,9 +915,8 @@ impl Config {
905
915
. map ( AbsPathBuf :: assert)
906
916
. collect ( ) ;
907
917
patch_old_style:: patch_json_for_outdated_configs ( & mut json) ;
908
- let input = ConfigInput :: from_json ( json, & mut errors) ;
909
- self . client_config = input;
910
- 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" ) ;
911
920
self . snippets . clear ( ) ;
912
921
913
922
let snips = self . completion_snippets_custom ( None ) . to_owned ( ) ;
@@ -1051,36 +1060,32 @@ impl Config {
1051
1060
}
1052
1061
}
1053
1062
1054
- pub fn hover_actions ( & self , source_root : Option < SourceRootId > ) -> HoverActionsConfig {
1055
- let enable =
1056
- self . experimental ( "hoverActions" ) && self . hover_actions_enable ( source_root) . to_owned ( ) ;
1063
+ pub fn hover_actions ( & self ) -> HoverActionsConfig {
1064
+ let enable = self . experimental ( "hoverActions" ) && self . hover_actions_enable ( ) . to_owned ( ) ;
1057
1065
HoverActionsConfig {
1058
- implementations : enable
1059
- && self . hover_actions_implementations_enable ( source_root) . to_owned ( ) ,
1060
- references : enable && self . hover_actions_references_enable ( source_root) . to_owned ( ) ,
1061
- run : enable && self . hover_actions_run_enable ( source_root) . to_owned ( ) ,
1062
- debug : enable && self . hover_actions_debug_enable ( source_root) . to_owned ( ) ,
1063
- goto_type_def : enable && self . hover_actions_gotoTypeDef_enable ( source_root) . to_owned ( ) ,
1066
+ implementations : enable && self . hover_actions_implementations_enable ( ) . to_owned ( ) ,
1067
+ references : enable && self . hover_actions_references_enable ( ) . to_owned ( ) ,
1068
+ run : enable && self . hover_actions_run_enable ( ) . to_owned ( ) ,
1069
+ debug : enable && self . hover_actions_debug_enable ( ) . to_owned ( ) ,
1070
+ goto_type_def : enable && self . hover_actions_gotoTypeDef_enable ( ) . to_owned ( ) ,
1064
1071
}
1065
1072
}
1066
1073
1067
- pub fn hover ( & self , source_root : Option < SourceRootId > ) -> HoverConfig {
1074
+ pub fn hover ( & self ) -> HoverConfig {
1068
1075
let mem_kind = |kind| match kind {
1069
1076
MemoryLayoutHoverRenderKindDef :: Both => MemoryLayoutHoverRenderKind :: Both ,
1070
1077
MemoryLayoutHoverRenderKindDef :: Decimal => MemoryLayoutHoverRenderKind :: Decimal ,
1071
1078
MemoryLayoutHoverRenderKindDef :: Hexadecimal => MemoryLayoutHoverRenderKind :: Hexadecimal ,
1072
1079
} ;
1073
1080
HoverConfig {
1074
- links_in_hover : self . hover_links_enable ( source_root) . to_owned ( ) ,
1075
- memory_layout : self . hover_memoryLayout_enable ( source_root) . then_some (
1076
- MemoryLayoutHoverConfig {
1077
- size : self . hover_memoryLayout_size ( source_root) . map ( mem_kind) ,
1078
- offset : self . hover_memoryLayout_offset ( source_root) . map ( mem_kind) ,
1079
- alignment : self . hover_memoryLayout_alignment ( source_root) . map ( mem_kind) ,
1080
- niches : self . hover_memoryLayout_niches ( source_root) . unwrap_or_default ( ) ,
1081
- } ,
1082
- ) ,
1083
- documentation : self . hover_documentation_enable ( source_root) . to_owned ( ) ,
1081
+ links_in_hover : self . hover_links_enable ( ) . to_owned ( ) ,
1082
+ memory_layout : self . hover_memoryLayout_enable ( ) . then_some ( MemoryLayoutHoverConfig {
1083
+ size : self . hover_memoryLayout_size ( ) . map ( mem_kind) ,
1084
+ offset : self . hover_memoryLayout_offset ( ) . map ( mem_kind) ,
1085
+ alignment : self . hover_memoryLayout_alignment ( ) . map ( mem_kind) ,
1086
+ niches : self . hover_memoryLayout_niches ( ) . unwrap_or_default ( ) ,
1087
+ } ) ,
1088
+ documentation : self . hover_documentation_enable ( ) . to_owned ( ) ,
1084
1089
format : {
1085
1090
let is_markdown = try_or_def ! ( self
1086
1091
. caps
@@ -1098,7 +1103,7 @@ impl Config {
1098
1103
HoverDocFormat :: PlainText
1099
1104
}
1100
1105
} ,
1101
- keywords : self . hover_documentation_keywords_enable ( source_root ) . to_owned ( ) ,
1106
+ keywords : self . hover_documentation_keywords_enable ( ) . to_owned ( ) ,
1102
1107
}
1103
1108
}
1104
1109
@@ -2196,7 +2201,7 @@ pub(crate) enum WorkspaceSymbolSearchKindDef {
2196
2201
#[ derive( Serialize , Deserialize , Debug , Copy , Clone , PartialEq ) ]
2197
2202
#[ serde( rename_all = "snake_case" ) ]
2198
2203
#[ serde( untagged) ]
2199
- enum MemoryLayoutHoverRenderKindDef {
2204
+ pub ( crate ) enum MemoryLayoutHoverRenderKindDef {
2200
2205
#[ serde( with = "unit_v::decimal" ) ]
2201
2206
Decimal ,
2202
2207
#[ serde( with = "unit_v::hexadecimal" ) ]
@@ -2260,7 +2265,7 @@ macro_rules! _impl_for_config_data {
2260
2265
return & v;
2261
2266
}
2262
2267
2263
- if let Some ( v) = self . xdg_config . local. $field. as_ref( ) {
2268
+ if let Some ( v) = self . user_config . local. $field. as_ref( ) {
2264
2269
return & v;
2265
2270
}
2266
2271
@@ -2283,7 +2288,7 @@ macro_rules! _impl_for_config_data {
2283
2288
return & v;
2284
2289
}
2285
2290
2286
- if let Some ( v) = self . xdg_config . global. $field. as_ref( ) {
2291
+ if let Some ( v) = self . user_config . global. $field. as_ref( ) {
2287
2292
return & v;
2288
2293
}
2289
2294
@@ -2315,7 +2320,7 @@ macro_rules! _impl_for_config_data {
2315
2320
2316
2321
macro_rules! _config_data {
2317
2322
// modname is for the tests
2318
- ( $modname: ident: struct $name: ident <- $input: ident -> {
2323
+ ( $( # [ doc=$dox : literal ] ) * $ modname: ident: struct $name: ident <- $input: ident -> {
2319
2324
$(
2320
2325
$( #[ doc=$doc: literal] ) *
2321
2326
$field: ident $( | $alias: ident) * : $ty: ty = $( @$marker: ident: ) ? $default: expr,
@@ -2382,7 +2387,7 @@ macro_rules! _config_data {
2382
2387
}
2383
2388
2384
2389
impl $input {
2385
- #[ allow( unused) ]
2390
+ #[ allow( unused, clippy :: ptr_arg ) ]
2386
2391
fn from_json( json: & mut serde_json:: Value , error_sink: & mut Vec <( String , serde_json:: Error ) >) -> Self {
2387
2392
Self { $(
2388
2393
$field: get_field(
@@ -2394,7 +2399,7 @@ macro_rules! _config_data {
2394
2399
) * }
2395
2400
}
2396
2401
2397
- #[ allow( unused) ]
2402
+ #[ allow( unused, clippy :: ptr_arg ) ]
2398
2403
fn from_toml( toml: & mut toml:: Table , error_sink: & mut Vec <( String , toml:: de:: Error ) >) -> Self {
2399
2404
Self { $(
2400
2405
$field: get_field_toml:: <$ty>(
0 commit comments