From 65885791165c42b48fa2deaed32c4f35c17c62f5 Mon Sep 17 00:00:00 2001 From: "Jeremy A. Kolb" Date: Fri, 25 Jan 2019 12:51:36 -0500 Subject: Add module documentation support --- crates/ra_ide_api/src/completion/complete_path.rs | 16 +++++++++++++ .../ra_ide_api/src/completion/completion_item.rs | 2 +- .../snapshots/completion_item__mod_with_docs.snap | 26 ++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__mod_with_docs.snap (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 172aedf95..b33ddcde5 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -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( diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index b2b047766..b16ac2b28 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs @@ -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)), diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__mod_with_docs.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__mod_with_docs.snap new file mode 100644 index 000000000..3db7119a7 --- /dev/null +++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__mod_with_docs.snap @@ -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 + } +] -- cgit v1.2.3