Skip to content

Commit b313968

Browse files
committed
Apply requested changes
1 parent bc4e4b1 commit b313968

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, str::FromStr};
1111
use cfg::CfgOptions;
1212
use la_arena::{Arena, Idx, RawIdx};
1313
use rustc_hash::{FxHashMap, FxHashSet};
14-
use serde::Serialize;
1514
use syntax::SmolStr;
1615
use triomphe::Arc;
1716
use vfs::{file_set::FileSet, AbsPathBuf, AnchoredPath, FileId, VfsPath};
@@ -102,15 +101,6 @@ pub type CrateId = Idx<CrateData>;
102101
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
103102
pub struct CrateName(SmolStr);
104103

105-
impl Serialize for CrateName {
106-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
107-
where
108-
S: serde::Serializer,
109-
{
110-
serializer.serialize_str(self)
111-
}
112-
}
113-
114104
impl CrateName {
115105
/// Creates a crate name, checking for dashes in the string provided.
116106
/// 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
@@ -63,6 +63,13 @@ mod patch_old_style;
6363
// To deprecate an option by replacing it with another name use `new_name | `old_name` so that we keep
6464
// parsing the old name.
6565
config_data! {
66+
/// Configs that apply on a workspace-wide scope. There are 3 levels on which a global configuration can be configured
67+
///
68+
/// 1. `rust-analyzer.toml` file under user's config directory (e.g ~/.config/rust-analyzer.toml)
69+
/// 2. Client's own configurations (e.g `settings.json` on VS Code)
70+
/// 3. `rust-analyzer.toml` file located at the workspace root
71+
///
72+
/// A config is searched for by traversing a "config tree" in a bottom up fashion. It is chosen by the nearest first principle.
6673
global: struct GlobalConfigData <- GlobalConfigInput -> {
6774
/// Whether to insert #[must_use] when generating `as_` methods
6875
/// 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,45 +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 associated items of a trait to display when hovering a trait.
507-
hover_show_traitAssocItems: Option<usize> = Option::<usize>::None,
508-
509514
/// 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.
510515
imports_granularity_enforce: bool = false,
511516
/// How imports should be grouped into use statements.
@@ -621,6 +626,8 @@ config_data! {
621626
}
622627

623628
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).
624631
client: struct ClientConfigData <- ClientConfigInput -> {}
625632
}
626633

@@ -637,8 +644,8 @@ pub struct Config {
637644

638645
default_config: ConfigData,
639646
client_config: ConfigInput,
640-
xdg_config: ConfigInput,
641-
ratoml_arena: FxHashMap<SourceRootId, RatomlNode>,
647+
user_config: ConfigInput,
648+
ratoml_files: FxHashMap<SourceRootId, RatomlNode>,
642649
}
643650

644651
#[derive(Clone, Debug)]
@@ -871,8 +878,8 @@ impl Config {
871878
workspace_roots,
872879
visual_studio_code_version,
873880
client_config: ConfigInput::default(),
874-
xdg_config: ConfigInput::default(),
875-
ratoml_arena: FxHashMap::default(),
881+
user_config: ConfigInput::default(),
882+
ratoml_files: FxHashMap::default(),
876883
default_config: ConfigData::default(),
877884
}
878885
}
@@ -909,9 +916,8 @@ impl Config {
909916
.map(AbsPathBuf::assert)
910917
.collect();
911918
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);
919+
self.client_config = ConfigInput::from_json(json, &mut errors);
920+
tracing::debug!(?self.client_config, "deserialized config data");
915921
self.snippets.clear();
916922

917923
let snips = self.completion_snippets_custom(None).to_owned();
@@ -1056,36 +1062,32 @@ impl Config {
10561062
}
10571063
}
10581064

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();
1065+
pub fn hover_actions(&self) -> HoverActionsConfig {
1066+
let enable = self.experimental("hoverActions") && self.hover_actions_enable().to_owned();
10621067
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(),
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(),
10691073
}
10701074
}
10711075

1072-
pub fn hover(&self, source_root: Option<SourceRootId>) -> HoverConfig {
1076+
pub fn hover(&self) -> HoverConfig {
10731077
let mem_kind = |kind| match kind {
10741078
MemoryLayoutHoverRenderKindDef::Both => MemoryLayoutHoverRenderKind::Both,
10751079
MemoryLayoutHoverRenderKindDef::Decimal => MemoryLayoutHoverRenderKind::Decimal,
10761080
MemoryLayoutHoverRenderKindDef::Hexadecimal => MemoryLayoutHoverRenderKind::Hexadecimal,
10771081
};
10781082
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(),
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(),
10891091
format: {
10901092
let is_markdown = try_or_def!(self
10911093
.caps
@@ -1103,8 +1105,8 @@ impl Config {
11031105
HoverDocFormat::PlainText
11041106
}
11051107
},
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(),
1108+
keywords: self.hover_documentation_keywords_enable().to_owned(),
1109+
max_trait_assoc_items_count: self.hover_show_traitAssocItems().to_owned(),
11081110
}
11091111
}
11101112

@@ -2206,7 +2208,7 @@ pub(crate) enum WorkspaceSymbolSearchKindDef {
22062208
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq)]
22072209
#[serde(rename_all = "snake_case")]
22082210
#[serde(untagged)]
2209-
enum MemoryLayoutHoverRenderKindDef {
2211+
pub(crate) enum MemoryLayoutHoverRenderKindDef {
22102212
#[serde(with = "unit_v::decimal")]
22112213
Decimal,
22122214
#[serde(with = "unit_v::hexadecimal")]
@@ -2270,7 +2272,7 @@ macro_rules! _impl_for_config_data {
22702272
return &v;
22712273
}
22722274

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

@@ -2293,7 +2295,7 @@ macro_rules! _impl_for_config_data {
22932295
return &v;
22942296
}
22952297

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

@@ -2325,7 +2327,7 @@ macro_rules! _impl_for_config_data {
23252327

23262328
macro_rules! _config_data {
23272329
// modname is for the tests
2328-
($modname:ident: struct $name:ident <- $input:ident -> {
2330+
($(#[doc=$dox:literal])* $modname:ident: struct $name:ident <- $input:ident -> {
23292331
$(
23302332
$(#[doc=$doc:literal])*
23312333
$field:ident $(| $alias:ident)*: $ty:ty = $(@$marker:ident: )? $default:expr,
@@ -2392,7 +2394,7 @@ macro_rules! _config_data {
23922394
}
23932395

23942396
impl $input {
2395-
#[allow(unused)]
2397+
#[allow(unused, clippy::ptr_arg)]
23962398
fn from_json(json: &mut serde_json::Value, error_sink: &mut Vec<(String, serde_json::Error)>) -> Self {
23972399
Self {$(
23982400
$field: get_field(
@@ -2404,7 +2406,7 @@ macro_rules! _config_data {
24042406
)*}
24052407
}
24062408

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

0 commit comments

Comments
 (0)