Skip to content

Commit 2e52129

Browse files
committed
Apply requested changes
1 parent 1fb04f1 commit 2e52129

File tree

6 files changed

+94
-110
lines changed

6 files changed

+94
-110
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
@@ -233,6 +233,7 @@ struct DepData {
233233
#[serde(rename = "crate")]
234234
krate: usize,
235235
#[serde(deserialize_with = "deserialize_crate_name")]
236+
#[serde(serialize_with = "serialize_crate_name")]
236237
name: CrateName,
237238
}
238239

@@ -249,3 +250,10 @@ where
249250
let name = String::deserialize(de)?;
250251
CrateName::new(&name).map_err(|err| de::Error::custom(format!("invalid crate name: {err:?}")))
251252
}
253+
254+
fn serialize_crate_name<S>(name: &CrateName, se: S) -> Result<S::Ok, S::Error>
255+
where
256+
S: serde::Serializer,
257+
{
258+
se.serialize_str(name)
259+
}

crates/rust-analyzer/src/config.rs

Lines changed: 79 additions & 77 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.
@@ -267,16 +274,51 @@ config_data! {
267274
/// Controls file watching implementation.
268275
files_watcher: FilesWatcherDef = FilesWatcherDef::Client,
269276

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

271315
/// Enables the experimental support for interpreting tests.
272316
interpret_tests: bool = false,
273317

274-
275-
276318
/// Whether to show `Debug` lens. Only applies when
277319
/// `#rust-analyzer.lens.enable#` is set.
278320
lens_debug_enable: bool = true,
279-
/// Whether to show CodeLens in Rust files.
321+
/// Whether to show CodeLens in Rust files.
280322
lens_enable: bool = true,
281323
/// Internal config: use custom client-side commands even when the
282324
/// client doesn't set the corresponding capability.
@@ -390,6 +432,8 @@ config_data! {
390432
}
391433

392434
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.
393437
local: struct LocalConfigData <- LocalConfigInput -> {
394438
/// Toggles the additional completions that automatically add imports when completed.
395439
/// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
@@ -464,45 +508,6 @@ config_data! {
464508
/// Enables highlighting of all break points for a loop or block context while the cursor is on any `async` or `await` keywords.
465509
highlightRelated_yieldPoints_enable: bool = true,
466510

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-
506511
/// 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.
507512
imports_granularity_enforce: bool = false,
508513
/// How imports should be grouped into use statements.
@@ -618,6 +623,8 @@ config_data! {
618623
}
619624

620625
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).
621628
client: struct ClientConfigData <- ClientConfigInput -> {}
622629
}
623630

@@ -634,8 +641,8 @@ pub struct Config {
634641

635642
default_config: ConfigData,
636643
client_config: ConfigInput,
637-
xdg_config: ConfigInput,
638-
ratoml_arena: FxHashMap<SourceRootId, RatomlNode>,
644+
user_config: ConfigInput,
645+
ratoml_files: FxHashMap<SourceRootId, RatomlNode>,
639646
}
640647

641648
#[derive(Clone, Debug)]
@@ -868,8 +875,8 @@ impl Config {
868875
workspace_roots,
869876
visual_studio_code_version,
870877
client_config: ConfigInput::default(),
871-
xdg_config: ConfigInput::default(),
872-
ratoml_arena: FxHashMap::default(),
878+
user_config: ConfigInput::default(),
879+
ratoml_files: FxHashMap::default(),
873880
default_config: ConfigData::default(),
874881
}
875882
}
@@ -906,9 +913,8 @@ impl Config {
906913
.map(AbsPathBuf::assert)
907914
.collect();
908915
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");
912918
self.snippets.clear();
913919

914920
let snips = self.completion_snippets_custom(None).to_owned();
@@ -1053,36 +1059,32 @@ impl Config {
10531059
}
10541060
}
10551061

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();
10591064
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(),
10661070
}
10671071
}
10681072

1069-
pub fn hover(&self, source_root: Option<SourceRootId>) -> HoverConfig {
1073+
pub fn hover(&self) -> HoverConfig {
10701074
let mem_kind = |kind| match kind {
10711075
MemoryLayoutHoverRenderKindDef::Both => MemoryLayoutHoverRenderKind::Both,
10721076
MemoryLayoutHoverRenderKindDef::Decimal => MemoryLayoutHoverRenderKind::Decimal,
10731077
MemoryLayoutHoverRenderKindDef::Hexadecimal => MemoryLayoutHoverRenderKind::Hexadecimal,
10741078
};
10751079
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(),
10861088
format: {
10871089
let is_markdown = try_or_def!(self
10881090
.caps
@@ -1100,8 +1102,8 @@ impl Config {
11001102
HoverDocFormat::PlainText
11011103
}
11021104
},
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(),
11051107
}
11061108
}
11071109

@@ -2205,7 +2207,7 @@ pub(crate) enum WorkspaceSymbolSearchKindDef {
22052207
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq)]
22062208
#[serde(rename_all = "snake_case")]
22072209
#[serde(untagged)]
2208-
enum MemoryLayoutHoverRenderKindDef {
2210+
pub(crate) enum MemoryLayoutHoverRenderKindDef {
22092211
#[serde(with = "unit_v::decimal")]
22102212
Decimal,
22112213
#[serde(with = "unit_v::hexadecimal")]
@@ -2269,7 +2271,7 @@ macro_rules! _impl_for_config_data {
22692271
return &v;
22702272
}
22712273

2272-
if let Some(v) = self.xdg_config.local.$field.as_ref() {
2274+
if let Some(v) = self.user_config.local.$field.as_ref() {
22732275
return &v;
22742276
}
22752277

@@ -2292,7 +2294,7 @@ macro_rules! _impl_for_config_data {
22922294
return &v;
22932295
}
22942296

2295-
if let Some(v) = self.xdg_config.global.$field.as_ref() {
2297+
if let Some(v) = self.user_config.global.$field.as_ref() {
22962298
return &v;
22972299
}
22982300

@@ -2324,7 +2326,7 @@ macro_rules! _impl_for_config_data {
23242326

23252327
macro_rules! _config_data {
23262328
// modname is for the tests
2327-
($modname:ident: struct $name:ident <- $input:ident -> {
2329+
($(#[doc=$dox:literal])* $modname:ident: struct $name:ident <- $input:ident -> {
23282330
$(
23292331
$(#[doc=$doc:literal])*
23302332
$field:ident $(| $alias:ident)*: $ty:ty = $(@$marker:ident: )? $default:expr,
@@ -2391,7 +2393,7 @@ macro_rules! _config_data {
23912393
}
23922394

23932395
impl $input {
2394-
#[allow(unused)]
2396+
#[allow(unused, clippy::ptr_arg)]
23952397
fn from_json(json: &mut serde_json::Value, error_sink: &mut Vec<(String, serde_json::Error)>) -> Self {
23962398
Self {$(
23972399
$field: get_field(
@@ -2403,7 +2405,7 @@ macro_rules! _config_data {
24032405
)*}
24042406
}
24052407

2406-
#[allow(unused)]
2408+
#[allow(unused, clippy::ptr_arg)]
24072409
fn from_toml(toml: &mut toml::Table , error_sink: &mut Vec<(String, toml::de::Error)>) -> Self {
24082410
Self {$(
24092411
$field: get_field_toml::<$ty>(

0 commit comments

Comments
 (0)