diff options
Diffstat (limited to 'crates')
-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 | ||||
-rw-r--r-- | crates/ra_syntax/src/lexer.rs | 2 | ||||
-rw-r--r-- | crates/ra_syntax/tests/test.rs | 12 |
5 files changed, 44 insertions, 12 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, |
diff --git a/crates/ra_syntax/src/lexer.rs b/crates/ra_syntax/src/lexer.rs index f388da273..c6acd095e 100644 --- a/crates/ra_syntax/src/lexer.rs +++ b/crates/ra_syntax/src/lexer.rs | |||
@@ -160,7 +160,7 @@ fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind { | |||
160 | // if we find one, then this is an invalid character literal | 160 | // if we find one, then this is an invalid character literal |
161 | if ptr.at('\'') { | 161 | if ptr.at('\'') { |
162 | ptr.bump(); | 162 | ptr.bump(); |
163 | return CHAR; // TODO: error reporting | 163 | return CHAR; |
164 | } | 164 | } |
165 | LIFETIME | 165 | LIFETIME |
166 | } else { | 166 | } else { |
diff --git a/crates/ra_syntax/tests/test.rs b/crates/ra_syntax/tests/test.rs index 14ad836b5..4266864bd 100644 --- a/crates/ra_syntax/tests/test.rs +++ b/crates/ra_syntax/tests/test.rs | |||
@@ -65,14 +65,10 @@ fn self_hosting_parsing() { | |||
65 | for entry in walkdir::WalkDir::new(dir) | 65 | for entry in walkdir::WalkDir::new(dir) |
66 | .into_iter() | 66 | .into_iter() |
67 | .filter_entry(|entry| { | 67 | .filter_entry(|entry| { |
68 | !entry | 68 | !entry.path().components().any(|component| { |
69 | .path() | 69 | // Get all files which are not in the crates/ra_syntax/tests/data folder |
70 | .components() | 70 | component == Component::Normal(OsStr::new("data")) |
71 | // TODO: this more neatly | 71 | }) |
72 | .any(|component| { | ||
73 | // Get all files which are not in the crates/ra_syntax/tests/data folder | ||
74 | component == Component::Normal(OsStr::new("data")) | ||
75 | }) | ||
76 | }) | 72 | }) |
77 | .map(|e| e.unwrap()) | 73 | .map(|e| e.unwrap()) |
78 | .filter(|entry| { | 74 | .filter(|entry| { |