diff options
-rw-r--r-- | crates/ra_hir/src/module/nameres/tests.rs | 19 | ||||
-rw-r--r-- | crates/ra_hir/src/path.rs | 21 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 2 |
3 files changed, 39 insertions, 3 deletions
diff --git a/crates/ra_hir/src/module/nameres/tests.rs b/crates/ra_hir/src/module/nameres/tests.rs index 9fa9146e3..3e29c3954 100644 --- a/crates/ra_hir/src/module/nameres/tests.rs +++ b/crates/ra_hir/src/module/nameres/tests.rs | |||
@@ -44,6 +44,25 @@ fn item_map_smoke_test() { | |||
44 | } | 44 | } |
45 | 45 | ||
46 | #[test] | 46 | #[test] |
47 | fn test_self() { | ||
48 | let (item_map, module_id) = item_map( | ||
49 | " | ||
50 | //- /lib.rs | ||
51 | mod foo; | ||
52 | use crate::foo::bar::Baz::{self}; | ||
53 | <|> | ||
54 | //- /foo/mod.rs | ||
55 | pub mod bar; | ||
56 | //- /foo/bar.rs | ||
57 | pub struct Baz; | ||
58 | ", | ||
59 | ); | ||
60 | let name = SmolStr::from("Baz"); | ||
61 | let resolution = &item_map.per_module[&module_id].items[&name]; | ||
62 | assert!(resolution.def_id.is_some()); | ||
63 | } | ||
64 | |||
65 | #[test] | ||
47 | fn item_map_across_crates() { | 66 | fn item_map_across_crates() { |
48 | let (mut db, sr) = MockDatabase::with_files( | 67 | let (mut db, sr) = MockDatabase::with_files( |
49 | " | 68 | " |
diff --git a/crates/ra_hir/src/path.rs b/crates/ra_hir/src/path.rs index 4a2e427cd..e04d00900 100644 --- a/crates/ra_hir/src/path.rs +++ b/crates/ra_hir/src/path.rs | |||
@@ -76,17 +76,32 @@ fn expand_use_tree( | |||
76 | ) { | 76 | ) { |
77 | if let Some(use_tree_list) = tree.use_tree_list() { | 77 | if let Some(use_tree_list) = tree.use_tree_list() { |
78 | let prefix = match tree.path() { | 78 | let prefix = match tree.path() { |
79 | // E.g. use something::{{{inner}}}; | ||
79 | None => prefix, | 80 | None => prefix, |
81 | // E.g. `use something::{inner}` (prefix is `None`, path is `something`) | ||
82 | // or `use something::{path::{inner::{innerer}}}` (prefix is `something::path`, path is `inner`) | ||
80 | Some(path) => match convert_path(prefix, path) { | 83 | Some(path) => match convert_path(prefix, path) { |
81 | Some(it) => Some(it), | 84 | Some(it) => Some(it), |
82 | None => return, // TODO: report errors somewhere | 85 | None => return, // TODO: report errors somewhere |
83 | }, | 86 | }, |
84 | }; | 87 | }; |
85 | for tree in use_tree_list.use_trees() { | 88 | for child_tree in use_tree_list.use_trees() { |
86 | expand_use_tree(prefix.clone(), tree, cb); | 89 | expand_use_tree(prefix.clone(), child_tree, cb); |
87 | } | 90 | } |
88 | } else { | 91 | } else { |
89 | if let Some(ast_path) = tree.path() { | 92 | if let Some(ast_path) = tree.path() { |
93 | // Handle self in a path. | ||
94 | // E.g. `use something::{self, <...>}` | ||
95 | if ast_path.qualifier().is_none() { | ||
96 | if let Some(segment) = ast_path.segment() { | ||
97 | if segment.kind() == Some(ast::PathSegmentKind::SelfKw) { | ||
98 | if let Some(prefix) = prefix { | ||
99 | cb(prefix, Some(segment.syntax().range())); | ||
100 | return; | ||
101 | } | ||
102 | } | ||
103 | } | ||
104 | } | ||
90 | if let Some(path) = convert_path(prefix, ast_path) { | 105 | if let Some(path) = convert_path(prefix, ast_path) { |
91 | let range = if tree.has_star() { | 106 | let range = if tree.has_star() { |
92 | None | 107 | None |
@@ -96,6 +111,8 @@ fn expand_use_tree( | |||
96 | }; | 111 | }; |
97 | cb(path, range) | 112 | cb(path, range) |
98 | } | 113 | } |
114 | // TODO: report errors somewhere | ||
115 | // We get here if we do | ||
99 | } | 116 | } |
100 | } | 117 | } |
101 | } | 118 | } |
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 91c67119f..f12479fb4 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -284,7 +284,7 @@ impl<'a> IfExpr<'a> { | |||
284 | } | 284 | } |
285 | } | 285 | } |
286 | 286 | ||
287 | #[derive(Debug, Clone, Copy)] | 287 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
288 | pub enum PathSegmentKind<'a> { | 288 | pub enum PathSegmentKind<'a> { |
289 | Name(NameRef<'a>), | 289 | Name(NameRef<'a>), |
290 | SelfKw, | 290 | SelfKw, |