646: Add module documentation support r=matklad a=kjeremy



Co-authored-by: Jeremy A. Kolb <jkolb@ara.com>
This commit is contained in:
bors[bot] 2019-01-25 17:55:29 +00:00
commit cc73d3ccbc
4 changed files with 50 additions and 1 deletions

View File

@ -177,6 +177,13 @@ impl Module {
}
}
impl Docs for Module {
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
self.declaration_source(db)
.and_then(|it| docs_from_ast(&*it.1))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct StructField {
pub(crate) parent: VariantDef,

View File

@ -65,6 +65,22 @@ mod tests {
check_completion(code, expected_completions, CompletionKind::Reference);
}
#[test]
fn completes_mod_with_docs() {
check_reference_completion(
"mod_with_docs",
r"
use self::my<|>;
/// Some simple
/// docs describing `mod my`.
mod my {
struct Bar;
}
",
);
}
#[test]
fn completes_use_item_starting_with_self() {
check_reference_completion(

View File

@ -215,7 +215,7 @@ impl Builder {
Some(it) => it,
};
let (kind, docs) = match def {
hir::ModuleDef::Module(_) => (CompletionItemKind::Module, None),
hir::ModuleDef::Module(it) => (CompletionItemKind::Module, it.docs(ctx.db)),
hir::ModuleDef::Function(func) => return self.from_function(ctx, func),
hir::ModuleDef::Struct(it) => (CompletionItemKind::Struct, it.docs(ctx.db)),
hir::ModuleDef::Enum(it) => (CompletionItemKind::Enum, it.docs(ctx.db)),

View File

@ -0,0 +1,26 @@
---
created: "2019-01-25T17:49:28.949186500+00:00"
creator: insta@0.5.2
expression: kind_completions
source: crates/ra_ide_api/src/completion/completion_item.rs
---
[
CompletionItem {
completion_kind: Reference,
label: "my",
kind: Some(
Module
),
detail: None,
documentation: Some(
Documentation(
"Some simple\ndocs describing `mod my`."
)
),
lookup: None,
insert_text: None,
insert_text_format: PlainText,
source_range: [23; 25),
text_edit: None
}
]