Add a bunch of new documentation to completions

This commit is contained in:
Jeremy A. Kolb 2019-01-23 17:46:14 -05:00
parent 576625f0a1
commit 7b548de634
3 changed files with 54 additions and 20 deletions

View File

@ -394,6 +394,12 @@ impl Const {
} }
} }
impl Docs for Const {
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
docs_from_ast(&*self.source(db).1)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Static { pub struct Static {
pub(crate) def_id: DefId, pub(crate) def_id: DefId,
@ -409,6 +415,12 @@ impl Static {
} }
} }
impl Docs for Static {
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
docs_from_ast(&*self.source(db).1)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Trait { pub struct Trait {
pub(crate) def_id: DefId, pub(crate) def_id: DefId,
@ -428,6 +440,12 @@ impl Trait {
} }
} }
impl Docs for Trait {
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
docs_from_ast(&*self.source(db).1)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Type { pub struct Type {
pub(crate) def_id: DefId, pub(crate) def_id: DefId,
@ -446,3 +464,9 @@ impl Type {
db.generic_params(self.def_id) db.generic_params(self.def_id)
} }
} }
impl Docs for Type {
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
docs_from_ast(&*self.source(db).1)
}
}

View File

@ -210,35 +210,35 @@ impl Builder {
resolution: &hir::Resolution, resolution: &hir::Resolution,
) -> Builder { ) -> Builder {
let resolved = resolution.def_id.map(|d| d.resolve(ctx.db)); let resolved = resolution.def_id.map(|d| d.resolve(ctx.db));
let kind = match resolved { let (kind, docs) = match resolved {
PerNs { PerNs {
types: Some(hir::Def::Module(..)), types: Some(hir::Def::Module(..)),
.. ..
} => CompletionItemKind::Module, } => (CompletionItemKind::Module, None),
PerNs { PerNs {
types: Some(hir::Def::Struct(..)), types: Some(hir::Def::Struct(s)),
.. ..
} => CompletionItemKind::Struct, } => (CompletionItemKind::Struct, s.docs(ctx.db)),
PerNs { PerNs {
types: Some(hir::Def::Enum(..)), types: Some(hir::Def::Enum(e)),
.. ..
} => CompletionItemKind::Enum, } => (CompletionItemKind::Enum, e.docs(ctx.db)),
PerNs { PerNs {
types: Some(hir::Def::Trait(..)), types: Some(hir::Def::Trait(t)),
.. ..
} => CompletionItemKind::Trait, } => (CompletionItemKind::Trait, t.docs(ctx.db)),
PerNs { PerNs {
types: Some(hir::Def::Type(..)), types: Some(hir::Def::Type(t)),
.. ..
} => CompletionItemKind::TypeAlias, } => (CompletionItemKind::TypeAlias, t.docs(ctx.db)),
PerNs { PerNs {
values: Some(hir::Def::Const(..)), values: Some(hir::Def::Const(c)),
.. ..
} => CompletionItemKind::Const, } => (CompletionItemKind::Const, c.docs(ctx.db)),
PerNs { PerNs {
values: Some(hir::Def::Static(..)), values: Some(hir::Def::Static(s)),
.. ..
} => CompletionItemKind::Static, } => (CompletionItemKind::Static, s.docs(ctx.db)),
PerNs { PerNs {
values: Some(hir::Def::Function(function)), values: Some(hir::Def::Function(function)),
.. ..
@ -246,6 +246,8 @@ impl Builder {
_ => return self, _ => return self,
}; };
self.kind = Some(kind); self.kind = Some(kind);
self.documentation = docs;
self self
} }

View File

@ -1,6 +1,6 @@
--- ---
created: "2019-01-22T14:45:00.717917+00:00" created: "2019-01-23T21:14:09.186661600+00:00"
creator: insta@0.4.0 creator: insta@0.5.1
expression: kind_completions expression: kind_completions
source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
--- ---
@ -12,11 +12,15 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
EnumVariant EnumVariant
), ),
detail: None, detail: None,
documentation: None, documentation: Some(
Documentation(
"This is foo"
)
),
lookup: None, lookup: None,
insert_text: None, insert_text: None,
insert_text_format: PlainText, insert_text_format: PlainText,
source_range: [47; 47), source_range: [109; 109),
text_edit: None text_edit: None
}, },
CompletionItem { CompletionItem {
@ -26,11 +30,15 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
EnumVariant EnumVariant
), ),
detail: None, detail: None,
documentation: None, documentation: Some(
Documentation(
"Use when we need an `i32`"
)
),
lookup: None, lookup: None,
insert_text: None, insert_text: None,
insert_text_format: PlainText, insert_text_format: PlainText,
source_range: [47; 47), source_range: [109; 109),
text_edit: None text_edit: None
} }
] ]