Skip to content

Commit fa7f873

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

File tree

6 files changed

+77
-101
lines changed

6 files changed

+77
-101
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: 62 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,41 @@ config_data! {
268268
/// Controls file watching implementation.
269269
files_watcher: FilesWatcherDef = FilesWatcherDef::Client,
270270

271+
/// Whether to show `Debug` action. Only applies when
272+
/// `#rust-analyzer.hover.actions.enable#` is set.
273+
hover_actions_debug_enable: bool = true,
274+
/// Whether to show HoverActions in Rust files.
275+
hover_actions_enable: bool = true,
276+
/// Whether to show `Go to Type Definition` action. Only applies when
277+
/// `#rust-analyzer.hover.actions.enable#` is set.
278+
hover_actions_gotoTypeDef_enable: bool = true,
279+
/// Whether to show `Implementations` action. Only applies when
280+
/// `#rust-analyzer.hover.actions.enable#` is set.
281+
hover_actions_implementations_enable: bool = true,
282+
/// Whether to show `References` action. Only applies when
283+
/// `#rust-analyzer.hover.actions.enable#` is set.
284+
hover_actions_references_enable: bool = false,
285+
/// Whether to show `Run` action. Only applies when
286+
/// `#rust-analyzer.hover.actions.enable#` is set.
287+
hover_actions_run_enable: bool = true,
288+
289+
/// Whether to show documentation on hover.
290+
hover_documentation_enable: bool = true,
291+
/// Whether to show keyword hover popups. Only applies when
292+
/// `#rust-analyzer.hover.documentation.enable#` is set.
293+
hover_documentation_keywords_enable: bool = true,
294+
/// Use markdown syntax for links on hover.
295+
hover_links_enable: bool = true,
296+
/// How to render the align information in a memory layout hover.
297+
hover_memoryLayout_alignment: Option<MemoryLayoutHoverRenderKindDef> = Some(MemoryLayoutHoverRenderKindDef::Hexadecimal),
298+
/// Whether to show memory layout data on hover.
299+
hover_memoryLayout_enable: bool = true,
300+
/// How to render the niche information in a memory layout hover.
301+
hover_memoryLayout_niches: Option<bool> = Some(false),
302+
/// How to render the offset information in a memory layout hover.
303+
hover_memoryLayout_offset: Option<MemoryLayoutHoverRenderKindDef> = Some(MemoryLayoutHoverRenderKindDef::Hexadecimal),
304+
/// How to render the size information in a memory layout hover.
305+
hover_memoryLayout_size: Option<MemoryLayoutHoverRenderKindDef> = Some(MemoryLayoutHoverRenderKindDef::Both),
271306

272307
/// Enables the experimental support for interpreting tests.
273308
interpret_tests: bool = false,
@@ -466,42 +501,6 @@ config_data! {
466501
/// Enables highlighting of all break points for a loop or block context while the cursor is on any `async` or `await` keywords.
467502
highlightRelated_yieldPoints_enable: bool = true,
468503

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-
505504
/// 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.
506505
imports_granularity_enforce: bool = false,
507506
/// How imports should be grouped into use statements.
@@ -633,8 +632,8 @@ pub struct Config {
633632

634633
default_config: ConfigData,
635634
client_config: ConfigInput,
636-
xdg_config: ConfigInput,
637-
ratoml_arena: FxHashMap<SourceRootId, RatomlNode>,
635+
user_config: ConfigInput,
636+
ratoml_files: FxHashMap<SourceRootId, RatomlNode>,
638637
}
639638

640639
#[derive(Clone, Debug)]
@@ -867,8 +866,8 @@ impl Config {
867866
workspace_roots,
868867
is_visual_studio_code,
869868
client_config: ConfigInput::default(),
870-
xdg_config: ConfigInput::default(),
871-
ratoml_arena: FxHashMap::default(),
869+
user_config: ConfigInput::default(),
870+
ratoml_files: FxHashMap::default(),
872871
default_config: ConfigData::default(),
873872
}
874873
}
@@ -905,8 +904,7 @@ impl Config {
905904
.map(AbsPathBuf::assert)
906905
.collect();
907906
patch_old_style::patch_json_for_outdated_configs(&mut json);
908-
let input = ConfigInput::from_json(json, &mut errors);
909-
self.client_config = input;
907+
self.client_config = ConfigInput::from_json(json, &mut errors);
910908
tracing::debug!("deserialized config data: {:#?}", self.client_config);
911909
self.snippets.clear();
912910

@@ -1051,36 +1049,32 @@ impl Config {
10511049
}
10521050
}
10531051

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();
1052+
pub fn hover_actions(&self) -> HoverActionsConfig {
1053+
let enable = self.experimental("hoverActions") && self.hover_actions_enable().to_owned();
10571054
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(),
1055+
implementations: enable && self.hover_actions_implementations_enable().to_owned(),
1056+
references: enable && self.hover_actions_references_enable().to_owned(),
1057+
run: enable && self.hover_actions_run_enable().to_owned(),
1058+
debug: enable && self.hover_actions_debug_enable().to_owned(),
1059+
goto_type_def: enable && self.hover_actions_gotoTypeDef_enable().to_owned(),
10641060
}
10651061
}
10661062

1067-
pub fn hover(&self, source_root: Option<SourceRootId>) -> HoverConfig {
1063+
pub fn hover(&self) -> HoverConfig {
10681064
let mem_kind = |kind| match kind {
10691065
MemoryLayoutHoverRenderKindDef::Both => MemoryLayoutHoverRenderKind::Both,
10701066
MemoryLayoutHoverRenderKindDef::Decimal => MemoryLayoutHoverRenderKind::Decimal,
10711067
MemoryLayoutHoverRenderKindDef::Hexadecimal => MemoryLayoutHoverRenderKind::Hexadecimal,
10721068
};
10731069
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(),
1070+
links_in_hover: self.hover_links_enable().to_owned(),
1071+
memory_layout: self.hover_memoryLayout_enable().then_some(MemoryLayoutHoverConfig {
1072+
size: self.hover_memoryLayout_size().map(mem_kind),
1073+
offset: self.hover_memoryLayout_offset().map(mem_kind),
1074+
alignment: self.hover_memoryLayout_alignment().map(mem_kind),
1075+
niches: self.hover_memoryLayout_niches().unwrap_or_default(),
1076+
}),
1077+
documentation: self.hover_documentation_enable().to_owned(),
10841078
format: {
10851079
let is_markdown = try_or_def!(self
10861080
.caps
@@ -1098,7 +1092,7 @@ impl Config {
10981092
HoverDocFormat::PlainText
10991093
}
11001094
},
1101-
keywords: self.hover_documentation_keywords_enable(source_root).to_owned(),
1095+
keywords: self.hover_documentation_keywords_enable().to_owned(),
11021096
}
11031097
}
11041098

@@ -2196,7 +2190,7 @@ pub(crate) enum WorkspaceSymbolSearchKindDef {
21962190
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq)]
21972191
#[serde(rename_all = "snake_case")]
21982192
#[serde(untagged)]
2199-
enum MemoryLayoutHoverRenderKindDef {
2193+
pub(crate) enum MemoryLayoutHoverRenderKindDef {
22002194
#[serde(with = "unit_v::decimal")]
22012195
Decimal,
22022196
#[serde(with = "unit_v::hexadecimal")]
@@ -2260,7 +2254,7 @@ macro_rules! _impl_for_config_data {
22602254
return &v;
22612255
}
22622256

2263-
if let Some(v) = self.xdg_config.local.$field.as_ref() {
2257+
if let Some(v) = self.user_config.local.$field.as_ref() {
22642258
return &v;
22652259
}
22662260

@@ -2283,7 +2277,7 @@ macro_rules! _impl_for_config_data {
22832277
return &v;
22842278
}
22852279

2286-
if let Some(v) = self.xdg_config.global.$field.as_ref() {
2280+
if let Some(v) = self.user_config.global.$field.as_ref() {
22872281
return &v;
22882282
}
22892283

@@ -2382,7 +2376,7 @@ macro_rules! _config_data {
23822376
}
23832377

23842378
impl $input {
2385-
#[allow(unused)]
2379+
#[allow(unused, clippy::ptr_arg)]
23862380
fn from_json(json: &mut serde_json::Value, error_sink: &mut Vec<(String, serde_json::Error)>) -> Self {
23872381
Self {$(
23882382
$field: get_field(
@@ -2394,7 +2388,7 @@ macro_rules! _config_data {
23942388
)*}
23952389
}
23962390

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

crates/rust-analyzer/src/handlers/request.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -973,9 +973,8 @@ pub(crate) fn handle_hover(
973973
PositionOrRange::Range(range) => range,
974974
};
975975
let file_range = from_proto::file_range(&snap, &params.text_document, range)?;
976-
let source_root = snap.analysis.source_root(file_range.file_id)?;
977976

978-
let hover = snap.config.hover(Some(source_root));
977+
let hover = snap.config.hover();
979978
let info = match snap.analysis.hover(&hover, file_range)? {
980979
None => return Ok(None),
981980
Some(info) => info,
@@ -992,7 +991,7 @@ pub(crate) fn handle_hover(
992991
)),
993992
range: Some(range),
994993
},
995-
actions: if snap.config.hover_actions(Some(source_root)).none() {
994+
actions: if snap.config.hover_actions().none() {
996995
Vec::new()
997996
} else {
998997
prepare_hover_actions(&snap, &info.info.actions)
@@ -1786,11 +1785,7 @@ fn show_impl_command_link(
17861785
snap: &GlobalStateSnapshot,
17871786
position: &FilePosition,
17881787
) -> Option<lsp_ext::CommandLinkGroup> {
1789-
let source_root = snap.analysis.source_root(position.file_id).ok()?;
1790-
1791-
if snap.config.hover_actions(Some(source_root)).implementations
1792-
&& snap.config.client_commands().show_reference
1793-
{
1788+
if snap.config.hover_actions().implementations && snap.config.client_commands().show_reference {
17941789
if let Some(nav_data) = snap.analysis.goto_implementation(*position).unwrap_or(None) {
17951790
let uri = to_proto::url(snap, position.file_id);
17961791
let line_index = snap.file_line_index(position.file_id).ok()?;
@@ -1816,11 +1811,7 @@ fn show_ref_command_link(
18161811
snap: &GlobalStateSnapshot,
18171812
position: &FilePosition,
18181813
) -> Option<lsp_ext::CommandLinkGroup> {
1819-
let source_root = snap.analysis.source_root(position.file_id).ok()?;
1820-
1821-
if snap.config.hover_actions(Some(source_root)).references
1822-
&& snap.config.client_commands().show_reference
1823-
{
1814+
if snap.config.hover_actions().references && snap.config.client_commands().show_reference {
18241815
if let Some(ref_search_res) = snap.analysis.find_all_refs(*position, None).unwrap_or(None) {
18251816
let uri = to_proto::url(snap, position.file_id);
18261817
let line_index = snap.file_line_index(position.file_id).ok()?;
@@ -1850,14 +1841,12 @@ fn runnable_action_links(
18501841
snap: &GlobalStateSnapshot,
18511842
runnable: Runnable,
18521843
) -> Option<lsp_ext::CommandLinkGroup> {
1853-
let cargo_spec = CargoTargetSpec::for_file(snap, runnable.nav.file_id).ok()?;
1854-
let source_root = snap.analysis.source_root(runnable.nav.file_id).ok()?;
1855-
1856-
let hover_actions_config = snap.config.hover_actions(Some(source_root));
1844+
let hover_actions_config = snap.config.hover_actions();
18571845
if !hover_actions_config.runnable() {
18581846
return None;
18591847
}
18601848

1849+
let cargo_spec = CargoTargetSpec::for_file(snap, runnable.nav.file_id).ok()?;
18611850
if should_skip_target(&runnable, cargo_spec.as_ref()) {
18621851
return None;
18631852
}
@@ -1889,11 +1878,8 @@ fn goto_type_action_links(
18891878
snap: &GlobalStateSnapshot,
18901879
nav_targets: &[HoverGotoTypeData],
18911880
) -> Option<lsp_ext::CommandLinkGroup> {
1892-
// FIXME @alibektas : Is it justified/logical to base this function's progress on a single nav target?
1893-
let source_root = snap.analysis.source_root(nav_targets[0].nav.file_id).ok()?;
1894-
18951881
if nav_targets.is_empty()
1896-
|| !snap.config.hover_actions(Some(source_root)).goto_type_def
1882+
|| !snap.config.hover_actions().goto_type_def
18971883
|| !snap.config.client_commands().goto_location
18981884
{
18991885
return None;

0 commit comments

Comments
 (0)