diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs index 0e221a2149a..08e0c6e7524 100644 --- a/crates/hir/src/display.rs +++ b/crates/hir/src/display.rs @@ -17,7 +17,10 @@ use hir_ty::{ }; use crate::{ - Adt, AsAssocItem, AssocItem, AssocItemContainer, Const, ConstParam, Enum, ExternCrateDecl, Field, Function, GenericParam, HasCrate, HasVisibility, LifetimeParam, Macro, Module, SelfParam, Static, Struct, Trait, TraitAlias, TupleField, TyBuilder, Type, TypeAlias, TypeOrConstParam, TypeParam, Union, Variant + Adt, AsAssocItem, AssocItem, AssocItemContainer, Const, ConstParam, Enum, ExternCrateDecl, + Field, Function, GenericParam, HasCrate, HasVisibility, LifetimeParam, Macro, Module, + SelfParam, Static, Struct, Trait, TraitAlias, TupleField, TyBuilder, Type, TypeAlias, + TypeOrConstParam, TypeParam, Union, Variant, }; impl HirDisplay for Function { @@ -593,9 +596,9 @@ 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); + let assoc_items_size = assoc_items.len(); + let max_display_size = f.max_size.unwrap_or(assoc_items_size); if assoc_items.is_empty() { f.write_str(" {}")?; } else { @@ -614,8 +617,7 @@ impl HirDisplay for Trait { } }; f.write_str(",\n")?; - display_size += 1; - if display_size == max_display_size && index != assoc_items.len() - 1{ + if index + 1 == max_display_size && index + 1 != assoc_items_size { f.write_str(" ...\n")?; break; } diff --git a/crates/ide-db/src/defs.rs b/crates/ide-db/src/defs.rs index 8de885f4994..35aaf864696 100644 --- a/crates/ide-db/src/defs.rs +++ b/crates/ide-db/src/defs.rs @@ -24,6 +24,12 @@ use crate::documentation::{Documentation, HasDocs}; use crate::famous_defs::FamousDefs; use crate::RootDatabase; +#[derive(Default)] +pub struct HoverDisplayConfig { + pub trait_item_display_num: Option, + // todo: add config for struct & enum +} + // FIXME: a more precise name would probably be `Symbol`? #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)] pub enum Definition { @@ -213,7 +219,7 @@ impl Definition { }) } - pub fn label(&self, db: &RootDatabase, max_size: Option) -> String { + pub fn label(&self, db: &RootDatabase, hover_display_config: HoverDisplayConfig) -> String { match *self { Definition::Macro(it) => it.display(db).to_string(), Definition::Field(it) => it.display(db).to_string(), @@ -224,7 +230,9 @@ 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_truncated(db, max_size).to_string(), + Definition::Trait(it) => { + it.display_truncated(db, hover_display_config.trait_item_display_num).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(), diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 4b3fdaff0b3..64346a59b77 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -32,7 +32,7 @@ pub struct HoverConfig { pub documentation: bool, pub keywords: bool, pub format: HoverDocFormat, - pub trait_item_display_on_hover: Option, + pub trait_item_display_num: Option, } #[derive(Copy, Clone, Debug, PartialEq, Eq)] diff --git a/crates/ide/src/hover/render.rs b/crates/ide/src/hover/render.rs index c955f46bc45..6d7886feec3 100644 --- a/crates/ide/src/hover/render.rs +++ b/crates/ide/src/hover/render.rs @@ -8,7 +8,7 @@ use hir::{ }; use ide_db::{ base_db::SourceDatabase, - defs::Definition, + defs::{Definition, HoverDisplayConfig}, documentation::HasDocs, famous_defs::FamousDefs, generated::lints::{CLIPPY_LINTS, DEFAULT_LINTS, FEATURES}, @@ -406,7 +406,8 @@ pub(super) fn definition( config: &HoverConfig, ) -> Markup { let mod_path = definition_mod_path(db, &def); - let label = def.label(db, config.trait_item_display_on_hover); + let hover_config = HoverDisplayConfig { trait_item_display_num: config.trait_item_display_num }; + let label = def.label(db, hover_config); let docs = def.docs(db, famous_defs); let value = (|| match def { Definition::Variant(it) => { diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs index 2df4ca5810b..e2278fe4b3a 100644 --- a/crates/ide/src/hover/tests.rs +++ b/crates/ide/src/hover/tests.rs @@ -17,7 +17,7 @@ const HOVER_BASE_CONFIG: HoverConfig = HoverConfig { documentation: true, format: HoverDocFormat::Markdown, keywords: true, - trait_item_display_on_hover: Some(7), + trait_item_display_num: Some(7), }; fn check_hover_no_result(ra_fixture: &str) { diff --git a/crates/ide/src/static_index.rs b/crates/ide/src/static_index.rs index 8d5f5e1bf67..8d6e161c1b9 100644 --- a/crates/ide/src/static_index.rs +++ b/crates/ide/src/static_index.rs @@ -4,7 +4,7 @@ use hir::{db::HirDatabase, Crate, HirFileIdExt, Module, Semantics}; use ide_db::{ base_db::{FileId, FileRange, SourceDatabaseExt}, - defs::Definition, + defs::{Definition, HoverDisplayConfig}, documentation::Documentation, famous_defs::FamousDefs, helpers::get_definition, @@ -166,7 +166,7 @@ impl StaticIndex<'_> { documentation: true, keywords: true, format: crate::HoverDocFormat::Markdown, - trait_item_display_on_hover: Some(7) + trait_item_display_num: None, }; let tokens = tokens.filter(|token| { matches!( @@ -197,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, hover_config.trait_item_display_on_hover)), + signature: Some(def.label(self.db, HoverDisplayConfig::default())), kind: def_to_kind(self.db, def), }); self.def_map.insert(def, it); diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 230a0385cdb..40a2077cb18 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -591,7 +591,7 @@ config_data! { signatureInfo_documentation_enable: bool = "true", /// How many trait item display on hover. - trait_item_display_on_hover: Option = "7", + traitItemDisplayNum: Option = "7", /// Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list. typing_autoClosingAngleBrackets_enable: bool = "false", @@ -1685,7 +1685,7 @@ impl Config { } }, keywords: self.data.hover_documentation_keywords_enable, - trait_item_display_on_hover: self.data.trait_item_display_on_hover, + trait_item_display_num: self.data.traitItemDisplayNum, } } diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc index 9f3ab451329..7d005828b8c 100644 --- a/docs/user/generated_config.adoc +++ b/docs/user/generated_config.adoc @@ -927,7 +927,7 @@ 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`):: +[[rust-analyzer.traitItemDisplayNum]]rust-analyzer.traitItemDisplayNum (default: `7`):: + -- How many trait item display on hover. diff --git a/editors/code/package.json b/editors/code/package.json index a4f54ae4f45..b68ab66cdab 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -1648,7 +1648,7 @@ "default": true, "type": "boolean" }, - "rust-analyzer.trait.item.display.on.hover": { + "rust-analyzer.traitItemDisplayNum": { "markdownDescription": "How many trait item display on hover.", "default": 7, "type": [