Skip to content

Commit df101f4

Browse files
committed
Apply requested changes
1 parent 9fcf450 commit df101f4

File tree

6 files changed

+94
-111
lines changed

6 files changed

+94
-111
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
@@ -17,7 +17,6 @@ salsa.workspace = true
1717
rustc-hash.workspace = true
1818
triomphe.workspace = true
1919
semver.workspace = true
20-
serde.workspace = true
2120
tracing.workspace = true
2221

2322
# 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 & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use project_model::{
3434
use rustc_hash::{FxHashMap, FxHashSet};
3535
use serde::{de::DeserializeOwned, Deserialize, Serialize};
3636
use stdx::format_to_acc;
37-
use toml;
3837
use vfs::{AbsPath, AbsPathBuf};
3938

4039
use 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.
6564
config_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

395436
config_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

623627
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).
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

23222323
macro_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

Comments
 (0)