Skip to content

Commit f582c5b

Browse files
committed
Apply requested changes
1 parent 6d5d76d commit f582c5b

File tree

6 files changed

+91
-104
lines changed

6 files changed

+91
-104
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: 76 additions & 71 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 workspace-wide level. 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 in the reversed order. First found declaration is chosen.
6672
global: struct GlobalConfigData <- GlobalConfigInput -> {
6773
/// Whether to insert #[must_use] when generating `as_` methods
6874
/// for enum variants.
@@ -268,6 +274,41 @@ config_data! {
268274
/// Controls file watching implementation.
269275
files_watcher: FilesWatcherDef = FilesWatcherDef::Client,
270276

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),
271312

272313
/// Enables the experimental support for interpreting tests.
273314
interpret_tests: bool = false,
@@ -392,6 +433,9 @@ config_data! {
392433
}
393434

394435
config_data! {
436+
/// Local configurations can be overridden for every crate by placing a `rust-analyzer.toml` on crate root.
437+
/// Starting from the nearest `SourceRoot` (i.e the crate itself for which a configuration is called.) a tree of configuration files is traversed and
438+
/// first occurrence is used.
395439
local: struct LocalConfigData <- LocalConfigInput -> {
396440
/// Toggles the additional completions that automatically add imports when completed.
397441
/// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
@@ -466,42 +510,6 @@ config_data! {
466510
/// Enables highlighting of all break points for a loop or block context while the cursor is on any `async` or `await` keywords.
467511
highlightRelated_yieldPoints_enable: bool = true,
468512

469-
/// Whether to show `Debug` action. Only applies when
470-
/// `#rust-analyzer.hover.actions.enable#` is set.
471-
hover_actions_debug_enable: bool = true,
472-
/// Whether to show HoverActions in Rust files.
473-
hover_actions_enable: bool = true,
474-
/// Whether to show `Go to Type Definition` action. Only applies when
475-
/// `#rust-analyzer.hover.actions.enable#` is set.
476-
hover_actions_gotoTypeDef_enable: bool = true,
477-
/// Whether to show `Implementations` action. Only applies when
478-
/// `#rust-analyzer.hover.actions.enable#` is set.
479-
hover_actions_implementations_enable: bool = true,
480-
/// Whether to show `References` action. Only applies when
481-
/// `#rust-analyzer.hover.actions.enable#` is set.
482-
hover_actions_references_enable: bool = false,
483-
/// Whether to show `Run` action. Only applies when
484-
/// `#rust-analyzer.hover.actions.enable#` is set.
485-
hover_actions_run_enable: bool = true,
486-
487-
/// Whether to show documentation on hover.
488-
hover_documentation_enable: bool = true,
489-
/// Whether to show keyword hover popups. Only applies when
490-
/// `#rust-analyzer.hover.documentation.enable#` is set.
491-
hover_documentation_keywords_enable: bool = true,
492-
/// Use markdown syntax for links on hover.
493-
hover_links_enable: bool = true,
494-
/// How to render the align information in a memory layout hover.
495-
hover_memoryLayout_alignment: Option<MemoryLayoutHoverRenderKindDef> = Some(MemoryLayoutHoverRenderKindDef::Hexadecimal),
496-
/// Whether to show memory layout data on hover.
497-
hover_memoryLayout_enable: bool = true,
498-
/// How to render the niche information in a memory layout hover.
499-
hover_memoryLayout_niches: Option<bool> = Some(false),
500-
/// How to render the offset information in a memory layout hover.
501-
hover_memoryLayout_offset: Option<MemoryLayoutHoverRenderKindDef> = Some(MemoryLayoutHoverRenderKindDef::Hexadecimal),
502-
/// How to render the size information in a memory layout hover.
503-
hover_memoryLayout_size: Option<MemoryLayoutHoverRenderKindDef> = Some(MemoryLayoutHoverRenderKindDef::Both),
504-
505513
/// 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.
506514
imports_granularity_enforce: bool = false,
507515
/// How imports should be grouped into use statements.
@@ -617,6 +625,8 @@ config_data! {
617625
}
618626

619627
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).
620630
client: struct ClientConfigData <- ClientConfigInput -> {}
621631
}
622632

@@ -633,8 +643,8 @@ pub struct Config {
633643

634644
default_config: ConfigData,
635645
client_config: ConfigInput,
636-
xdg_config: ConfigInput,
637-
ratoml_arena: FxHashMap<SourceRootId, RatomlNode>,
646+
user_config: ConfigInput,
647+
ratoml_files: FxHashMap<SourceRootId, RatomlNode>,
638648
}
639649

640650
#[derive(Clone, Debug)]
@@ -867,8 +877,8 @@ impl Config {
867877
workspace_roots,
868878
is_visual_studio_code,
869879
client_config: ConfigInput::default(),
870-
xdg_config: ConfigInput::default(),
871-
ratoml_arena: FxHashMap::default(),
880+
user_config: ConfigInput::default(),
881+
ratoml_files: FxHashMap::default(),
872882
default_config: ConfigData::default(),
873883
}
874884
}
@@ -905,9 +915,8 @@ impl Config {
905915
.map(AbsPathBuf::assert)
906916
.collect();
907917
patch_old_style::patch_json_for_outdated_configs(&mut json);
908-
let input = ConfigInput::from_json(json, &mut errors);
909-
self.client_config = input;
910-
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");
911920
self.snippets.clear();
912921

913922
let snips = self.completion_snippets_custom(None).to_owned();
@@ -1051,36 +1060,32 @@ impl Config {
10511060
}
10521061
}
10531062

1054-
pub fn hover_actions(&self, source_root: Option<SourceRootId>) -> HoverActionsConfig {
1055-
let enable =
1056-
self.experimental("hoverActions") && self.hover_actions_enable(source_root).to_owned();
1063+
pub fn hover_actions(&self) -> HoverActionsConfig {
1064+
let enable = self.experimental("hoverActions") && self.hover_actions_enable().to_owned();
10571065
HoverActionsConfig {
1058-
implementations: enable
1059-
&& self.hover_actions_implementations_enable(source_root).to_owned(),
1060-
references: enable && self.hover_actions_references_enable(source_root).to_owned(),
1061-
run: enable && self.hover_actions_run_enable(source_root).to_owned(),
1062-
debug: enable && self.hover_actions_debug_enable(source_root).to_owned(),
1063-
goto_type_def: enable && self.hover_actions_gotoTypeDef_enable(source_root).to_owned(),
1066+
implementations: enable && self.hover_actions_implementations_enable().to_owned(),
1067+
references: enable && self.hover_actions_references_enable().to_owned(),
1068+
run: enable && self.hover_actions_run_enable().to_owned(),
1069+
debug: enable && self.hover_actions_debug_enable().to_owned(),
1070+
goto_type_def: enable && self.hover_actions_gotoTypeDef_enable().to_owned(),
10641071
}
10651072
}
10661073

1067-
pub fn hover(&self, source_root: Option<SourceRootId>) -> HoverConfig {
1074+
pub fn hover(&self) -> HoverConfig {
10681075
let mem_kind = |kind| match kind {
10691076
MemoryLayoutHoverRenderKindDef::Both => MemoryLayoutHoverRenderKind::Both,
10701077
MemoryLayoutHoverRenderKindDef::Decimal => MemoryLayoutHoverRenderKind::Decimal,
10711078
MemoryLayoutHoverRenderKindDef::Hexadecimal => MemoryLayoutHoverRenderKind::Hexadecimal,
10721079
};
10731080
HoverConfig {
1074-
links_in_hover: self.hover_links_enable(source_root).to_owned(),
1075-
memory_layout: self.hover_memoryLayout_enable(source_root).then_some(
1076-
MemoryLayoutHoverConfig {
1077-
size: self.hover_memoryLayout_size(source_root).map(mem_kind),
1078-
offset: self.hover_memoryLayout_offset(source_root).map(mem_kind),
1079-
alignment: self.hover_memoryLayout_alignment(source_root).map(mem_kind),
1080-
niches: self.hover_memoryLayout_niches(source_root).unwrap_or_default(),
1081-
},
1082-
),
1083-
documentation: self.hover_documentation_enable(source_root).to_owned(),
1081+
links_in_hover: self.hover_links_enable().to_owned(),
1082+
memory_layout: self.hover_memoryLayout_enable().then_some(MemoryLayoutHoverConfig {
1083+
size: self.hover_memoryLayout_size().map(mem_kind),
1084+
offset: self.hover_memoryLayout_offset().map(mem_kind),
1085+
alignment: self.hover_memoryLayout_alignment().map(mem_kind),
1086+
niches: self.hover_memoryLayout_niches().unwrap_or_default(),
1087+
}),
1088+
documentation: self.hover_documentation_enable().to_owned(),
10841089
format: {
10851090
let is_markdown = try_or_def!(self
10861091
.caps
@@ -1098,7 +1103,7 @@ impl Config {
10981103
HoverDocFormat::PlainText
10991104
}
11001105
},
1101-
keywords: self.hover_documentation_keywords_enable(source_root).to_owned(),
1106+
keywords: self.hover_documentation_keywords_enable().to_owned(),
11021107
}
11031108
}
11041109

@@ -2196,7 +2201,7 @@ pub(crate) enum WorkspaceSymbolSearchKindDef {
21962201
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq)]
21972202
#[serde(rename_all = "snake_case")]
21982203
#[serde(untagged)]
2199-
enum MemoryLayoutHoverRenderKindDef {
2204+
pub(crate) enum MemoryLayoutHoverRenderKindDef {
22002205
#[serde(with = "unit_v::decimal")]
22012206
Decimal,
22022207
#[serde(with = "unit_v::hexadecimal")]
@@ -2260,7 +2265,7 @@ macro_rules! _impl_for_config_data {
22602265
return &v;
22612266
}
22622267

2263-
if let Some(v) = self.xdg_config.local.$field.as_ref() {
2268+
if let Some(v) = self.user_config.local.$field.as_ref() {
22642269
return &v;
22652270
}
22662271

@@ -2283,7 +2288,7 @@ macro_rules! _impl_for_config_data {
22832288
return &v;
22842289
}
22852290

2286-
if let Some(v) = self.xdg_config.global.$field.as_ref() {
2291+
if let Some(v) = self.user_config.global.$field.as_ref() {
22872292
return &v;
22882293
}
22892294

@@ -2315,7 +2320,7 @@ macro_rules! _impl_for_config_data {
23152320

23162321
macro_rules! _config_data {
23172322
// modname is for the tests
2318-
($modname:ident: struct $name:ident <- $input:ident -> {
2323+
($(#[doc=$dox:literal])* $modname:ident: struct $name:ident <- $input:ident -> {
23192324
$(
23202325
$(#[doc=$doc:literal])*
23212326
$field:ident $(| $alias:ident)*: $ty:ty = $(@$marker:ident: )? $default:expr,
@@ -2382,7 +2387,7 @@ macro_rules! _config_data {
23822387
}
23832388

23842389
impl $input {
2385-
#[allow(unused)]
2390+
#[allow(unused, clippy::ptr_arg)]
23862391
fn from_json(json: &mut serde_json::Value, error_sink: &mut Vec<(String, serde_json::Error)>) -> Self {
23872392
Self {$(
23882393
$field: get_field(
@@ -2394,7 +2399,7 @@ macro_rules! _config_data {
23942399
)*}
23952400
}
23962401

2397-
#[allow(unused)]
2402+
#[allow(unused, clippy::ptr_arg)]
23982403
fn from_toml(toml: &mut toml::Table , error_sink: &mut Vec<(String, toml::de::Error)>) -> Self {
23992404
Self {$(
24002405
$field: get_field_toml::<$ty>(

0 commit comments

Comments
 (0)