aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-02-01 23:18:10 +0000
committerFlorian Diebold <[email protected]>2019-02-01 23:23:53 +0000
commit5a7fce4e4cd8846a49ce007910f72340007d9c8c (patch)
tree7ec654f142d821e5ad5f9347bb84367fef0943d6 /crates/ra_hir/src
parentaa5f6a1ee8b56343e9f3dc9b1578d56f29dd2bc8 (diff)
Pass aliases to ImportData
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/nameres/lower.rs4
-rw-r--r--crates/ra_hir/src/path.rs13
2 files changed, 10 insertions, 7 deletions
diff --git a/crates/ra_hir/src/nameres/lower.rs b/crates/ra_hir/src/nameres/lower.rs
index 9a45fa61c..df87f520f 100644
--- a/crates/ra_hir/src/nameres/lower.rs
+++ b/crates/ra_hir/src/nameres/lower.rs
@@ -21,6 +21,7 @@ impl_arena_id!(ImportId);
21#[derive(Debug, PartialEq, Eq)] 21#[derive(Debug, PartialEq, Eq)]
22pub(super) struct ImportData { 22pub(super) struct ImportData {
23 pub(super) path: Path, 23 pub(super) path: Path,
24 pub(super) alias: Option<Name>,
24 pub(super) is_glob: bool, 25 pub(super) is_glob: bool,
25} 26}
26 27
@@ -209,9 +210,10 @@ impl LoweredModule {
209 } 210 }
210 211
211 fn add_use_item(&mut self, source_map: &mut ImportSourceMap, item: &ast::UseItem) { 212 fn add_use_item(&mut self, source_map: &mut ImportSourceMap, item: &ast::UseItem) {
212 Path::expand_use_item(item, |path, segment| { 213 Path::expand_use_item(item, |path, segment, alias| {
213 let import = self.imports.alloc(ImportData { 214 let import = self.imports.alloc(ImportData {
214 path, 215 path,
216 alias,
215 is_glob: segment.is_none(), 217 is_glob: segment.is_none(),
216 }); 218 });
217 if let Some(segment) = segment { 219 if let Some(segment) = segment {
diff --git a/crates/ra_hir/src/path.rs b/crates/ra_hir/src/path.rs
index e13d84c57..cb0a04500 100644
--- a/crates/ra_hir/src/path.rs
+++ b/crates/ra_hir/src/path.rs
@@ -1,6 +1,6 @@
1use std::sync::Arc; 1use std::sync::Arc;
2 2
3use ra_syntax::{ast, AstNode}; 3use ra_syntax::{ast::{self, NameOwner}, AstNode};
4 4
5use crate::{Name, AsName, type_ref::TypeRef}; 5use crate::{Name, AsName, type_ref::TypeRef};
6 6
@@ -46,7 +46,7 @@ impl Path {
46 /// Calls `cb` with all paths, represented by this use item. 46 /// Calls `cb` with all paths, represented by this use item.
47 pub fn expand_use_item<'a>( 47 pub fn expand_use_item<'a>(
48 item: &'a ast::UseItem, 48 item: &'a ast::UseItem,
49 mut cb: impl FnMut(Path, Option<&'a ast::PathSegment>), 49 mut cb: impl FnMut(Path, Option<&'a ast::PathSegment>, Option<Name>),
50 ) { 50 ) {
51 if let Some(tree) = item.use_tree() { 51 if let Some(tree) = item.use_tree() {
52 expand_use_tree(None, tree, &mut cb); 52 expand_use_tree(None, tree, &mut cb);
@@ -164,7 +164,7 @@ impl From<Name> for Path {
164fn expand_use_tree<'a>( 164fn expand_use_tree<'a>(
165 prefix: Option<Path>, 165 prefix: Option<Path>,
166 tree: &'a ast::UseTree, 166 tree: &'a ast::UseTree,
167 cb: &mut impl FnMut(Path, Option<&'a ast::PathSegment>), 167 cb: &mut impl FnMut(Path, Option<&'a ast::PathSegment>, Option<Name>),
168) { 168) {
169 if let Some(use_tree_list) = tree.use_tree_list() { 169 if let Some(use_tree_list) = tree.use_tree_list() {
170 let prefix = match tree.path() { 170 let prefix = match tree.path() {
@@ -181,6 +181,7 @@ fn expand_use_tree<'a>(
181 expand_use_tree(prefix.clone(), child_tree, cb); 181 expand_use_tree(prefix.clone(), child_tree, cb);
182 } 182 }
183 } else { 183 } else {
184 let alias = tree.alias().and_then(|a| a.name()).map(|a| a.as_name());
184 if let Some(ast_path) = tree.path() { 185 if let Some(ast_path) = tree.path() {
185 // Handle self in a path. 186 // Handle self in a path.
186 // E.g. `use something::{self, <...>}` 187 // E.g. `use something::{self, <...>}`
@@ -188,7 +189,7 @@ fn expand_use_tree<'a>(
188 if let Some(segment) = ast_path.segment() { 189 if let Some(segment) = ast_path.segment() {
189 if segment.kind() == Some(ast::PathSegmentKind::SelfKw) { 190 if segment.kind() == Some(ast::PathSegmentKind::SelfKw) {
190 if let Some(prefix) = prefix { 191 if let Some(prefix) = prefix {
191 cb(prefix, Some(segment)); 192 cb(prefix, Some(segment), alias);
192 return; 193 return;
193 } 194 }
194 } 195 }
@@ -196,9 +197,9 @@ fn expand_use_tree<'a>(
196 } 197 }
197 if let Some(path) = convert_path(prefix, ast_path) { 198 if let Some(path) = convert_path(prefix, ast_path) {
198 if tree.has_star() { 199 if tree.has_star() {
199 cb(path, None) 200 cb(path, None, alias)
200 } else if let Some(segment) = ast_path.segment() { 201 } else if let Some(segment) = ast_path.segment() {
201 cb(path, Some(segment)) 202 cb(path, Some(segment), alias)
202 }; 203 };
203 } 204 }
204 // TODO: report errors somewhere 205 // TODO: report errors somewhere