diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-24 01:22:29 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-24 01:22:29 +0000 |
commit | 6a0a4a564accb12b48e703245655e3e3a0637445 (patch) | |
tree | 248097d8ceaded63601e3d663ef795e3bae55bfe /crates/ra_ide_api/src/completion/complete_path.rs | |
parent | bf9cd6ee30b3044b61e99e24e82fad56d3965417 (diff) | |
parent | f87ce73579759fdb623f1d8d82880c0d6306746e (diff) |
Merge #621
621: Completion docs for code model r=kjeremy a=kjeremy
Adds a way to access documentation through the code model and exposes it to completions. Also allows us to document enum variants.
Co-authored-by: Jeremy A. Kolb <[email protected]>
Co-authored-by: Jeremy Kolb <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src/completion/complete_path.rs')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_path.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 6bed299d2..e44b76c4a 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs | |||
@@ -2,6 +2,8 @@ use crate::{ | |||
2 | completion::{CompletionItem, CompletionItemKind, Completions, CompletionKind, CompletionContext}, | 2 | completion::{CompletionItem, CompletionItemKind, Completions, CompletionKind, CompletionContext}, |
3 | }; | 3 | }; |
4 | 4 | ||
5 | use hir::Docs; | ||
6 | |||
5 | pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | 7 | pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { |
6 | let (path, module) = match (&ctx.path_prefix, &ctx.module) { | 8 | let (path, module) = match (&ctx.path_prefix, &ctx.module) { |
7 | (Some(path), Some(module)) => (path.clone(), module), | 9 | (Some(path), Some(module)) => (path.clone(), module), |
@@ -27,13 +29,14 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
27 | hir::Def::Enum(e) => { | 29 | hir::Def::Enum(e) => { |
28 | e.variants(ctx.db) | 30 | e.variants(ctx.db) |
29 | .into_iter() | 31 | .into_iter() |
30 | .for_each(|(variant_name, _variant)| { | 32 | .for_each(|(variant_name, variant)| { |
31 | CompletionItem::new( | 33 | CompletionItem::new( |
32 | CompletionKind::Reference, | 34 | CompletionKind::Reference, |
33 | ctx.source_range(), | 35 | ctx.source_range(), |
34 | variant_name.to_string(), | 36 | variant_name.to_string(), |
35 | ) | 37 | ) |
36 | .kind(CompletionItemKind::EnumVariant) | 38 | .kind(CompletionItemKind::EnumVariant) |
39 | .set_documentation(variant.docs(ctx.db)) | ||
37 | .add_to(acc) | 40 | .add_to(acc) |
38 | }); | 41 | }); |
39 | } | 42 | } |
@@ -116,7 +119,13 @@ mod tests { | |||
116 | "reference_completion", | 119 | "reference_completion", |
117 | " | 120 | " |
118 | //- /lib.rs | 121 | //- /lib.rs |
119 | enum E { Foo, Bar(i32) } | 122 | /// An enum |
123 | enum E { | ||
124 | /// Foo Variant | ||
125 | Foo, | ||
126 | /// Bar Variant with i32 | ||
127 | Bar(i32) | ||
128 | } | ||
120 | fn foo() { let _ = E::<|> } | 129 | fn foo() { let _ = E::<|> } |
121 | ", | 130 | ", |
122 | ); | 131 | ); |