From 549728bba87ed8f4375f27bb9a77223bf8f65452 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 13 May 2019 19:39:06 +0300 Subject: make AstId untyped --- crates/ra_hir/src/source_id.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'crates/ra_hir/src/source_id.rs') diff --git a/crates/ra_hir/src/source_id.rs b/crates/ra_hir/src/source_id.rs index 0a8fb6d32..7a39be779 100644 --- a/crates/ra_hir/src/source_id.rs +++ b/crates/ra_hir/src/source_id.rs @@ -1,7 +1,7 @@ use std::{marker::PhantomData, sync::Arc, hash::{Hash, Hasher}}; use ra_arena::{Arena, RawId, impl_arena_id}; -use ra_syntax::{SyntaxNodePtr, TreeArc, SyntaxNode, SourceFile, AstNode, ast}; +use ra_syntax::{SyntaxNodePtr, TreeArc, SyntaxNode, AstNode, ast}; use crate::{HirFileId, DefDatabase}; @@ -89,7 +89,7 @@ pub struct AstIdMap { impl AstIdMap { pub(crate) fn ast_id_map_query(db: &impl DefDatabase, file_id: HirFileId) -> Arc { let source_file = db.hir_parse(file_id); - Arc::new(AstIdMap::from_source_file(&source_file)) + Arc::new(AstIdMap::from_source(source_file.syntax())) } pub(crate) fn file_item_query( @@ -98,7 +98,7 @@ impl AstIdMap { ast_id: ErasedFileAstId, ) -> TreeArc { let source_file = db.hir_parse(file_id); - db.ast_id_map(file_id).arena[ast_id].to_node(&source_file).to_owned() + db.ast_id_map(file_id).arena[ast_id].to_node(source_file.syntax()).to_owned() } pub(crate) fn ast_id(&self, item: &N) -> FileAstId { @@ -115,13 +115,14 @@ impl AstIdMap { FileAstId { raw, _ty: PhantomData } } - fn from_source_file(source_file: &SourceFile) -> AstIdMap { + fn from_source(node: &SyntaxNode) -> AstIdMap { + assert!(node.parent().is_none()); let mut res = AstIdMap { arena: Arena::default() }; // By walking the tree in bread-first order we make sure that parents // get lower ids then children. That is, adding a new child does not // change parent's id. This means that, say, adding a new function to a // trait does not change ids of top-level items, which helps caching. - bfs(source_file.syntax(), |it| { + bfs(node, |it| { if let Some(module_item) = ast::ModuleItem::cast(it) { res.alloc(module_item.syntax()); } else if let Some(macro_call) = ast::MacroCall::cast(it) { -- cgit v1.2.3