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/diagnostics.rs | 4 ++-- crates/ra_hir/src/expr/validation.rs | 2 +- crates/ra_hir/src/impl_block.rs | 2 +- crates/ra_hir/src/nameres/raw.rs | 5 ++++- crates/ra_hir/src/source_id.rs | 11 ++++++----- crates/ra_hir/src/ty/tests.rs | 2 +- 6 files changed, 15 insertions(+), 11 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/diagnostics.rs b/crates/ra_hir/src/diagnostics.rs index 61cd9d6b1..d41525779 100644 --- a/crates/ra_hir/src/diagnostics.rs +++ b/crates/ra_hir/src/diagnostics.rs @@ -1,6 +1,6 @@ use std::{fmt, any::Any}; -use ra_syntax::{SyntaxNodePtr, TreeArc, AstPtr, TextRange, ast, SyntaxNode}; +use ra_syntax::{SyntaxNodePtr, TreeArc, AstPtr, TextRange, ast, SyntaxNode, AstNode}; use relative_path::RelativePathBuf; use crate::{HirFileId, HirDatabase, Name}; @@ -30,7 +30,7 @@ pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { impl dyn Diagnostic { pub fn syntax_node(&self, db: &impl HirDatabase) -> TreeArc { let source_file = db.hir_parse(self.file()); - self.syntax_node_ptr().to_node(&source_file).to_owned() + self.syntax_node_ptr().to_node(source_file.syntax()).to_owned() } pub fn downcast_ref(&self) -> Option<&D> { self.as_any().downcast_ref() diff --git a/crates/ra_hir/src/expr/validation.rs b/crates/ra_hir/src/expr/validation.rs index fd4907313..aebed6788 100644 --- a/crates/ra_hir/src/expr/validation.rs +++ b/crates/ra_hir/src/expr/validation.rs @@ -76,7 +76,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { let source_file = db.parse(file_id.original_file(db)); if let Some(field_list_node) = source_map .expr_syntax(id) - .map(|ptr| ptr.to_node(&source_file)) + .map(|ptr| ptr.to_node(source_file.syntax())) .and_then(StructLit::cast) .and_then(|lit| lit.named_field_list()) { diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index b7dd775f1..51fa491c3 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs @@ -34,7 +34,7 @@ impl ImplSourceMap { ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(), }; - self.map[impl_id].to_node(file).to_owned() + self.map[impl_id].to_node(file.syntax()).to_owned() } } diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs index 43c97a0bf..211e02068 100644 --- a/crates/ra_hir/src/nameres/raw.rs +++ b/crates/ra_hir/src/nameres/raw.rs @@ -39,7 +39,10 @@ type ImportSource = Either, TreeArc> impl ImportSourcePtr { fn to_node(self, file: &SourceFile) -> ImportSource { - self.map(|ptr| ptr.to_node(file).to_owned(), |ptr| ptr.to_node(file).to_owned()) + self.map( + |ptr| ptr.to_node(file.syntax()).to_owned(), + |ptr| ptr.to_node(file.syntax()).to_owned(), + ) } } 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) { diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 978cc2587..f8364203d 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -2715,7 +2715,7 @@ fn infer(content: &str) -> String { // sort ranges for consistency types.sort_by_key(|(ptr, _)| (ptr.range().start(), ptr.range().end())); for (syntax_ptr, ty) in &types { - let node = syntax_ptr.to_node(&source_file); + let node = syntax_ptr.to_node(source_file.syntax()); let (range, text) = if let Some(self_param) = ast::SelfParam::cast(node) { (self_param.self_kw_token().range(), "self".to_string()) } else { -- cgit v1.2.3