mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-27 20:35:09 +00:00
update for review
This commit is contained in:
parent
2e87f31fe9
commit
dba67b46a1
10 changed files with 65 additions and 39 deletions
|
@ -62,7 +62,8 @@ pub struct HirFormatter<'a> {
|
||||||
fmt: &'a mut dyn HirWrite,
|
fmt: &'a mut dyn HirWrite,
|
||||||
buf: String,
|
buf: String,
|
||||||
curr_size: usize,
|
curr_size: usize,
|
||||||
pub max_size: Option<usize>,
|
pub(crate) max_size: Option<usize>,
|
||||||
|
pub limited_size: Option<usize>,
|
||||||
omit_verbose_types: bool,
|
omit_verbose_types: bool,
|
||||||
closure_style: ClosureStyle,
|
closure_style: ClosureStyle,
|
||||||
display_target: DisplayTarget,
|
display_target: DisplayTarget,
|
||||||
|
@ -86,6 +87,7 @@ pub trait HirDisplay {
|
||||||
&'a self,
|
&'a self,
|
||||||
db: &'a dyn HirDatabase,
|
db: &'a dyn HirDatabase,
|
||||||
max_size: Option<usize>,
|
max_size: Option<usize>,
|
||||||
|
limited_size: Option<usize>,
|
||||||
omit_verbose_types: bool,
|
omit_verbose_types: bool,
|
||||||
display_target: DisplayTarget,
|
display_target: DisplayTarget,
|
||||||
closure_style: ClosureStyle,
|
closure_style: ClosureStyle,
|
||||||
|
@ -101,6 +103,7 @@ pub trait HirDisplay {
|
||||||
db,
|
db,
|
||||||
t: self,
|
t: self,
|
||||||
max_size,
|
max_size,
|
||||||
|
limited_size,
|
||||||
omit_verbose_types,
|
omit_verbose_types,
|
||||||
display_target,
|
display_target,
|
||||||
closure_style,
|
closure_style,
|
||||||
|
@ -117,6 +120,7 @@ pub trait HirDisplay {
|
||||||
db,
|
db,
|
||||||
t: self,
|
t: self,
|
||||||
max_size: None,
|
max_size: None,
|
||||||
|
limited_size: None,
|
||||||
omit_verbose_types: false,
|
omit_verbose_types: false,
|
||||||
closure_style: ClosureStyle::ImplFn,
|
closure_style: ClosureStyle::ImplFn,
|
||||||
display_target: DisplayTarget::Diagnostics,
|
display_target: DisplayTarget::Diagnostics,
|
||||||
|
@ -137,6 +141,28 @@ pub trait HirDisplay {
|
||||||
db,
|
db,
|
||||||
t: self,
|
t: self,
|
||||||
max_size,
|
max_size,
|
||||||
|
limited_size: None,
|
||||||
|
omit_verbose_types: true,
|
||||||
|
closure_style: ClosureStyle::ImplFn,
|
||||||
|
display_target: DisplayTarget::Diagnostics,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a `Display`able type that is human-readable and tries to limit the item inside this type.
|
||||||
|
/// Use this for showing types which may contain two many item when user hover on, like `trait`, `struct`, `enum`
|
||||||
|
fn display_limited<'a>(
|
||||||
|
&'a self,
|
||||||
|
db: &'a dyn HirDatabase,
|
||||||
|
limited_size: Option<usize>,
|
||||||
|
) -> HirDisplayWrapper<'a, Self>
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
|
HirDisplayWrapper {
|
||||||
|
db,
|
||||||
|
t: self,
|
||||||
|
max_size: None,
|
||||||
|
limited_size,
|
||||||
omit_verbose_types: true,
|
omit_verbose_types: true,
|
||||||
closure_style: ClosureStyle::ImplFn,
|
closure_style: ClosureStyle::ImplFn,
|
||||||
display_target: DisplayTarget::Diagnostics,
|
display_target: DisplayTarget::Diagnostics,
|
||||||
|
@ -158,6 +184,7 @@ pub trait HirDisplay {
|
||||||
buf: String::with_capacity(20),
|
buf: String::with_capacity(20),
|
||||||
curr_size: 0,
|
curr_size: 0,
|
||||||
max_size: None,
|
max_size: None,
|
||||||
|
limited_size: None,
|
||||||
omit_verbose_types: false,
|
omit_verbose_types: false,
|
||||||
closure_style: ClosureStyle::ImplFn,
|
closure_style: ClosureStyle::ImplFn,
|
||||||
display_target: DisplayTarget::SourceCode { module_id, allow_opaque },
|
display_target: DisplayTarget::SourceCode { module_id, allow_opaque },
|
||||||
|
@ -178,6 +205,7 @@ pub trait HirDisplay {
|
||||||
db,
|
db,
|
||||||
t: self,
|
t: self,
|
||||||
max_size: None,
|
max_size: None,
|
||||||
|
limited_size: None,
|
||||||
omit_verbose_types: false,
|
omit_verbose_types: false,
|
||||||
closure_style: ClosureStyle::ImplFn,
|
closure_style: ClosureStyle::ImplFn,
|
||||||
display_target: DisplayTarget::Test,
|
display_target: DisplayTarget::Test,
|
||||||
|
@ -295,6 +323,7 @@ pub struct HirDisplayWrapper<'a, T> {
|
||||||
db: &'a dyn HirDatabase,
|
db: &'a dyn HirDatabase,
|
||||||
t: &'a T,
|
t: &'a T,
|
||||||
max_size: Option<usize>,
|
max_size: Option<usize>,
|
||||||
|
limited_size: Option<usize>,
|
||||||
omit_verbose_types: bool,
|
omit_verbose_types: bool,
|
||||||
closure_style: ClosureStyle,
|
closure_style: ClosureStyle,
|
||||||
display_target: DisplayTarget,
|
display_target: DisplayTarget,
|
||||||
|
@ -323,6 +352,7 @@ impl<T: HirDisplay> HirDisplayWrapper<'_, T> {
|
||||||
buf: String::with_capacity(20),
|
buf: String::with_capacity(20),
|
||||||
curr_size: 0,
|
curr_size: 0,
|
||||||
max_size: self.max_size,
|
max_size: self.max_size,
|
||||||
|
limited_size: self.limited_size,
|
||||||
omit_verbose_types: self.omit_verbose_types,
|
omit_verbose_types: self.omit_verbose_types,
|
||||||
display_target: self.display_target,
|
display_target: self.display_target,
|
||||||
closure_style: self.closure_style,
|
closure_style: self.closure_style,
|
||||||
|
|
|
@ -598,7 +598,7 @@ impl HirDisplay for Trait {
|
||||||
|
|
||||||
let assoc_items = self.items(f.db);
|
let assoc_items = self.items(f.db);
|
||||||
let assoc_items_size = assoc_items.len();
|
let assoc_items_size = assoc_items.len();
|
||||||
let max_display_size = f.max_size.unwrap_or(assoc_items_size);
|
let limited_size = f.limited_size.unwrap_or(assoc_items_size);
|
||||||
if assoc_items.is_empty() {
|
if assoc_items.is_empty() {
|
||||||
f.write_str(" {}")?;
|
f.write_str(" {}")?;
|
||||||
} else {
|
} else {
|
||||||
|
@ -617,7 +617,7 @@ impl HirDisplay for Trait {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
f.write_str(",\n")?;
|
f.write_str(",\n")?;
|
||||||
if index + 1 == max_display_size && index + 1 != assoc_items_size {
|
if index + 1 == limited_size && index + 1 != assoc_items_size {
|
||||||
f.write_str(" ...\n")?;
|
f.write_str(" ...\n")?;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,12 +24,6 @@ use crate::documentation::{Documentation, HasDocs};
|
||||||
use crate::famous_defs::FamousDefs;
|
use crate::famous_defs::FamousDefs;
|
||||||
use crate::RootDatabase;
|
use crate::RootDatabase;
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct HoverDisplayConfig {
|
|
||||||
pub trait_item_display_num: Option<usize>,
|
|
||||||
// todo: add config for struct & enum
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: a more precise name would probably be `Symbol`?
|
// FIXME: a more precise name would probably be `Symbol`?
|
||||||
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
|
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
|
||||||
pub enum Definition {
|
pub enum Definition {
|
||||||
|
@ -219,7 +213,7 @@ impl Definition {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn label(&self, db: &RootDatabase, hover_display_config: HoverDisplayConfig) -> String {
|
pub fn label(&self, db: &RootDatabase) -> String {
|
||||||
match *self {
|
match *self {
|
||||||
Definition::Macro(it) => it.display(db).to_string(),
|
Definition::Macro(it) => it.display(db).to_string(),
|
||||||
Definition::Field(it) => it.display(db).to_string(),
|
Definition::Field(it) => it.display(db).to_string(),
|
||||||
|
@ -230,9 +224,7 @@ impl Definition {
|
||||||
Definition::Variant(it) => it.display(db).to_string(),
|
Definition::Variant(it) => it.display(db).to_string(),
|
||||||
Definition::Const(it) => it.display(db).to_string(),
|
Definition::Const(it) => it.display(db).to_string(),
|
||||||
Definition::Static(it) => it.display(db).to_string(),
|
Definition::Static(it) => it.display(db).to_string(),
|
||||||
Definition::Trait(it) => {
|
Definition::Trait(it) => it.display(db).to_string(),
|
||||||
it.display_truncated(db, hover_display_config.trait_item_display_num).to_string()
|
|
||||||
}
|
|
||||||
Definition::TraitAlias(it) => it.display(db).to_string(),
|
Definition::TraitAlias(it) => it.display(db).to_string(),
|
||||||
Definition::TypeAlias(it) => it.display(db).to_string(),
|
Definition::TypeAlias(it) => it.display(db).to_string(),
|
||||||
Definition::BuiltinType(it) => it.name().display(db).to_string(),
|
Definition::BuiltinType(it) => it.name().display(db).to_string(),
|
||||||
|
|
|
@ -32,7 +32,7 @@ pub struct HoverConfig {
|
||||||
pub documentation: bool,
|
pub documentation: bool,
|
||||||
pub keywords: bool,
|
pub keywords: bool,
|
||||||
pub format: HoverDocFormat,
|
pub format: HoverDocFormat,
|
||||||
pub trait_item_display_num: Option<usize>,
|
pub trait_assoc_items_size: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
|
|
|
@ -8,7 +8,7 @@ use hir::{
|
||||||
};
|
};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
base_db::SourceDatabase,
|
base_db::SourceDatabase,
|
||||||
defs::{Definition, HoverDisplayConfig},
|
defs::Definition,
|
||||||
documentation::HasDocs,
|
documentation::HasDocs,
|
||||||
famous_defs::FamousDefs,
|
famous_defs::FamousDefs,
|
||||||
generated::lints::{CLIPPY_LINTS, DEFAULT_LINTS, FEATURES},
|
generated::lints::{CLIPPY_LINTS, DEFAULT_LINTS, FEATURES},
|
||||||
|
@ -406,8 +406,12 @@ pub(super) fn definition(
|
||||||
config: &HoverConfig,
|
config: &HoverConfig,
|
||||||
) -> Markup {
|
) -> Markup {
|
||||||
let mod_path = definition_mod_path(db, &def);
|
let mod_path = definition_mod_path(db, &def);
|
||||||
let hover_config = HoverDisplayConfig { trait_item_display_num: config.trait_item_display_num };
|
let label = match def {
|
||||||
let label = def.label(db, hover_config);
|
Definition::Trait(trait_) => {
|
||||||
|
trait_.display_limited(db, config.trait_assoc_items_size).to_string()
|
||||||
|
}
|
||||||
|
_ => def.label(db),
|
||||||
|
};
|
||||||
let docs = def.docs(db, famous_defs);
|
let docs = def.docs(db, famous_defs);
|
||||||
let value = (|| match def {
|
let value = (|| match def {
|
||||||
Definition::Variant(it) => {
|
Definition::Variant(it) => {
|
||||||
|
|
|
@ -17,7 +17,7 @@ const HOVER_BASE_CONFIG: HoverConfig = HoverConfig {
|
||||||
documentation: true,
|
documentation: true,
|
||||||
format: HoverDocFormat::Markdown,
|
format: HoverDocFormat::Markdown,
|
||||||
keywords: true,
|
keywords: true,
|
||||||
trait_item_display_num: Some(7),
|
trait_assoc_items_size: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn check_hover_no_result(ra_fixture: &str) {
|
fn check_hover_no_result(ra_fixture: &str) {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
use hir::{db::HirDatabase, Crate, HirFileIdExt, Module, Semantics};
|
use hir::{db::HirDatabase, Crate, HirFileIdExt, Module, Semantics};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
base_db::{FileId, FileRange, SourceDatabaseExt},
|
base_db::{FileId, FileRange, SourceDatabaseExt},
|
||||||
defs::{Definition, HoverDisplayConfig},
|
defs::Definition,
|
||||||
documentation::Documentation,
|
documentation::Documentation,
|
||||||
famous_defs::FamousDefs,
|
famous_defs::FamousDefs,
|
||||||
helpers::get_definition,
|
helpers::get_definition,
|
||||||
|
@ -166,7 +166,7 @@ impl StaticIndex<'_> {
|
||||||
documentation: true,
|
documentation: true,
|
||||||
keywords: true,
|
keywords: true,
|
||||||
format: crate::HoverDocFormat::Markdown,
|
format: crate::HoverDocFormat::Markdown,
|
||||||
trait_item_display_num: None,
|
trait_assoc_items_size: None,
|
||||||
};
|
};
|
||||||
let tokens = tokens.filter(|token| {
|
let tokens = tokens.filter(|token| {
|
||||||
matches!(
|
matches!(
|
||||||
|
@ -197,7 +197,7 @@ impl StaticIndex<'_> {
|
||||||
enclosing_moniker: current_crate
|
enclosing_moniker: current_crate
|
||||||
.zip(def.enclosing_definition(self.db))
|
.zip(def.enclosing_definition(self.db))
|
||||||
.and_then(|(cc, enclosing_def)| def_to_moniker(self.db, enclosing_def, cc)),
|
.and_then(|(cc, enclosing_def)| def_to_moniker(self.db, enclosing_def, cc)),
|
||||||
signature: Some(def.label(self.db, HoverDisplayConfig::default())),
|
signature: Some(def.label(self.db)),
|
||||||
kind: def_to_kind(self.db, def),
|
kind: def_to_kind(self.db, def),
|
||||||
});
|
});
|
||||||
self.def_map.insert(def, it);
|
self.def_map.insert(def, it);
|
||||||
|
|
|
@ -368,6 +368,9 @@ config_data! {
|
||||||
/// How to render the size information in a memory layout hover.
|
/// How to render the size information in a memory layout hover.
|
||||||
hover_memoryLayout_size: Option<MemoryLayoutHoverRenderKindDef> = "\"both\"",
|
hover_memoryLayout_size: Option<MemoryLayoutHoverRenderKindDef> = "\"both\"",
|
||||||
|
|
||||||
|
/// How many associated items of a trait to display when hovering a trait.
|
||||||
|
hover_show_traitAssocItems: Option<usize> = "null",
|
||||||
|
|
||||||
/// 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",
|
||||||
/// How imports should be grouped into use statements.
|
/// How imports should be grouped into use statements.
|
||||||
|
@ -590,9 +593,6 @@ config_data! {
|
||||||
/// Show documentation.
|
/// Show documentation.
|
||||||
signatureInfo_documentation_enable: bool = "true",
|
signatureInfo_documentation_enable: bool = "true",
|
||||||
|
|
||||||
/// How many trait item display on hover.
|
|
||||||
traitItemDisplayNum: Option<usize> = "7",
|
|
||||||
|
|
||||||
/// Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list.
|
/// Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list.
|
||||||
typing_autoClosingAngleBrackets_enable: bool = "false",
|
typing_autoClosingAngleBrackets_enable: bool = "false",
|
||||||
|
|
||||||
|
@ -1685,7 +1685,7 @@ impl Config {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
keywords: self.data.hover_documentation_keywords_enable,
|
keywords: self.data.hover_documentation_keywords_enable,
|
||||||
trait_item_display_num: self.data.traitItemDisplayNum,
|
trait_assoc_items_size: self.data.hover_show_traitAssocItems,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -505,6 +505,11 @@ How to render the offset information in a memory layout hover.
|
||||||
--
|
--
|
||||||
How to render the size information in a memory layout hover.
|
How to render the size information in a memory layout hover.
|
||||||
--
|
--
|
||||||
|
[[rust-analyzer.hover.show.traitAssocItems]]rust-analyzer.hover.show.traitAssocItems (default: `null`)::
|
||||||
|
+
|
||||||
|
--
|
||||||
|
How many associated items of a trait to display when hovering a trait.
|
||||||
|
--
|
||||||
[[rust-analyzer.imports.granularity.enforce]]rust-analyzer.imports.granularity.enforce (default: `false`)::
|
[[rust-analyzer.imports.granularity.enforce]]rust-analyzer.imports.granularity.enforce (default: `false`)::
|
||||||
+
|
+
|
||||||
--
|
--
|
||||||
|
@ -927,11 +932,6 @@ Show full signature of the callable. Only shows parameters if disabled.
|
||||||
--
|
--
|
||||||
Show documentation.
|
Show documentation.
|
||||||
--
|
--
|
||||||
[[rust-analyzer.traitItemDisplayNum]]rust-analyzer.traitItemDisplayNum (default: `7`)::
|
|
||||||
+
|
|
||||||
--
|
|
||||||
How many trait item display on hover.
|
|
||||||
--
|
|
||||||
[[rust-analyzer.typing.autoClosingAngleBrackets.enable]]rust-analyzer.typing.autoClosingAngleBrackets.enable (default: `false`)::
|
[[rust-analyzer.typing.autoClosingAngleBrackets.enable]]rust-analyzer.typing.autoClosingAngleBrackets.enable (default: `false`)::
|
||||||
+
|
+
|
||||||
--
|
--
|
||||||
|
|
|
@ -1119,6 +1119,15 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"rust-analyzer.hover.show.traitAssocItems": {
|
||||||
|
"markdownDescription": "How many associated items of a trait to display when hovering a trait.",
|
||||||
|
"default": null,
|
||||||
|
"type": [
|
||||||
|
"null",
|
||||||
|
"integer"
|
||||||
|
],
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
"rust-analyzer.imports.granularity.enforce": {
|
"rust-analyzer.imports.granularity.enforce": {
|
||||||
"markdownDescription": "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.",
|
"markdownDescription": "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.",
|
||||||
"default": false,
|
"default": false,
|
||||||
|
@ -1648,15 +1657,6 @@
|
||||||
"default": true,
|
"default": true,
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
"rust-analyzer.traitItemDisplayNum": {
|
|
||||||
"markdownDescription": "How many trait item display on hover.",
|
|
||||||
"default": 7,
|
|
||||||
"type": [
|
|
||||||
"null",
|
|
||||||
"integer"
|
|
||||||
],
|
|
||||||
"minimum": 0
|
|
||||||
},
|
|
||||||
"rust-analyzer.typing.autoClosingAngleBrackets.enable": {
|
"rust-analyzer.typing.autoClosingAngleBrackets.enable": {
|
||||||
"markdownDescription": "Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list.",
|
"markdownDescription": "Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list.",
|
||||||
"default": false,
|
"default": false,
|
||||||
|
|
Loading…
Reference in a new issue