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 @@ pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::ConstDef
}
}
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)]
pub struct Static {
pub(crate) def_id: DefId,
@ -409,6 +415,12 @@ pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::StaticDe
}
}
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)]
pub struct Trait {
pub(crate) def_id: DefId,
@ -428,6 +440,12 @@ pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> {
}
}
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)]
pub struct Type {
pub(crate) def_id: DefId,
@ -446,3 +464,9 @@ pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> {
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 @@ pub(super) fn from_resolution(
resolution: &hir::Resolution,
) -> Builder {
let resolved = resolution.def_id.map(|d| d.resolve(ctx.db));
let kind = match resolved {
let (kind, docs) = match resolved {
PerNs {
types: Some(hir::Def::Module(..)),
..
} => CompletionItemKind::Module,
} => (CompletionItemKind::Module, None),
PerNs {
types: Some(hir::Def::Struct(..)),
types: Some(hir::Def::Struct(s)),
..
} => CompletionItemKind::Struct,
} => (CompletionItemKind::Struct, s.docs(ctx.db)),
PerNs {
types: Some(hir::Def::Enum(..)),
types: Some(hir::Def::Enum(e)),
..
} => CompletionItemKind::Enum,
} => (CompletionItemKind::Enum, e.docs(ctx.db)),
PerNs {
types: Some(hir::Def::Trait(..)),
types: Some(hir::Def::Trait(t)),
..
} => CompletionItemKind::Trait,
} => (CompletionItemKind::Trait, t.docs(ctx.db)),
PerNs {
types: Some(hir::Def::Type(..)),
types: Some(hir::Def::Type(t)),
..
} => CompletionItemKind::TypeAlias,
} => (CompletionItemKind::TypeAlias, t.docs(ctx.db)),
PerNs {
values: Some(hir::Def::Const(..)),
values: Some(hir::Def::Const(c)),
..
} => CompletionItemKind::Const,
} => (CompletionItemKind::Const, c.docs(ctx.db)),
PerNs {
values: Some(hir::Def::Static(..)),
values: Some(hir::Def::Static(s)),
..
} => CompletionItemKind::Static,
} => (CompletionItemKind::Static, s.docs(ctx.db)),
PerNs {
values: Some(hir::Def::Function(function)),
..
@ -246,6 +246,8 @@ pub(super) fn from_resolution(
_ => return self,
};
self.kind = Some(kind);
self.documentation = docs;
self
}

View File

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