aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/ids.rs29
-rw-r--r--crates/ra_hir/src/query_definitions.rs7
2 files changed, 15 insertions, 21 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index 631f6f6a1..015d640e3 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -4,7 +4,7 @@ use std::{
4}; 4};
5 5
6use ra_db::{LocationIntener, FileId}; 6use ra_db::{LocationIntener, FileId};
7use ra_syntax::{TreeArc, SyntaxNode, SourceFile, AstNode, ast}; 7use ra_syntax::{TreeArc, SyntaxNode, SourceFile, AstNode, SyntaxNodePtr, ast};
8use ra_arena::{Arena, RawId, ArenaId, impl_arena_id}; 8use ra_arena::{Arena, RawId, ArenaId, impl_arena_id};
9 9
10use crate::{ 10use crate::{
@@ -309,7 +309,7 @@ pub struct SourceItemId {
309#[derive(Debug, PartialEq, Eq)] 309#[derive(Debug, PartialEq, Eq)]
310pub struct SourceFileItems { 310pub struct SourceFileItems {
311 file_id: HirFileId, 311 file_id: HirFileId,
312 arena: Arena<SourceFileItemId, TreeArc<SyntaxNode>>, 312 arena: Arena<SourceFileItemId, SyntaxNodePtr>,
313} 313}
314 314
315impl SourceFileItems { 315impl SourceFileItems {
@@ -329,15 +329,15 @@ impl SourceFileItems {
329 // trait does not chage ids of top-level items, which helps caching. 329 // trait does not chage ids of top-level items, which helps caching.
330 bfs(source_file.syntax(), |it| { 330 bfs(source_file.syntax(), |it| {
331 if let Some(module_item) = ast::ModuleItem::cast(it) { 331 if let Some(module_item) = ast::ModuleItem::cast(it) {
332 self.alloc(module_item.syntax().to_owned()); 332 self.alloc(module_item.syntax());
333 } else if let Some(macro_call) = ast::MacroCall::cast(it) { 333 } else if let Some(macro_call) = ast::MacroCall::cast(it) {
334 self.alloc(macro_call.syntax().to_owned()); 334 self.alloc(macro_call.syntax());
335 } 335 }
336 }) 336 })
337 } 337 }
338 338
339 fn alloc(&mut self, item: TreeArc<SyntaxNode>) -> SourceFileItemId { 339 fn alloc(&mut self, item: &SyntaxNode) -> SourceFileItemId {
340 self.arena.alloc(item) 340 self.arena.alloc(SyntaxNodePtr::new(item))
341 } 341 }
342 pub(crate) fn id_of(&self, file_id: HirFileId, item: &SyntaxNode) -> SourceFileItemId { 342 pub(crate) fn id_of(&self, file_id: HirFileId, item: &SyntaxNode) -> SourceFileItemId {
343 assert_eq!( 343 assert_eq!(
@@ -348,17 +348,8 @@ impl SourceFileItems {
348 self.id_of_unchecked(item) 348 self.id_of_unchecked(item)
349 } 349 }
350 pub(crate) fn id_of_unchecked(&self, item: &SyntaxNode) -> SourceFileItemId { 350 pub(crate) fn id_of_unchecked(&self, item: &SyntaxNode) -> SourceFileItemId {
351 if let Some((id, _)) = self.arena.iter().find(|(_id, i)| *i == item) { 351 let ptr = SyntaxNodePtr::new(item);
352 return id; 352 if let Some((id, _)) = self.arena.iter().find(|(_id, i)| **i == ptr) {
353 }
354 // This should not happen. Let's try to give a sensible diagnostics.
355 if let Some((id, i)) = self.arena.iter().find(|(_id, i)| i.range() == item.range()) {
356 // FIXME(#288): whyyy are we getting here?
357 log::error!(
358 "unequal syntax nodes with the same range:\n{:?}\n{:?}",
359 item,
360 i
361 );
362 return id; 353 return id;
363 } 354 }
364 panic!( 355 panic!(
@@ -370,8 +361,8 @@ impl SourceFileItems {
370} 361}
371 362
372impl std::ops::Index<SourceFileItemId> for SourceFileItems { 363impl std::ops::Index<SourceFileItemId> for SourceFileItems {
373 type Output = SyntaxNode; 364 type Output = SyntaxNodePtr;
374 fn index(&self, idx: SourceFileItemId) -> &SyntaxNode { 365 fn index(&self, idx: SourceFileItemId) -> &SyntaxNodePtr {
375 &self.arena[idx] 366 &self.arena[idx]
376 } 367 }
377} 368}
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs
index 61c93a964..380c06404 100644
--- a/crates/ra_hir/src/query_definitions.rs
+++ b/crates/ra_hir/src/query_definitions.rs
@@ -32,9 +32,12 @@ pub(super) fn file_item(
32 db: &impl HirDatabase, 32 db: &impl HirDatabase,
33 source_item_id: SourceItemId, 33 source_item_id: SourceItemId,
34) -> TreeArc<SyntaxNode> { 34) -> TreeArc<SyntaxNode> {
35 let source_file = db.hir_parse(source_item_id.file_id);
35 match source_item_id.item_id { 36 match source_item_id.item_id {
36 Some(id) => db.file_items(source_item_id.file_id)[id].to_owned(), 37 Some(id) => db.file_items(source_item_id.file_id)[id]
37 None => db.hir_parse(source_item_id.file_id).syntax().to_owned(), 38 .to_node(&source_file)
39 .to_owned(),
40 None => source_file.syntax().to_owned(),
38 } 41 }
39} 42}
40 43