aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/completion.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/completion.rs')
-rw-r--r--crates/ra_analysis/src/completion.rs23
1 files changed, 7 insertions, 16 deletions
diff --git a/crates/ra_analysis/src/completion.rs b/crates/ra_analysis/src/completion.rs
index f480af611..ed1b6dd0c 100644
--- a/crates/ra_analysis/src/completion.rs
+++ b/crates/ra_analysis/src/completion.rs
@@ -1,3 +1,4 @@
1mod completion_item;
1mod reference_completion; 2mod reference_completion;
2 3
3use ra_editor::find_node_at_offset; 4use ra_editor::find_node_at_offset;
@@ -17,15 +18,7 @@ use crate::{
17 Cancelable, FilePosition 18 Cancelable, FilePosition
18}; 19};
19 20
20#[derive(Debug)] 21pub use crate::completion::completion_item::CompletionItem;
21pub struct CompletionItem {
22 /// What user sees in pop-up
23 pub label: String,
24 /// What string is used for filtering, defaults to label
25 pub lookup: Option<String>,
26 /// What is inserted, defaults to label
27 pub snippet: Option<String>,
28}
29 22
30pub(crate) fn completions( 23pub(crate) fn completions(
31 db: &db::RootDatabase, 24 db: &db::RootDatabase,
@@ -63,6 +56,10 @@ pub(crate) fn completions(
63 Ok(res) 56 Ok(res)
64} 57}
65 58
59/// Complete repeated parametes, both name and type. For example, if all
60/// functions in a file have a `spam: &mut Spam` parameter, a completion with
61/// `spam: &mut Spam` insert text/label and `spam` lookup string will be
62/// suggested.
66fn param_completions(ctx: SyntaxNodeRef, acc: &mut Vec<CompletionItem>) { 63fn param_completions(ctx: SyntaxNodeRef, acc: &mut Vec<CompletionItem>) {
67 let mut params = FxHashMap::default(); 64 let mut params = FxHashMap::default();
68 for node in ctx.ancestors() { 65 for node in ctx.ancestors() {
@@ -81,13 +78,7 @@ fn param_completions(ctx: SyntaxNodeRef, acc: &mut Vec<CompletionItem>) {
81 Some((label, lookup)) 78 Some((label, lookup))
82 } 79 }
83 }) 80 })
84 .for_each(|(label, lookup)| { 81 .for_each(|(label, lookup)| CompletionItem::new(label).lookup_by(lookup).add_to(acc));
85 acc.push(CompletionItem {
86 label,
87 lookup: Some(lookup),
88 snippet: None,
89 })
90 });
91 82
92 fn process<'a, N: ast::FnDefOwner<'a>>( 83 fn process<'a, N: ast::FnDefOwner<'a>>(
93 node: N, 84 node: N,