diff options
Diffstat (limited to 'crates/ra_analysis/src/completion')
-rw-r--r-- | crates/ra_analysis/src/completion/completion_item.rs | 34 | ||||
-rw-r--r-- | crates/ra_analysis/src/completion/reference_completion.rs | 30 |
2 files changed, 40 insertions, 24 deletions
diff --git a/crates/ra_analysis/src/completion/completion_item.rs b/crates/ra_analysis/src/completion/completion_item.rs index 7edb86436..4280976e7 100644 --- a/crates/ra_analysis/src/completion/completion_item.rs +++ b/crates/ra_analysis/src/completion/completion_item.rs | |||
@@ -1,11 +1,13 @@ | |||
1 | #[derive(Debug)] | 1 | #[derive(Debug)] |
2 | pub struct CompletionItem { | 2 | pub struct CompletionItem { |
3 | /// What user sees in pop-up in the UI. | 3 | label: String, |
4 | pub label: String, | 4 | lookup: Option<String>, |
5 | /// What string is used for filtering, defaults to label. | 5 | snippet: Option<String>, |
6 | pub lookup: Option<String>, | 6 | } |
7 | /// What is inserted, defaults to label. | 7 | |
8 | pub snippet: Option<String>, | 8 | pub enum InsertText { |
9 | PlainText { text: String }, | ||
10 | Snippet { text: String }, | ||
9 | } | 11 | } |
10 | 12 | ||
11 | impl CompletionItem { | 13 | impl CompletionItem { |
@@ -17,6 +19,26 @@ impl CompletionItem { | |||
17 | snippet: None, | 19 | snippet: None, |
18 | } | 20 | } |
19 | } | 21 | } |
22 | /// What user sees in pop-up in the UI. | ||
23 | pub fn label(&self) -> &str { | ||
24 | &self.label | ||
25 | } | ||
26 | /// What string is used for filtering. | ||
27 | pub fn lookup(&self) -> &str { | ||
28 | self.lookup | ||
29 | .as_ref() | ||
30 | .map(|it| it.as_str()) | ||
31 | .unwrap_or(self.label()) | ||
32 | } | ||
33 | /// What is inserted. | ||
34 | pub fn insert_text(&self) -> InsertText { | ||
35 | match &self.snippet { | ||
36 | None => InsertText::PlainText { | ||
37 | text: self.label.clone(), | ||
38 | }, | ||
39 | Some(it) => InsertText::Snippet { text: it.clone() }, | ||
40 | } | ||
41 | } | ||
20 | } | 42 | } |
21 | 43 | ||
22 | #[must_use] | 44 | #[must_use] |
diff --git a/crates/ra_analysis/src/completion/reference_completion.rs b/crates/ra_analysis/src/completion/reference_completion.rs index 23052295c..f9f01a642 100644 --- a/crates/ra_analysis/src/completion/reference_completion.rs +++ b/crates/ra_analysis/src/completion/reference_completion.rs | |||
@@ -39,25 +39,19 @@ pub(super) fn completions( | |||
39 | } | 39 | } |
40 | 40 | ||
41 | let module_scope = module.scope(db)?; | 41 | let module_scope = module.scope(db)?; |
42 | acc.extend( | 42 | module_scope |
43 | module_scope | 43 | .entries() |
44 | .entries() | 44 | .filter(|(_name, res)| { |
45 | .filter(|(_name, res)| { | 45 | // Don't expose this item |
46 | // Don't expose this item | 46 | match res.import { |
47 | match res.import { | 47 | None => true, |
48 | None => true, | 48 | Some(import) => { |
49 | Some(import) => { | 49 | let range = import.range(db, module.source().file_id()); |
50 | let range = import.range(db, module.source().file_id()); | 50 | !range.is_subrange(&name_ref.syntax().range()) |
51 | !range.is_subrange(&name_ref.syntax().range()) | ||
52 | } | ||
53 | } | 51 | } |
54 | }) | 52 | } |
55 | .map(|(name, _res)| CompletionItem { | 53 | }) |
56 | label: name.to_string(), | 54 | .for_each(|(name, _res)| CompletionItem::new(name.to_string()).add_to(acc)); |
57 | lookup: None, | ||
58 | snippet: None, | ||
59 | }), | ||
60 | ); | ||
61 | } | 55 | } |
62 | NameRefKind::Path(path) => complete_path(acc, db, module, path)?, | 56 | NameRefKind::Path(path) => complete_path(acc, db, module, path)?, |
63 | NameRefKind::BareIdentInMod => { | 57 | NameRefKind::BareIdentInMod => { |