aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-05-13 17:39:06 +0100
committerAleksey Kladov <[email protected]>2019-05-13 17:39:06 +0100
commit549728bba87ed8f4375f27bb9a77223bf8f65452 (patch)
tree7d2711f243047a5e7ee74d7181905a36ae2c033d /crates/ra_hir/src
parent033a32f34944d7e07facd900a78db59b35e6698c (diff)
make AstId untyped
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/diagnostics.rs4
-rw-r--r--crates/ra_hir/src/expr/validation.rs2
-rw-r--r--crates/ra_hir/src/impl_block.rs2
-rw-r--r--crates/ra_hir/src/nameres/raw.rs5
-rw-r--r--crates/ra_hir/src/source_id.rs11
-rw-r--r--crates/ra_hir/src/ty/tests.rs2
6 files changed, 15 insertions, 11 deletions
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 @@
1use std::{fmt, any::Any}; 1use std::{fmt, any::Any};
2 2
3use ra_syntax::{SyntaxNodePtr, TreeArc, AstPtr, TextRange, ast, SyntaxNode}; 3use ra_syntax::{SyntaxNodePtr, TreeArc, AstPtr, TextRange, ast, SyntaxNode, AstNode};
4use relative_path::RelativePathBuf; 4use relative_path::RelativePathBuf;
5 5
6use crate::{HirFileId, HirDatabase, Name}; 6use crate::{HirFileId, HirDatabase, Name};
@@ -30,7 +30,7 @@ pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static {
30impl dyn Diagnostic { 30impl dyn Diagnostic {
31 pub fn syntax_node(&self, db: &impl HirDatabase) -> TreeArc<SyntaxNode> { 31 pub fn syntax_node(&self, db: &impl HirDatabase) -> TreeArc<SyntaxNode> {
32 let source_file = db.hir_parse(self.file()); 32 let source_file = db.hir_parse(self.file());
33 self.syntax_node_ptr().to_node(&source_file).to_owned() 33 self.syntax_node_ptr().to_node(source_file.syntax()).to_owned()
34 } 34 }
35 pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> { 35 pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> {
36 self.as_any().downcast_ref() 36 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> {
76 let source_file = db.parse(file_id.original_file(db)); 76 let source_file = db.parse(file_id.original_file(db));
77 if let Some(field_list_node) = source_map 77 if let Some(field_list_node) = source_map
78 .expr_syntax(id) 78 .expr_syntax(id)
79 .map(|ptr| ptr.to_node(&source_file)) 79 .map(|ptr| ptr.to_node(source_file.syntax()))
80 .and_then(StructLit::cast) 80 .and_then(StructLit::cast)
81 .and_then(|lit| lit.named_field_list()) 81 .and_then(|lit| lit.named_field_list())
82 { 82 {
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 {
34 ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(), 34 ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(),
35 }; 35 };
36 36
37 self.map[impl_id].to_node(file).to_owned() 37 self.map[impl_id].to_node(file.syntax()).to_owned()
38 } 38 }
39} 39}
40 40
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<ast::UseTree>, TreeArc<ast::ExternCrateItem>>
39 39
40impl ImportSourcePtr { 40impl ImportSourcePtr {
41 fn to_node(self, file: &SourceFile) -> ImportSource { 41 fn to_node(self, file: &SourceFile) -> ImportSource {
42 self.map(|ptr| ptr.to_node(file).to_owned(), |ptr| ptr.to_node(file).to_owned()) 42 self.map(
43 |ptr| ptr.to_node(file.syntax()).to_owned(),
44 |ptr| ptr.to_node(file.syntax()).to_owned(),
45 )
43 } 46 }
44} 47}
45 48
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 @@
1use std::{marker::PhantomData, sync::Arc, hash::{Hash, Hasher}}; 1use std::{marker::PhantomData, sync::Arc, hash::{Hash, Hasher}};
2 2
3use ra_arena::{Arena, RawId, impl_arena_id}; 3use ra_arena::{Arena, RawId, impl_arena_id};
4use ra_syntax::{SyntaxNodePtr, TreeArc, SyntaxNode, SourceFile, AstNode, ast}; 4use ra_syntax::{SyntaxNodePtr, TreeArc, SyntaxNode, AstNode, ast};
5 5
6use crate::{HirFileId, DefDatabase}; 6use crate::{HirFileId, DefDatabase};
7 7
@@ -89,7 +89,7 @@ pub struct AstIdMap {
89impl AstIdMap { 89impl AstIdMap {
90 pub(crate) fn ast_id_map_query(db: &impl DefDatabase, file_id: HirFileId) -> Arc<AstIdMap> { 90 pub(crate) fn ast_id_map_query(db: &impl DefDatabase, file_id: HirFileId) -> Arc<AstIdMap> {
91 let source_file = db.hir_parse(file_id); 91 let source_file = db.hir_parse(file_id);
92 Arc::new(AstIdMap::from_source_file(&source_file)) 92 Arc::new(AstIdMap::from_source(source_file.syntax()))
93 } 93 }
94 94
95 pub(crate) fn file_item_query( 95 pub(crate) fn file_item_query(
@@ -98,7 +98,7 @@ impl AstIdMap {
98 ast_id: ErasedFileAstId, 98 ast_id: ErasedFileAstId,
99 ) -> TreeArc<SyntaxNode> { 99 ) -> TreeArc<SyntaxNode> {
100 let source_file = db.hir_parse(file_id); 100 let source_file = db.hir_parse(file_id);
101 db.ast_id_map(file_id).arena[ast_id].to_node(&source_file).to_owned() 101 db.ast_id_map(file_id).arena[ast_id].to_node(source_file.syntax()).to_owned()
102 } 102 }
103 103
104 pub(crate) fn ast_id<N: AstNode>(&self, item: &N) -> FileAstId<N> { 104 pub(crate) fn ast_id<N: AstNode>(&self, item: &N) -> FileAstId<N> {
@@ -115,13 +115,14 @@ impl AstIdMap {
115 FileAstId { raw, _ty: PhantomData } 115 FileAstId { raw, _ty: PhantomData }
116 } 116 }
117 117
118 fn from_source_file(source_file: &SourceFile) -> AstIdMap { 118 fn from_source(node: &SyntaxNode) -> AstIdMap {
119 assert!(node.parent().is_none());
119 let mut res = AstIdMap { arena: Arena::default() }; 120 let mut res = AstIdMap { arena: Arena::default() };
120 // By walking the tree in bread-first order we make sure that parents 121 // By walking the tree in bread-first order we make sure that parents
121 // get lower ids then children. That is, adding a new child does not 122 // get lower ids then children. That is, adding a new child does not
122 // change parent's id. This means that, say, adding a new function to a 123 // change parent's id. This means that, say, adding a new function to a
123 // trait does not change ids of top-level items, which helps caching. 124 // trait does not change ids of top-level items, which helps caching.
124 bfs(source_file.syntax(), |it| { 125 bfs(node, |it| {
125 if let Some(module_item) = ast::ModuleItem::cast(it) { 126 if let Some(module_item) = ast::ModuleItem::cast(it) {
126 res.alloc(module_item.syntax()); 127 res.alloc(module_item.syntax());
127 } else if let Some(macro_call) = ast::MacroCall::cast(it) { 128 } 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 {
2715 // sort ranges for consistency 2715 // sort ranges for consistency
2716 types.sort_by_key(|(ptr, _)| (ptr.range().start(), ptr.range().end())); 2716 types.sort_by_key(|(ptr, _)| (ptr.range().start(), ptr.range().end()));
2717 for (syntax_ptr, ty) in &types { 2717 for (syntax_ptr, ty) in &types {
2718 let node = syntax_ptr.to_node(&source_file); 2718 let node = syntax_ptr.to_node(source_file.syntax());
2719 let (range, text) = if let Some(self_param) = ast::SelfParam::cast(node) { 2719 let (range, text) = if let Some(self_param) = ast::SelfParam::cast(node) {
2720 (self_param.self_kw_token().range(), "self".to_string()) 2720 (self_param.self_kw_token().range(), "self".to_string())
2721 } else { 2721 } else {