Skip to content

Commit beef4bd

Browse files
committed
Apply requested changes
1 parent 94eab88 commit beef4bd

File tree

6 files changed

+95
-113
lines changed

6 files changed

+95
-113
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/base-db/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ salsa.workspace = true
1919
rustc-hash.workspace = true
2020
triomphe.workspace = true
2121
semver.workspace = true
22-
serde.workspace = true
2322
tracing.workspace = true
2423

2524
# local deps

crates/base-db/src/input.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use std::{fmt, mem, ops};
1111
use cfg::CfgOptions;
1212
use la_arena::{Arena, Idx, RawIdx};
1313
use rustc_hash::{FxHashMap, FxHashSet};
14-
use serde::Serialize;
1514
use span::Edition;
1615
use syntax::SmolStr;
1716
use triomphe::Arc;
@@ -103,15 +102,6 @@ pub type CrateId = Idx<CrateData>;
103102
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
104103
pub struct CrateName(SmolStr);
105104

106-
impl Serialize for CrateName {
107-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
108-
where
109-
S: serde::Serializer,
110-
{
111-
serializer.serialize_str(self)
112-
}
113-
}
114-
115105
impl CrateName {
116106
/// Creates a crate name, checking for dashes in the string provided.
117107
/// Dashes are not allowed in the crate names,

crates/project-model/src/project_json.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ pub(crate) struct Dep {
228228
#[serde(rename = "crate")]
229229
pub(crate) krate: CrateArrayIdx,
230230
#[serde(deserialize_with = "deserialize_crate_name")]
231+
#[serde(serialize_with = "serialize_crate_name")]
231232
pub(crate) name: CrateName,
232233
}
233234

@@ -244,3 +245,10 @@ where
244245
let name = String::deserialize(de)?;
245246
CrateName::new(&name).map_err(|err| de::Error::custom(format!("invalid crate name: {err:?}")))
246247
}
248+
249+
fn serialize_crate_name<S>(name: &CrateName, se: S) -> Result<S::Ok, S::Error>
250+
where
251+
S: serde::Serializer,
252+
{
253+
se.serialize_str(name)
254+
}

crates/rust-analyzer/src/config.rs

Lines changed: 80 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ mod patch_old_style;
6060
// To deprecate an option by replacing it with another name use `new_name | `old_name` so that we keep
6161
// parsing the old name.
6262
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.
6370
global: struct GlobalConfigData <- GlobalConfigInput -> {
6471
/// Whether to insert #[must_use] when generating `as_` methods
6572
/// for enum variants.
@@ -270,16 +277,51 @@ config_data! {
270277
/// Controls file watching implementation.
271278
files_watcher: FilesWatcherDef = FilesWatcherDef::Client,
272279

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,
273317

274318
/// Enables the experimental support for interpreting tests.
275319
interpret_tests: bool = false,
276320

277-
278-
279321
/// Whether to show `Debug` lens. Only applies when
280322
/// `#rust-analyzer.lens.enable#` is set.
281323
lens_debug_enable: bool = true,
282-
/// Whether to show CodeLens in Rust files.
324+
/// Whether to show CodeLens in Rust files.
283325
lens_enable: bool = true,
284326
/// Internal config: use custom client-side commands even when the
285327
/// client doesn't set the corresponding capability.
@@ -393,6 +435,8 @@ config_data! {
393435
}
394436

395437
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.
396440
local: struct LocalConfigData <- LocalConfigInput -> {
397441
/// Toggles the additional completions that automatically add imports when completed.
398442
/// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
@@ -467,47 +511,6 @@ config_data! {
467511
/// Enables highlighting of all break points for a loop or block context while the cursor is on any `async` or `await` keywords.
468512
highlightRelated_yieldPoints_enable: bool = true,
469513

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 fields of a struct to display when hovering a struct.
507-
hover_show_structFields: Option<usize> = Option::<usize>::None,
508-
/// How many associated items of a trait to display when hovering a trait.
509-
hover_show_traitAssocItems: Option<usize> = Option::<usize>::None,
510-
511514
/// 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.
512515
imports_granularity_enforce: bool = false,
513516
/// How imports should be grouped into use statements.
@@ -623,6 +626,8 @@ config_data! {
623626
}
624627

625628
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).
626631
client: struct ClientConfigData <- ClientConfigInput -> {}
627632
}
628633

@@ -639,8 +644,8 @@ pub struct Config {
639644

640645
default_config: ConfigData,
641646
client_config: ConfigInput,
642-
xdg_config: ConfigInput,
643-
ratoml_arena: FxHashMap<SourceRootId, RatomlNode>,
647+
user_config: ConfigInput,
648+
ratoml_files: FxHashMap<SourceRootId, RatomlNode>,
644649
}
645650

646651
#[derive(Clone, Debug)]
@@ -873,8 +878,8 @@ impl Config {
873878
workspace_roots,
874879
visual_studio_code_version,
875880
client_config: ConfigInput::default(),
876-
xdg_config: ConfigInput::default(),
877-
ratoml_arena: FxHashMap::default(),
881+
user_config: ConfigInput::default(),
882+
ratoml_files: FxHashMap::default(),
878883
default_config: ConfigData::default(),
879884
}
880885
}
@@ -911,9 +916,8 @@ impl Config {
911916
.map(AbsPathBuf::assert)
912917
.collect();
913918
patch_old_style::patch_json_for_outdated_configs(&mut json);
914-
let input = ConfigInput::from_json(json, &mut errors);
915-
self.client_config = input;
916-
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");
917921
self.snippets.clear();
918922

919923
let snips = self.completion_snippets_custom(None).to_owned();
@@ -1058,36 +1062,32 @@ impl Config {
10581062
}
10591063
}
10601064

1061-
pub fn hover_actions(&self, source_root: Option<SourceRootId>) -> HoverActionsConfig {
1062-
let enable =
1063-
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();
10641067
HoverActionsConfig {
1065-
implementations: enable
1066-
&& self.hover_actions_implementations_enable(source_root).to_owned(),
1067-
references: enable && self.hover_actions_references_enable(source_root).to_owned(),
1068-
run: enable && self.hover_actions_run_enable(source_root).to_owned(),
1069-
debug: enable && self.hover_actions_debug_enable(source_root).to_owned(),
1070-
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(),
10711073
}
10721074
}
10731075

1074-
pub fn hover(&self, source_root: Option<SourceRootId>) -> HoverConfig {
1076+
pub fn hover(&self) -> HoverConfig {
10751077
let mem_kind = |kind| match kind {
10761078
MemoryLayoutHoverRenderKindDef::Both => MemoryLayoutHoverRenderKind::Both,
10771079
MemoryLayoutHoverRenderKindDef::Decimal => MemoryLayoutHoverRenderKind::Decimal,
10781080
MemoryLayoutHoverRenderKindDef::Hexadecimal => MemoryLayoutHoverRenderKind::Hexadecimal,
10791081
};
10801082
HoverConfig {
1081-
links_in_hover: self.hover_links_enable(source_root).to_owned(),
1082-
memory_layout: self.hover_memoryLayout_enable(source_root).then_some(
1083-
MemoryLayoutHoverConfig {
1084-
size: self.hover_memoryLayout_size(source_root).map(mem_kind),
1085-
offset: self.hover_memoryLayout_offset(source_root).map(mem_kind),
1086-
alignment: self.hover_memoryLayout_alignment(source_root).map(mem_kind),
1087-
niches: self.hover_memoryLayout_niches(source_root).unwrap_or_default(),
1088-
},
1089-
),
1090-
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(),
10911091
format: {
10921092
let is_markdown = try_or_def!(self
10931093
.caps
@@ -1105,9 +1105,9 @@ impl Config {
11051105
HoverDocFormat::PlainText
11061106
}
11071107
},
1108-
keywords: self.hover_documentation_keywords_enable(source_root).to_owned(),
1109-
max_trait_assoc_items_count: self.hover_show_traitAssocItems(source_root).to_owned(),
1110-
max_struct_field_count: self.hover_show_structFields(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(),
1110+
max_struct_field_count: self.hover_show_structFields().to_owned(),
11111111
}
11121112
}
11131113

@@ -2244,7 +2244,7 @@ pub(crate) enum WorkspaceSymbolSearchKindDef {
22442244
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq)]
22452245
#[serde(rename_all = "snake_case")]
22462246
#[serde(untagged)]
2247-
enum MemoryLayoutHoverRenderKindDef {
2247+
pub(crate) enum MemoryLayoutHoverRenderKindDef {
22482248
#[serde(with = "unit_v::decimal")]
22492249
Decimal,
22502250
#[serde(with = "unit_v::hexadecimal")]
@@ -2308,7 +2308,7 @@ macro_rules! _impl_for_config_data {
23082308
return &v;
23092309
}
23102310

2311-
if let Some(v) = self.xdg_config.local.$field.as_ref() {
2311+
if let Some(v) = self.user_config.local.$field.as_ref() {
23122312
return &v;
23132313
}
23142314

@@ -2331,7 +2331,7 @@ macro_rules! _impl_for_config_data {
23312331
return &v;
23322332
}
23332333

2334-
if let Some(v) = self.xdg_config.global.$field.as_ref() {
2334+
if let Some(v) = self.user_config.global.$field.as_ref() {
23352335
return &v;
23362336
}
23372337

@@ -2363,7 +2363,7 @@ macro_rules! _impl_for_config_data {
23632363

23642364
macro_rules! _config_data {
23652365
// modname is for the tests
2366-
($modname:ident: struct $name:ident <- $input:ident -> {
2366+
($(#[doc=$dox:literal])* $modname:ident: struct $name:ident <- $input:ident -> {
23672367
$(
23682368
$(#[doc=$doc:literal])*
23692369
$field:ident $(| $alias:ident)*: $ty:ty = $(@$marker:ident: )? $default:expr,
@@ -2430,7 +2430,7 @@ macro_rules! _config_data {
24302430
}
24312431

24322432
impl $input {
2433-
#[allow(unused)]
2433+
#[allow(unused, clippy::ptr_arg)]
24342434
fn from_json(json: &mut serde_json::Value, error_sink: &mut Vec<(String, serde_json::Error)>) -> Self {
24352435
Self {$(
24362436
$field: get_field(
@@ -2442,7 +2442,7 @@ macro_rules! _config_data {
24422442
)*}
24432443
}
24442444

2445-
#[allow(unused)]
2445+
#[allow(unused, clippy::ptr_arg)]
24462446
fn from_toml(toml: &mut toml::Table , error_sink: &mut Vec<(String, toml::de::Error)>) -> Self {
24472447
Self {$(
24482448
$field: get_field_toml::<$ty>(

0 commit comments

Comments
 (0)