diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-05-13 22:04:04 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-05-13 22:04:04 +0100 |
commit | bebc5c71664a144b9addd357eb503f776f2cf416 (patch) | |
tree | a7e95d622803bd745a93713dbce396be11846543 /crates/ra_hir/src/source_id.rs | |
parent | d7a4ae43f9308f683ddb3ca89104c5eb12d8d6b3 (diff) | |
parent | 549728bba87ed8f4375f27bb9a77223bf8f65452 (diff) |
Merge #1271
1271: make AstId untyped r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/source_id.rs')
-rw-r--r-- | crates/ra_hir/src/source_id.rs | 11 |
1 files changed, 6 insertions, 5 deletions
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 @@ | |||
1 | use std::{marker::PhantomData, sync::Arc, hash::{Hash, Hasher}}; | 1 | use std::{marker::PhantomData, sync::Arc, hash::{Hash, Hasher}}; |
2 | 2 | ||
3 | use ra_arena::{Arena, RawId, impl_arena_id}; | 3 | use ra_arena::{Arena, RawId, impl_arena_id}; |
4 | use ra_syntax::{SyntaxNodePtr, TreeArc, SyntaxNode, SourceFile, AstNode, ast}; | 4 | use ra_syntax::{SyntaxNodePtr, TreeArc, SyntaxNode, AstNode, ast}; |
5 | 5 | ||
6 | use crate::{HirFileId, DefDatabase}; | 6 | use crate::{HirFileId, DefDatabase}; |
7 | 7 | ||
@@ -89,7 +89,7 @@ pub struct AstIdMap { | |||
89 | impl AstIdMap { | 89 | impl 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) { |