diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir_expand/src/db.rs | 15 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/lib.rs | 5 |
2 files changed, 5 insertions, 15 deletions
diff --git a/crates/ra_hir_expand/src/db.rs b/crates/ra_hir_expand/src/db.rs index 12aa7ad0e..8b92d4c1f 100644 --- a/crates/ra_hir_expand/src/db.rs +++ b/crates/ra_hir_expand/src/db.rs | |||
@@ -6,16 +6,14 @@ use ra_prof::profile; | |||
6 | use ra_syntax::{AstNode, Parse, SyntaxNode}; | 6 | use ra_syntax::{AstNode, Parse, SyntaxNode}; |
7 | 7 | ||
8 | use crate::{ | 8 | use crate::{ |
9 | ast_id_map::{AstIdMap, ErasedFileAstId}, | 9 | ast_id_map::AstIdMap, HirFileId, HirFileIdRepr, MacroCallId, MacroCallLoc, MacroDefId, |
10 | HirFileId, HirFileIdRepr, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, MacroFileKind, | 10 | MacroFile, MacroFileKind, |
11 | }; | 11 | }; |
12 | 12 | ||
13 | // FIXME: rename to ExpandDatabase | 13 | // FIXME: rename to ExpandDatabase |
14 | #[salsa::query_group(AstDatabaseStorage)] | 14 | #[salsa::query_group(AstDatabaseStorage)] |
15 | pub trait AstDatabase: SourceDatabase { | 15 | pub trait AstDatabase: SourceDatabase { |
16 | fn ast_id_map(&self, file_id: HirFileId) -> Arc<AstIdMap>; | 16 | fn ast_id_map(&self, file_id: HirFileId) -> Arc<AstIdMap>; |
17 | #[salsa::transparent] | ||
18 | fn ast_id_to_node(&self, file_id: HirFileId, ast_id: ErasedFileAstId) -> SyntaxNode; | ||
19 | 17 | ||
20 | #[salsa::transparent] | 18 | #[salsa::transparent] |
21 | fn parse_or_expand(&self, file_id: HirFileId) -> Option<SyntaxNode>; | 19 | fn parse_or_expand(&self, file_id: HirFileId) -> Option<SyntaxNode>; |
@@ -34,15 +32,6 @@ pub(crate) fn ast_id_map(db: &impl AstDatabase, file_id: HirFileId) -> Arc<AstId | |||
34 | Arc::new(map) | 32 | Arc::new(map) |
35 | } | 33 | } |
36 | 34 | ||
37 | pub(crate) fn ast_id_to_node( | ||
38 | db: &impl AstDatabase, | ||
39 | file_id: HirFileId, | ||
40 | ast_id: ErasedFileAstId, | ||
41 | ) -> SyntaxNode { | ||
42 | let node = db.parse_or_expand(file_id).unwrap(); | ||
43 | db.ast_id_map(file_id)[ast_id].to_node(&node) | ||
44 | } | ||
45 | |||
46 | pub(crate) fn macro_def(db: &impl AstDatabase, id: MacroDefId) -> Option<Arc<MacroRules>> { | 35 | pub(crate) fn macro_def(db: &impl AstDatabase, id: MacroDefId) -> Option<Arc<MacroRules>> { |
47 | let macro_call = id.ast_id.to_node(db); | 36 | let macro_call = id.ast_id.to_node(db); |
48 | let arg = macro_call.token_tree()?; | 37 | let arg = macro_call.token_tree()?; |
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index 002a5b45a..1fb124374 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs | |||
@@ -171,7 +171,8 @@ impl<N: AstNode> AstId<N> { | |||
171 | } | 171 | } |
172 | 172 | ||
173 | pub fn to_node(&self, db: &impl AstDatabase) -> N { | 173 | pub fn to_node(&self, db: &impl AstDatabase) -> N { |
174 | let syntax_node = db.ast_id_to_node(self.file_id, self.file_ast_id.into()); | 174 | let root = db.parse_or_expand(self.file_id).unwrap(); |
175 | N::cast(syntax_node).unwrap() | 175 | let node = db.ast_id_map(self.file_id)[self.file_ast_id.into()].to_node(&root); |
176 | N::cast(node).unwrap() | ||
176 | } | 177 | } |
177 | } | 178 | } |