@@ -34,7 +34,6 @@ use project_model::{
3434use rustc_hash:: { FxHashMap , FxHashSet } ;
3535use serde:: { de:: DeserializeOwned , Deserialize , Serialize } ;
3636use stdx:: format_to_acc;
37- use toml;
3837use vfs:: { AbsPath , AbsPathBuf } ;
3938
4039use crate :: {
@@ -63,6 +62,13 @@ mod patch_old_style;
6362// To deprecate an option by replacing it with another name use `new_name | `old_name` so that we keep
6463// parsing the old name.
6564config_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.
6672 global: struct GlobalConfigData <- GlobalConfigInput -> {
6773 /// Whether to insert #[must_use] when generating `as_` methods
6874 /// for enum variants.
@@ -270,16 +276,51 @@ config_data! {
270276 /// Controls file watching implementation.
271277 files_watcher: FilesWatcherDef = FilesWatcherDef :: Client ,
272278
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 ,
273316
274317 /// Enables the experimental support for interpreting tests.
275318 interpret_tests: bool = false ,
276319
277-
278-
279320 /// Whether to show `Debug` lens. Only applies when
280321 /// `#rust-analyzer.lens.enable#` is set.
281322 lens_debug_enable: bool = true ,
282- /// Whether to show CodeLens in Rust files.
323+ /// Whether to show CodeLens in Rust files.
283324 lens_enable: bool = true ,
284325 /// Internal config: use custom client-side commands even when the
285326 /// client doesn't set the corresponding capability.
@@ -393,6 +434,8 @@ config_data! {
393434}
394435
395436config_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.
396439 local: struct LocalConfigData <- LocalConfigInput -> {
397440 /// Toggles the additional completions that automatically add imports when completed.
398441 /// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
@@ -467,45 +510,6 @@ config_data! {
467510 /// Enables highlighting of all break points for a loop or block context while the cursor is on any `async` or `await` keywords.
468511 highlightRelated_yieldPoints_enable: bool = true ,
469512
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-
509513 /// 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.
510514 imports_granularity_enforce: bool = false ,
511515 /// How imports should be grouped into use statements.
@@ -621,6 +625,8 @@ config_data! {
621625}
622626
623627config_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).
624630 client: struct ClientConfigData <- ClientConfigInput -> { }
625631}
626632
@@ -637,8 +643,8 @@ pub struct Config {
637643
638644 default_config : ConfigData ,
639645 client_config : ConfigInput ,
640- xdg_config : ConfigInput ,
641- ratoml_arena : FxHashMap < SourceRootId , RatomlNode > ,
646+ user_config : ConfigInput ,
647+ ratoml_files : FxHashMap < SourceRootId , RatomlNode > ,
642648}
643649
644650#[ derive( Clone , Debug ) ]
@@ -871,8 +877,8 @@ impl Config {
871877 workspace_roots,
872878 is_visual_studio_code,
873879 client_config : ConfigInput :: default ( ) ,
874- xdg_config : ConfigInput :: default ( ) ,
875- ratoml_arena : FxHashMap :: default ( ) ,
880+ user_config : ConfigInput :: default ( ) ,
881+ ratoml_files : FxHashMap :: default ( ) ,
876882 default_config : ConfigData :: default ( ) ,
877883 }
878884 }
@@ -909,9 +915,8 @@ impl Config {
909915 . map ( AbsPathBuf :: assert)
910916 . collect ( ) ;
911917 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" ) ;
915920 self . snippets . clear ( ) ;
916921
917922 let snips = self . completion_snippets_custom ( None ) . to_owned ( ) ;
@@ -1056,36 +1061,32 @@ impl Config {
10561061 }
10571062 }
10581063
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 ( ) ;
10621066 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 ( ) ,
10691072 }
10701073 }
10711074
1072- pub fn hover ( & self , source_root : Option < SourceRootId > ) -> HoverConfig {
1075+ pub fn hover ( & self ) -> HoverConfig {
10731076 let mem_kind = |kind| match kind {
10741077 MemoryLayoutHoverRenderKindDef :: Both => MemoryLayoutHoverRenderKind :: Both ,
10751078 MemoryLayoutHoverRenderKindDef :: Decimal => MemoryLayoutHoverRenderKind :: Decimal ,
10761079 MemoryLayoutHoverRenderKindDef :: Hexadecimal => MemoryLayoutHoverRenderKind :: Hexadecimal ,
10771080 } ;
10781081 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 ( ) ,
10891090 format : {
10901091 let is_markdown = try_or_def ! ( self
10911092 . caps
@@ -1103,8 +1104,8 @@ impl Config {
11031104 HoverDocFormat :: PlainText
11041105 }
11051106 } ,
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 ( ) ,
11081109 }
11091110 }
11101111
@@ -2202,7 +2203,7 @@ pub(crate) enum WorkspaceSymbolSearchKindDef {
22022203#[ derive( Serialize , Deserialize , Debug , Copy , Clone , PartialEq ) ]
22032204#[ serde( rename_all = "snake_case" ) ]
22042205#[ serde( untagged) ]
2205- enum MemoryLayoutHoverRenderKindDef {
2206+ pub ( crate ) enum MemoryLayoutHoverRenderKindDef {
22062207 #[ serde( with = "unit_v::decimal" ) ]
22072208 Decimal ,
22082209 #[ serde( with = "unit_v::hexadecimal" ) ]
@@ -2266,7 +2267,7 @@ macro_rules! _impl_for_config_data {
22662267 return & v;
22672268 }
22682269
2269- if let Some ( v) = self . xdg_config . local. $field. as_ref( ) {
2270+ if let Some ( v) = self . user_config . local. $field. as_ref( ) {
22702271 return & v;
22712272 }
22722273
@@ -2289,7 +2290,7 @@ macro_rules! _impl_for_config_data {
22892290 return & v;
22902291 }
22912292
2292- if let Some ( v) = self . xdg_config . global. $field. as_ref( ) {
2293+ if let Some ( v) = self . user_config . global. $field. as_ref( ) {
22932294 return & v;
22942295 }
22952296
@@ -2321,7 +2322,7 @@ macro_rules! _impl_for_config_data {
23212322
23222323macro_rules! _config_data {
23232324 // modname is for the tests
2324- ( $modname: ident: struct $name: ident <- $input: ident -> {
2325+ ( $( # [ doc=$dox : literal ] ) * $ modname: ident: struct $name: ident <- $input: ident -> {
23252326 $(
23262327 $( #[ doc=$doc: literal] ) *
23272328 $field: ident $( | $alias: ident) * : $ty: ty = $( @$marker: ident: ) ? $default: expr,
@@ -2388,7 +2389,7 @@ macro_rules! _config_data {
23882389 }
23892390
23902391 impl $input {
2391- #[ allow( unused) ]
2392+ #[ allow( unused, clippy :: ptr_arg ) ]
23922393 fn from_json( json: & mut serde_json:: Value , error_sink: & mut Vec <( String , serde_json:: Error ) >) -> Self {
23932394 Self { $(
23942395 $field: get_field(
@@ -2400,7 +2401,7 @@ macro_rules! _config_data {
24002401 ) * }
24012402 }
24022403
2403- #[ allow( unused) ]
2404+ #[ allow( unused, clippy :: ptr_arg ) ]
24042405 fn from_toml( toml: & mut toml:: Table , error_sink: & mut Vec <( String , toml:: de:: Error ) >) -> Self {
24052406 Self { $(
24062407 $field: get_field_toml:: <$ty>(
0 commit comments