mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-25 22:22:44 +00:00
Merge #646
646: Add module documentation support r=matklad a=kjeremy Co-authored-by: Jeremy A. Kolb <jkolb@ara.com>
This commit is contained in:
commit
cc73d3ccbc
@ -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,
|
||||
|
@ -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(
|
||||
|
@ -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)),
|
||||
|
@ -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
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue
Block a user