aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/body/scope.rs7
-rw-r--r--crates/ra_hir_def/src/nameres/raw.rs32
-rw-r--r--crates/ra_hir_def/src/nameres/tests.rs9
3 files changed, 43 insertions, 5 deletions
diff --git a/crates/ra_hir_def/src/body/scope.rs b/crates/ra_hir_def/src/body/scope.rs
index fe4137176..5b36a7cc1 100644
--- a/crates/ra_hir_def/src/body/scope.rs
+++ b/crates/ra_hir_def/src/body/scope.rs
@@ -325,8 +325,11 @@ mod tests {
325 let resolved = scopes.resolve_name_in_scope(expr_scope, &name_ref.as_name()).unwrap(); 325 let resolved = scopes.resolve_name_in_scope(expr_scope, &name_ref.as_name()).unwrap();
326 let pat_src = source_map.pat_syntax(resolved.pat()).unwrap(); 326 let pat_src = source_map.pat_syntax(resolved.pat()).unwrap();
327 327
328 let local_name = pat_src.value.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr()); 328 let local_name = pat_src.value.either(
329 assert_eq!(local_name.range(), expected_name.syntax().text_range()); 329 |it| it.syntax_node_ptr().to_node(file.syntax()),
330 |it| it.syntax_node_ptr().to_node(file.syntax()),
331 );
332 assert_eq!(local_name.text_range(), expected_name.syntax().text_range());
330 } 333 }
331 334
332 #[test] 335 #[test]
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs
index afd538e4a..39b011ad7 100644
--- a/crates/ra_hir_def/src/nameres/raw.rs
+++ b/crates/ra_hir_def/src/nameres/raw.rs
@@ -266,8 +266,8 @@ impl RawItemsCollector {
266 self.add_macro(current_module, it); 266 self.add_macro(current_module, it);
267 return; 267 return;
268 } 268 }
269 ast::ModuleItem::ExternBlock(_) => { 269 ast::ModuleItem::ExternBlock(it) => {
270 // FIXME: add extern block 270 self.add_extern_block(current_module, it);
271 return; 271 return;
272 } 272 }
273 }; 273 };
@@ -278,6 +278,34 @@ impl RawItemsCollector {
278 } 278 }
279 } 279 }
280 280
281 fn add_extern_block(
282 &mut self,
283 current_module: Option<Idx<ModuleData>>,
284 block: ast::ExternBlock,
285 ) {
286 if let Some(items) = block.extern_item_list() {
287 for item in items.extern_items() {
288 let attrs = self.parse_attrs(&item);
289 let visibility =
290 RawVisibility::from_ast_with_hygiene(item.visibility(), &self.hygiene);
291 let (kind, name) = match item {
292 ast::ExternItem::FnDef(it) => {
293 (DefKind::Function(self.source_ast_id_map.ast_id(&it)), it.name())
294 }
295 ast::ExternItem::StaticDef(it) => {
296 (DefKind::Static(self.source_ast_id_map.ast_id(&it)), it.name())
297 }
298 };
299
300 if let Some(name) = name {
301 let name = name.as_name();
302 let def = self.raw_items.defs.alloc(DefData { name, kind, visibility });
303 self.push_item(current_module, attrs, RawItemKind::Def(def));
304 }
305 }
306 }
307 }
308
281 fn add_module(&mut self, current_module: Option<Idx<ModuleData>>, module: ast::Module) { 309 fn add_module(&mut self, current_module: Option<Idx<ModuleData>>, module: ast::Module) {
282 let name = match module.name() { 310 let name = match module.name() {
283 Some(it) => it.as_name(), 311 Some(it) => it.as_name(),
diff --git a/crates/ra_hir_def/src/nameres/tests.rs b/crates/ra_hir_def/src/nameres/tests.rs
index 949ca7595..83120fa36 100644
--- a/crates/ra_hir_def/src/nameres/tests.rs
+++ b/crates/ra_hir_def/src/nameres/tests.rs
@@ -25,7 +25,7 @@ fn compute_crate_def_map(fixture: &str) -> Arc<CrateDefMap> {
25#[test] 25#[test]
26fn crate_def_map_smoke_test() { 26fn crate_def_map_smoke_test() {
27 let map = def_map( 27 let map = def_map(
28 " 28 r"
29 //- /lib.rs 29 //- /lib.rs
30 mod foo; 30 mod foo;
31 struct S; 31 struct S;
@@ -45,6 +45,11 @@ fn crate_def_map_smoke_test() {
45 } 45 }
46 46
47 enum E { V } 47 enum E { V }
48
49 extern {
50 static EXT: u8;
51 fn ext();
52 }
48 ", 53 ",
49 ); 54 );
50 assert_snapshot!(map, @r###" 55 assert_snapshot!(map, @r###"
@@ -61,7 +66,9 @@ fn crate_def_map_smoke_test() {
61 ⋮crate::foo::bar 66 ⋮crate::foo::bar
62 ⋮Baz: t v 67 ⋮Baz: t v
63 ⋮E: t 68 ⋮E: t
69 ⋮EXT: v
64 ⋮U: t v 70 ⋮U: t v
71 ⋮ext: v
65 "###) 72 "###)
66} 73}
67 74