mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-25 22:22:44 +00:00
Add docs to struct fields
This commit is contained in:
parent
55906341a6
commit
7a0bc2dd64
@ -216,6 +216,15 @@ impl StructField {
|
||||
}
|
||||
}
|
||||
|
||||
impl Docs for StructField {
|
||||
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
||||
match self.source(db).1 {
|
||||
FieldSource::Named(named) => docs_from_ast(&*named),
|
||||
FieldSource::Pos(..) => return None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct Struct {
|
||||
pub(crate) id: StructId,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use hir::{Ty, AdtDef};
|
||||
use hir::{Ty, AdtDef, Docs};
|
||||
|
||||
use crate::completion::{CompletionContext, Completions, CompletionItem, CompletionItemKind};
|
||||
use crate::completion::completion_item::CompletionKind;
|
||||
@ -38,6 +38,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty)
|
||||
)
|
||||
.kind(CompletionItemKind::Field)
|
||||
.detail(field.ty(ctx.db).subst(substs).to_string())
|
||||
.set_documentation(field.docs(ctx.db))
|
||||
.add_to(acc);
|
||||
}
|
||||
}
|
||||
@ -107,7 +108,10 @@ mod tests {
|
||||
check_ref_completion(
|
||||
"struct_field_completion_self",
|
||||
r"
|
||||
struct A { the_field: (u32,) }
|
||||
struct A {
|
||||
/// This is the_field
|
||||
the_field: (u32,)
|
||||
}
|
||||
impl A {
|
||||
fn foo(self) {
|
||||
self.<|>
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
created: "2019-01-23T13:19:23.501297515+00:00"
|
||||
created: "2019-01-25T19:27:09.519688600+00:00"
|
||||
creator: insta@0.5.2
|
||||
expression: kind_completions
|
||||
source: crates/ra_ide_api/src/completion/completion_item.rs
|
||||
@ -14,11 +14,15 @@ source: crates/ra_ide_api/src/completion/completion_item.rs
|
||||
detail: Some(
|
||||
"(u32,)"
|
||||
),
|
||||
documentation: None,
|
||||
documentation: Some(
|
||||
Documentation(
|
||||
"This is the_field"
|
||||
)
|
||||
),
|
||||
lookup: None,
|
||||
insert_text: None,
|
||||
insert_text_format: PlainText,
|
||||
source_range: [121; 121),
|
||||
source_range: [187; 187),
|
||||
text_edit: None
|
||||
},
|
||||
CompletionItem {
|
||||
@ -36,7 +40,7 @@ source: crates/ra_ide_api/src/completion/completion_item.rs
|
||||
"foo()$0"
|
||||
),
|
||||
insert_text_format: Snippet,
|
||||
source_range: [121; 121),
|
||||
source_range: [187; 187),
|
||||
text_edit: None
|
||||
}
|
||||
]
|
||||
|
@ -2248,6 +2248,7 @@ impl ToOwned for NamedFieldDef {
|
||||
impl ast::VisibilityOwner for NamedFieldDef {}
|
||||
impl ast::NameOwner for NamedFieldDef {}
|
||||
impl ast::AttrsOwner for NamedFieldDef {}
|
||||
impl ast::DocCommentsOwner for NamedFieldDef {}
|
||||
impl NamedFieldDef {
|
||||
pub fn type_ref(&self) -> Option<&TypeRef> {
|
||||
super::child_opt(self)
|
||||
|
@ -268,7 +268,7 @@ Grammar(
|
||||
]
|
||||
),
|
||||
"NamedFieldDefList": (collections: [["fields", "NamedFieldDef"]]),
|
||||
"NamedFieldDef": ( traits: ["VisibilityOwner", "NameOwner", "AttrsOwner"], options: ["TypeRef"] ),
|
||||
"NamedFieldDef": ( traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner"], options: ["TypeRef"] ),
|
||||
"PosFieldList": (collections: [["fields", "PosField"]]),
|
||||
"PosField": ( traits: ["VisibilityOwner", "AttrsOwner"], options: ["TypeRef"]),
|
||||
"EnumDef": ( traits: [
|
||||
|
@ -250,7 +250,7 @@ fn n_attached_trivias<'a>(
|
||||
) -> usize {
|
||||
match kind {
|
||||
CONST_DEF | TYPE_DEF | STRUCT_DEF | ENUM_DEF | ENUM_VARIANT | FN_DEF | TRAIT_DEF
|
||||
| MODULE => {
|
||||
| MODULE | NAMED_FIELD_DEF => {
|
||||
let mut res = 0;
|
||||
for (i, (kind, text)) in trivias.enumerate() {
|
||||
match kind {
|
||||
|
Loading…
Reference in New Issue
Block a user