mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Add config for disabling hover memory layout data
This commit is contained in:
parent
ecc081d625
commit
4ed0fa8414
7 changed files with 63 additions and 10 deletions
|
@ -27,6 +27,7 @@ use crate::{
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct HoverConfig {
|
pub struct HoverConfig {
|
||||||
pub links_in_hover: bool,
|
pub links_in_hover: bool,
|
||||||
|
pub memory_layout: bool,
|
||||||
pub documentation: bool,
|
pub documentation: bool,
|
||||||
pub keywords: bool,
|
pub keywords: bool,
|
||||||
pub format: HoverDocFormat,
|
pub format: HoverDocFormat,
|
||||||
|
|
|
@ -415,7 +415,7 @@ pub(super) fn definition(
|
||||||
let mod_path = definition_mod_path(db, &def);
|
let mod_path = definition_mod_path(db, &def);
|
||||||
let (label, docs) = match def {
|
let (label, docs) = match def {
|
||||||
Definition::Macro(it) => label_and_docs(db, it),
|
Definition::Macro(it) => label_and_docs(db, it),
|
||||||
Definition::Field(it) => label_and_layout_info_and_docs(db, it, |&it| {
|
Definition::Field(it) => label_and_layout_info_and_docs(db, it, config, |&it| {
|
||||||
let var_def = it.parent_def(db);
|
let var_def = it.parent_def(db);
|
||||||
let id = it.index();
|
let id = it.index();
|
||||||
let layout = it.layout(db).ok()?;
|
let layout = it.layout(db).ok()?;
|
||||||
|
@ -435,7 +435,7 @@ pub(super) fn definition(
|
||||||
}),
|
}),
|
||||||
Definition::Module(it) => label_and_docs(db, it),
|
Definition::Module(it) => label_and_docs(db, it),
|
||||||
Definition::Function(it) => label_and_docs(db, it),
|
Definition::Function(it) => label_and_docs(db, it),
|
||||||
Definition::Adt(it) => label_and_layout_info_and_docs(db, it, |&it| {
|
Definition::Adt(it) => label_and_layout_info_and_docs(db, it, config, |&it| {
|
||||||
let layout = it.layout(db).ok()?;
|
let layout = it.layout(db).ok()?;
|
||||||
Some(format!("size = {}, align = {}", layout.size.bytes(), layout.align.abi.bytes()))
|
Some(format!("size = {}, align = {}", layout.size.bytes(), layout.align.abi.bytes()))
|
||||||
}),
|
}),
|
||||||
|
@ -473,7 +473,7 @@ pub(super) fn definition(
|
||||||
}),
|
}),
|
||||||
Definition::Trait(it) => label_and_docs(db, it),
|
Definition::Trait(it) => label_and_docs(db, it),
|
||||||
Definition::TraitAlias(it) => label_and_docs(db, it),
|
Definition::TraitAlias(it) => label_and_docs(db, it),
|
||||||
Definition::TypeAlias(it) => label_and_layout_info_and_docs(db, it, |&it| {
|
Definition::TypeAlias(it) => label_and_layout_info_and_docs(db, it, config, |&it| {
|
||||||
let layout = it.ty(db).layout(db).ok()?;
|
let layout = it.ty(db).layout(db).ok()?;
|
||||||
Some(format!("size = {}, align = {}", layout.size.bytes(), layout.align.abi.bytes()))
|
Some(format!("size = {}, align = {}", layout.size.bytes(), layout.align.abi.bytes()))
|
||||||
}),
|
}),
|
||||||
|
@ -577,6 +577,7 @@ where
|
||||||
fn label_and_layout_info_and_docs<D, E, V>(
|
fn label_and_layout_info_and_docs<D, E, V>(
|
||||||
db: &RootDatabase,
|
db: &RootDatabase,
|
||||||
def: D,
|
def: D,
|
||||||
|
config: &HoverConfig,
|
||||||
value_extractor: E,
|
value_extractor: E,
|
||||||
) -> (String, Option<hir::Documentation>)
|
) -> (String, Option<hir::Documentation>)
|
||||||
where
|
where
|
||||||
|
@ -584,10 +585,9 @@ where
|
||||||
E: Fn(&D) -> Option<V>,
|
E: Fn(&D) -> Option<V>,
|
||||||
V: Display,
|
V: Display,
|
||||||
{
|
{
|
||||||
let label = if let Some(value) = value_extractor(&def) {
|
let label = match value_extractor(&def) {
|
||||||
format!("{} // {value}", def.display(db))
|
Some(value) if config.memory_layout => format!("{} // {value}", def.display(db)),
|
||||||
} else {
|
_ => def.display(db).to_string(),
|
||||||
def.display(db).to_string()
|
|
||||||
};
|
};
|
||||||
let docs = def.attrs(db).docs();
|
let docs = def.attrs(db).docs();
|
||||||
(label, docs)
|
(label, docs)
|
||||||
|
|
|
@ -6,6 +6,7 @@ use crate::{fixture, HoverConfig, HoverDocFormat};
|
||||||
|
|
||||||
const HOVER_BASE_CONFIG: HoverConfig = HoverConfig {
|
const HOVER_BASE_CONFIG: HoverConfig = HoverConfig {
|
||||||
links_in_hover: false,
|
links_in_hover: false,
|
||||||
|
memory_layout: true,
|
||||||
documentation: true,
|
documentation: true,
|
||||||
format: HoverDocFormat::Markdown,
|
format: HoverDocFormat::Markdown,
|
||||||
keywords: true,
|
keywords: true,
|
||||||
|
@ -57,6 +58,23 @@ fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
|
||||||
expect.assert_eq(&actual)
|
expect.assert_eq(&actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn check_hover_no_memory_layout(ra_fixture: &str, expect: Expect) {
|
||||||
|
let (analysis, position) = fixture::position(ra_fixture);
|
||||||
|
let hover = analysis
|
||||||
|
.hover(
|
||||||
|
&HoverConfig { memory_layout: false, ..HOVER_BASE_CONFIG },
|
||||||
|
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let content = analysis.db.file_text(position.file_id);
|
||||||
|
let hovered_element = &content[hover.range];
|
||||||
|
|
||||||
|
let actual = format!("*{hovered_element}*\n{}\n", hover.info.markup);
|
||||||
|
expect.assert_eq(&actual)
|
||||||
|
}
|
||||||
|
|
||||||
fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
|
fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
|
||||||
let (analysis, position) = fixture::position(ra_fixture);
|
let (analysis, position) = fixture::position(ra_fixture);
|
||||||
let hover = analysis
|
let hover = analysis
|
||||||
|
@ -1745,6 +1763,26 @@ pub fn fo$0o() {}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_hover_no_memory_layout() {
|
||||||
|
check_hover_no_memory_layout(
|
||||||
|
r#"
|
||||||
|
struct Foo { fiel$0d_a: u8, field_b: i32, field_c: i16 }
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
*field_a*
|
||||||
|
|
||||||
|
```rust
|
||||||
|
test::Foo
|
||||||
|
```
|
||||||
|
|
||||||
|
```rust
|
||||||
|
field_a: u8
|
||||||
|
```
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_hover_macro_generated_struct_fn_doc_comment() {
|
fn test_hover_macro_generated_struct_fn_doc_comment() {
|
||||||
cov_mark::check!(hover_macro_generated_struct_fn_doc_comment);
|
cov_mark::check!(hover_macro_generated_struct_fn_doc_comment);
|
||||||
|
|
|
@ -137,6 +137,7 @@ impl StaticIndex<'_> {
|
||||||
});
|
});
|
||||||
let hover_config = HoverConfig {
|
let hover_config = HoverConfig {
|
||||||
links_in_hover: true,
|
links_in_hover: true,
|
||||||
|
memory_layout: true,
|
||||||
documentation: true,
|
documentation: true,
|
||||||
keywords: true,
|
keywords: true,
|
||||||
format: crate::HoverDocFormat::Markdown,
|
format: crate::HoverDocFormat::Markdown,
|
||||||
|
|
|
@ -313,8 +313,10 @@ config_data! {
|
||||||
/// Whether to show keyword hover popups. Only applies when
|
/// Whether to show keyword hover popups. Only applies when
|
||||||
/// `#rust-analyzer.hover.documentation.enable#` is set.
|
/// `#rust-analyzer.hover.documentation.enable#` is set.
|
||||||
hover_documentation_keywords_enable: bool = "true",
|
hover_documentation_keywords_enable: bool = "true",
|
||||||
/// Use markdown syntax for links in hover.
|
/// Use markdown syntax for links on hover.
|
||||||
hover_links_enable: bool = "true",
|
hover_links_enable: bool = "true",
|
||||||
|
/// Whether to show memory layout data on hover.
|
||||||
|
hover_memory_layout_enable: bool = "true",
|
||||||
|
|
||||||
/// 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.
|
/// 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.
|
||||||
imports_granularity_enforce: bool = "false",
|
imports_granularity_enforce: bool = "false",
|
||||||
|
@ -1472,6 +1474,7 @@ impl Config {
|
||||||
pub fn hover(&self) -> HoverConfig {
|
pub fn hover(&self) -> HoverConfig {
|
||||||
HoverConfig {
|
HoverConfig {
|
||||||
links_in_hover: self.data.hover_links_enable,
|
links_in_hover: self.data.hover_links_enable,
|
||||||
|
memory_layout: self.data.hover_memory_layout_enable,
|
||||||
documentation: self.data.hover_documentation_enable,
|
documentation: self.data.hover_documentation_enable,
|
||||||
format: {
|
format: {
|
||||||
let is_markdown = try_or_def!(self
|
let is_markdown = try_or_def!(self
|
||||||
|
|
|
@ -421,7 +421,12 @@ Whether to show keyword hover popups. Only applies when
|
||||||
[[rust-analyzer.hover.links.enable]]rust-analyzer.hover.links.enable (default: `true`)::
|
[[rust-analyzer.hover.links.enable]]rust-analyzer.hover.links.enable (default: `true`)::
|
||||||
+
|
+
|
||||||
--
|
--
|
||||||
Use markdown syntax for links in hover.
|
Use markdown syntax for links on hover.
|
||||||
|
--
|
||||||
|
[[rust-analyzer.hover.memory.layout.enable]]rust-analyzer.hover.memory.layout.enable (default: `true`)::
|
||||||
|
+
|
||||||
|
--
|
||||||
|
Whether to show memory layout data on hover.
|
||||||
--
|
--
|
||||||
[[rust-analyzer.imports.granularity.enforce]]rust-analyzer.imports.granularity.enforce (default: `false`)::
|
[[rust-analyzer.imports.granularity.enforce]]rust-analyzer.imports.granularity.enforce (default: `false`)::
|
||||||
+
|
+
|
||||||
|
|
|
@ -955,7 +955,12 @@
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
"rust-analyzer.hover.links.enable": {
|
"rust-analyzer.hover.links.enable": {
|
||||||
"markdownDescription": "Use markdown syntax for links in hover.",
|
"markdownDescription": "Use markdown syntax for links on hover.",
|
||||||
|
"default": true,
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"rust-analyzer.hover.memory.layout.enable": {
|
||||||
|
"markdownDescription": "Whether to show memory layout data on hover.",
|
||||||
"default": true,
|
"default": true,
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue