add config item for hover display

This commit is contained in:
Young-Flash 2024-02-18 17:43:22 +08:00
parent 00358b1fe0
commit 35ec5955eb
10 changed files with 34 additions and 7 deletions

View file

@ -62,7 +62,7 @@ pub struct HirFormatter<'a> {
fmt: &'a mut dyn HirWrite,
buf: String,
curr_size: usize,
pub(crate) max_size: Option<usize>,
pub max_size: Option<usize>,
omit_verbose_types: bool,
closure_style: ClosureStyle,
display_target: DisplayTarget,

View file

@ -593,12 +593,14 @@ impl HirDisplay for Trait {
write_generic_params(def_id, f)?;
write_where_clause(def_id, f)?;
let mut display_size = 0;
let max_display_size = f.max_size.unwrap_or(7);
let assoc_items = self.items(f.db);
if assoc_items.is_empty() {
f.write_str(" {}")?;
} else {
f.write_str(" {\n")?;
for item in assoc_items {
for (index, item) in assoc_items.iter().enumerate() {
f.write_str(" ")?;
match item {
AssocItem::Function(func) => {
@ -612,6 +614,11 @@ impl HirDisplay for Trait {
}
};
f.write_str(",\n")?;
display_size += 1;
if display_size == max_display_size && index != assoc_items.len() - 1{
f.write_str(" ...\n")?;
break;
}
}
f.write_str("}")?;
}

View file

@ -213,7 +213,7 @@ impl Definition {
})
}
pub fn label(&self, db: &RootDatabase) -> String {
pub fn label(&self, db: &RootDatabase, max_size: Option<usize>) -> String {
match *self {
Definition::Macro(it) => it.display(db).to_string(),
Definition::Field(it) => it.display(db).to_string(),
@ -224,7 +224,7 @@ impl Definition {
Definition::Variant(it) => it.display(db).to_string(),
Definition::Const(it) => it.display(db).to_string(),
Definition::Static(it) => it.display(db).to_string(),
Definition::Trait(it) => it.display(db).to_string(),
Definition::Trait(it) => it.display_truncated(db, max_size).to_string(),
Definition::TraitAlias(it) => it.display(db).to_string(),
Definition::TypeAlias(it) => it.display(db).to_string(),
Definition::BuiltinType(it) => it.name().display(db).to_string(),

View file

@ -32,6 +32,7 @@ pub struct HoverConfig {
pub documentation: bool,
pub keywords: bool,
pub format: HoverDocFormat,
pub trait_item_display_on_hover: Option<usize>,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]

View file

@ -406,7 +406,7 @@ pub(super) fn definition(
config: &HoverConfig,
) -> Markup {
let mod_path = definition_mod_path(db, &def);
let label = def.label(db);
let label = def.label(db, config.trait_item_display_on_hover);
let docs = def.docs(db, famous_defs);
let value = (|| match def {
Definition::Variant(it) => {

View file

@ -17,6 +17,7 @@ const HOVER_BASE_CONFIG: HoverConfig = HoverConfig {
documentation: true,
format: HoverDocFormat::Markdown,
keywords: true,
trait_item_display_on_hover: Some(7),
};
fn check_hover_no_result(ra_fixture: &str) {

View file

@ -166,6 +166,7 @@ impl StaticIndex<'_> {
documentation: true,
keywords: true,
format: crate::HoverDocFormat::Markdown,
trait_item_display_on_hover: Some(7)
};
let tokens = tokens.filter(|token| {
matches!(
@ -196,7 +197,7 @@ impl StaticIndex<'_> {
enclosing_moniker: current_crate
.zip(def.enclosing_definition(self.db))
.and_then(|(cc, enclosing_def)| def_to_moniker(self.db, enclosing_def, cc)),
signature: Some(def.label(self.db)),
signature: Some(def.label(self.db, hover_config.trait_item_display_on_hover)),
kind: def_to_kind(self.db, def),
});
self.def_map.insert(def, it);

View file

@ -511,7 +511,6 @@ config_data! {
/// Exclude tests from find-all-references.
references_excludeTests: bool = "false",
/// Command to be executed instead of 'cargo' for runnables.
runnables_command: Option<String> = "null",
/// Additional arguments to be passed to cargo for runnables such as
@ -591,6 +590,9 @@ config_data! {
/// Show documentation.
signatureInfo_documentation_enable: bool = "true",
/// How many trait item display on hover.
trait_item_display_on_hover: Option<usize> = "7",
/// Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list.
typing_autoClosingAngleBrackets_enable: bool = "false",
@ -1683,6 +1685,7 @@ impl Config {
}
},
keywords: self.data.hover_documentation_keywords_enable,
trait_item_display_on_hover: self.data.trait_item_display_on_hover,
}
}

View file

@ -927,6 +927,11 @@ Show full signature of the callable. Only shows parameters if disabled.
--
Show documentation.
--
[[rust-analyzer.trait.item.display.on.hover]]rust-analyzer.trait.item.display.on.hover (default: `7`)::
+
--
How many trait item display on hover.
--
[[rust-analyzer.typing.autoClosingAngleBrackets.enable]]rust-analyzer.typing.autoClosingAngleBrackets.enable (default: `false`)::
+
--

View file

@ -1648,6 +1648,15 @@
"default": true,
"type": "boolean"
},
"rust-analyzer.trait.item.display.on.hover": {
"markdownDescription": "How many trait item display on hover.",
"default": 7,
"type": [
"null",
"integer"
],
"minimum": 0
},
"rust-analyzer.typing.autoClosingAngleBrackets.enable": {
"markdownDescription": "Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list.",
"default": false,