diff options
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/src/completion/complete_scope.rs | 71 |
1 files changed, 47 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..fe0795984 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,80 @@ 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 { |
85 | let dummy_names = vec![ | 75 | let dummy_names = vec![ |
86 | (SmolStr::new("fmt"), vec![SmolStr::new("std"), SmolStr::new("fmt")]), | 76 | ( |
87 | (SmolStr::new("io"), vec![SmolStr::new("std"), SmolStr::new("io")]), | 77 | SmolStr::new("fmt"), |
88 | (SmolStr::new("iter"), vec![SmolStr::new("std"), SmolStr::new("iter")]), | 78 | ModPath { kind: PathKind::Plain, segments: vec![hir::known::std, hir::known::fmt] }, |
89 | (SmolStr::new("hash"), vec![SmolStr::new("std"), SmolStr::new("hash")]), | 79 | ), |
80 | ( | ||
81 | SmolStr::new("io"), | ||
82 | ModPath { kind: PathKind::Plain, segments: vec![hir::known::std, hir::known::io] }, | ||
83 | ), | ||
84 | ( | ||
85 | SmolStr::new("iter"), | ||
86 | ModPath { | ||
87 | kind: PathKind::Plain, | ||
88 | segments: vec![hir::known::std, hir::known::iter], | ||
89 | }, | ||
90 | ), | ||
91 | ( | ||
92 | SmolStr::new("hash"), | ||
93 | ModPath { | ||
94 | kind: PathKind::Plain, | ||
95 | segments: vec![hir::known::std, hir::known::hash], | ||
96 | }, | ||
97 | ), | ||
90 | ( | 98 | ( |
91 | SmolStr::new("Debug"), | 99 | SmolStr::new("Debug"), |
92 | vec![SmolStr::new("std"), SmolStr::new("fmt"), SmolStr::new("Debug")], | 100 | ModPath { |
101 | kind: PathKind::Plain, | ||
102 | segments: vec![hir::known::std, hir::known::fmt, hir::known::Debug], | ||
103 | }, | ||
93 | ), | 104 | ), |
94 | ( | 105 | ( |
95 | SmolStr::new("Display"), | 106 | SmolStr::new("Display"), |
96 | vec![SmolStr::new("std"), SmolStr::new("fmt"), SmolStr::new("Display")], | 107 | ModPath { |
108 | kind: PathKind::Plain, | ||
109 | segments: vec![hir::known::std, hir::known::fmt, hir::known::Display], | ||
110 | }, | ||
97 | ), | 111 | ), |
98 | ( | 112 | ( |
99 | SmolStr::new("Hash"), | 113 | SmolStr::new("Hash"), |
100 | vec![SmolStr::new("std"), SmolStr::new("hash"), SmolStr::new("Hash")], | 114 | ModPath { |
115 | kind: PathKind::Plain, | ||
116 | segments: vec![hir::known::std, hir::known::hash, hir::known::Hash], | ||
117 | }, | ||
101 | ), | 118 | ), |
102 | ( | 119 | ( |
103 | SmolStr::new("Hasher"), | 120 | SmolStr::new("Hasher"), |
104 | vec![SmolStr::new("std"), SmolStr::new("hash"), SmolStr::new("Hasher")], | 121 | ModPath { |
122 | kind: PathKind::Plain, | ||
123 | segments: vec![hir::known::std, hir::known::hash, hir::known::Hasher], | ||
124 | }, | ||
105 | ), | 125 | ), |
106 | ( | 126 | ( |
107 | SmolStr::new("Iterator"), | 127 | SmolStr::new("Iterator"), |
108 | vec![SmolStr::new("std"), SmolStr::new("iter"), SmolStr::new("Iterator")], | 128 | ModPath { |
129 | kind: PathKind::Plain, | ||
130 | segments: vec![hir::known::std, hir::known::iter, hir::known::Iterator], | ||
131 | }, | ||
109 | ), | 132 | ), |
110 | ]; | 133 | ]; |
111 | 134 | ||
@@ -115,7 +138,7 @@ impl ImportResolver { | |||
115 | // Returns a map of importable items filtered by name. | 138 | // Returns a map of importable items filtered by name. |
116 | // The map associates item name with its full path. | 139 | // The map associates item name with its full path. |
117 | // todo: should return Resolutions | 140 | // todo: should return Resolutions |
118 | pub(crate) fn all_names(&self, name: &str) -> FxHashMap<SmolStr, Vec<SmolStr>> { | 141 | pub(crate) fn all_names(&self, name: &str) -> FxHashMap<SmolStr, ModPath> { |
119 | if name.len() > 1 { | 142 | if name.len() > 1 { |
120 | self.dummy_names.iter().filter(|(n, _)| n.contains(name)).cloned().collect() | 143 | self.dummy_names.iter().filter(|(n, _)| n.contains(name)).cloned().collect() |
121 | } else { | 144 | } else { |