diff options
Diffstat (limited to 'crates/ra_ide/src/completion')
-rw-r--r-- | crates/ra_ide/src/completion/complete_scope.rs | 67 |
1 files changed, 43 insertions, 24 deletions
diff --git a/crates/ra_ide/src/completion/complete_scope.rs b/crates/ra_ide/src/completion/complete_scope.rs index 458d7525e..64b04ec2b 100644 --- a/crates/ra_ide/src/completion/complete_scope.rs +++ b/crates/ra_ide/src/completion/complete_scope.rs | |||
@@ -6,6 +6,7 @@ use ra_text_edit::TextEditBuilder; | |||
6 | use rustc_hash::FxHashMap; | 6 | use rustc_hash::FxHashMap; |
7 | 7 | ||
8 | use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions}; | 8 | use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions}; |
9 | use hir::{ModPath, PathKind}; | ||
9 | 10 | ||
10 | pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { | 11 | pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { |
11 | if !ctx.is_trivial_path { | 12 | if !ctx.is_trivial_path { |
@@ -54,58 +55,76 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { | |||
54 | } | 55 | } |
55 | } | 56 | } |
56 | 57 | ||
57 | fn build_import_label(name: &str, path: &[SmolStr]) -> String { | 58 | fn build_import_label(name: &str, path: &ModPath) -> String { |
58 | let mut buf = String::with_capacity(64); | 59 | let mut buf = String::with_capacity(64); |
59 | buf.push_str(name); | 60 | buf.push_str(name); |
60 | buf.push_str(" ("); | 61 | buf.push_str(" ("); |
61 | fmt_import_path(path, &mut buf); | 62 | buf.push_str(&path.to_string()); |
62 | buf.push_str(")"); | 63 | buf.push_str(")"); |
63 | buf | 64 | buf |
64 | } | 65 | } |
65 | 66 | ||
66 | fn fmt_import_path(path: &[SmolStr], buf: &mut String) { | ||
67 | let mut segments = path.iter(); | ||
68 | if let Some(s) = segments.next() { | ||
69 | buf.push_str(&s); | ||
70 | } | ||
71 | for s in segments { | ||
72 | buf.push_str("::"); | ||
73 | buf.push_str(&s); | ||
74 | } | ||
75 | } | ||
76 | |||
77 | #[derive(Debug, Clone, Default)] | 67 | #[derive(Debug, Clone, Default)] |
78 | pub(crate) struct ImportResolver { | 68 | pub(crate) struct ImportResolver { |
79 | // todo: use fst crate or something like that | 69 | // todo: use fst crate or something like that |
80 | dummy_names: Vec<(SmolStr, Vec<SmolStr>)>, | 70 | dummy_names: Vec<(SmolStr, ModPath)>, |
81 | } | 71 | } |
82 | 72 | ||
83 | impl ImportResolver { | 73 | impl ImportResolver { |
84 | pub(crate) fn new() -> Self { | 74 | pub(crate) fn new() -> Self { |
75 | use hir::name; | ||
76 | |||
85 | let dummy_names = vec![ | 77 | let dummy_names = vec![ |
86 | (SmolStr::new("fmt"), vec![SmolStr::new("std"), SmolStr::new("fmt")]), | 78 | ( |
87 | (SmolStr::new("io"), vec![SmolStr::new("std"), SmolStr::new("io")]), | 79 | SmolStr::new("fmt"), |
88 | (SmolStr::new("iter"), vec![SmolStr::new("std"), SmolStr::new("iter")]), | 80 | ModPath { kind: PathKind::Plain, segments: vec![name![std], name![fmt]] }, |
89 | (SmolStr::new("hash"), vec![SmolStr::new("std"), SmolStr::new("hash")]), | 81 | ), |
82 | ( | ||
83 | SmolStr::new("io"), | ||
84 | ModPath { kind: PathKind::Plain, segments: vec![name![std], name![io]] }, | ||
85 | ), | ||
86 | ( | ||
87 | SmolStr::new("iter"), | ||
88 | ModPath { kind: PathKind::Plain, segments: vec![name![std], name![iter]] }, | ||
89 | ), | ||
90 | ( | ||
91 | SmolStr::new("hash"), | ||
92 | ModPath { kind: PathKind::Plain, segments: vec![name![std], name![hash]] }, | ||
93 | ), | ||
90 | ( | 94 | ( |
91 | SmolStr::new("Debug"), | 95 | SmolStr::new("Debug"), |
92 | vec![SmolStr::new("std"), SmolStr::new("fmt"), SmolStr::new("Debug")], | 96 | ModPath { |
97 | kind: PathKind::Plain, | ||
98 | segments: vec![name![std], name![fmt], name![Debug]], | ||
99 | }, | ||
93 | ), | 100 | ), |
94 | ( | 101 | ( |
95 | SmolStr::new("Display"), | 102 | SmolStr::new("Display"), |
96 | vec![SmolStr::new("std"), SmolStr::new("fmt"), SmolStr::new("Display")], | 103 | ModPath { |
104 | kind: PathKind::Plain, | ||
105 | segments: vec![name![std], name![fmt], name![Display]], | ||
106 | }, | ||
97 | ), | 107 | ), |
98 | ( | 108 | ( |
99 | SmolStr::new("Hash"), | 109 | SmolStr::new("Hash"), |
100 | vec![SmolStr::new("std"), SmolStr::new("hash"), SmolStr::new("Hash")], | 110 | ModPath { |
111 | kind: PathKind::Plain, | ||
112 | segments: vec![name![std], name![hash], name![Hash]], | ||
113 | }, | ||
101 | ), | 114 | ), |
102 | ( | 115 | ( |
103 | SmolStr::new("Hasher"), | 116 | SmolStr::new("Hasher"), |
104 | vec![SmolStr::new("std"), SmolStr::new("hash"), SmolStr::new("Hasher")], | 117 | ModPath { |
118 | kind: PathKind::Plain, | ||
119 | segments: vec![name![std], name![hash], name![Hasher]], | ||
120 | }, | ||
105 | ), | 121 | ), |
106 | ( | 122 | ( |
107 | SmolStr::new("Iterator"), | 123 | SmolStr::new("Iterator"), |
108 | vec![SmolStr::new("std"), SmolStr::new("iter"), SmolStr::new("Iterator")], | 124 | ModPath { |
125 | kind: PathKind::Plain, | ||
126 | segments: vec![name![std], name![iter], name![Iterator]], | ||
127 | }, | ||
109 | ), | 128 | ), |
110 | ]; | 129 | ]; |
111 | 130 | ||
@@ -115,7 +134,7 @@ impl ImportResolver { | |||
115 | // Returns a map of importable items filtered by name. | 134 | // Returns a map of importable items filtered by name. |
116 | // The map associates item name with its full path. | 135 | // The map associates item name with its full path. |
117 | // todo: should return Resolutions | 136 | // todo: should return Resolutions |
118 | pub(crate) fn all_names(&self, name: &str) -> FxHashMap<SmolStr, Vec<SmolStr>> { | 137 | pub(crate) fn all_names(&self, name: &str) -> FxHashMap<SmolStr, ModPath> { |
119 | if name.len() > 1 { | 138 | if name.len() > 1 { |
120 | self.dummy_names.iter().filter(|(n, _)| n.contains(name)).cloned().collect() | 139 | self.dummy_names.iter().filter(|(n, _)| n.contains(name)).cloned().collect() |
121 | } else { | 140 | } else { |