diff options
Diffstat (limited to 'crates/ra_hir/src/source_id.rs')
-rw-r--r-- | crates/ra_hir/src/source_id.rs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/crates/ra_hir/src/source_id.rs b/crates/ra_hir/src/source_id.rs index 6cdb90141..51cd65dda 100644 --- a/crates/ra_hir/src/source_id.rs +++ b/crates/ra_hir/src/source_id.rs | |||
@@ -5,7 +5,7 @@ use std::{ | |||
5 | }; | 5 | }; |
6 | 6 | ||
7 | use ra_arena::{impl_arena_id, Arena, RawId}; | 7 | use ra_arena::{impl_arena_id, Arena, RawId}; |
8 | use ra_syntax::{ast, AstNode, SyntaxNode, SyntaxNodePtr, TreeArc}; | 8 | use ra_syntax::{ast, AstNode, SyntaxNode, SyntaxNodePtr}; |
9 | 9 | ||
10 | use crate::{AstDatabase, HirFileId}; | 10 | use crate::{AstDatabase, HirFileId}; |
11 | 11 | ||
@@ -42,9 +42,9 @@ impl<N: AstNode> AstId<N> { | |||
42 | self.file_id | 42 | self.file_id |
43 | } | 43 | } |
44 | 44 | ||
45 | pub(crate) fn to_node(&self, db: &impl AstDatabase) -> TreeArc<N> { | 45 | pub(crate) fn to_node(&self, db: &impl AstDatabase) -> N { |
46 | let syntax_node = db.ast_id_to_node(self.file_id, self.file_ast_id.raw); | 46 | let syntax_node = db.ast_id_to_node(self.file_id, self.file_ast_id.raw); |
47 | N::cast(&syntax_node).unwrap().to_owned() | 47 | N::cast(syntax_node).unwrap() |
48 | } | 48 | } |
49 | } | 49 | } |
50 | 50 | ||
@@ -93,7 +93,7 @@ pub struct AstIdMap { | |||
93 | impl AstIdMap { | 93 | impl AstIdMap { |
94 | pub(crate) fn ast_id_map_query(db: &impl AstDatabase, file_id: HirFileId) -> Arc<AstIdMap> { | 94 | pub(crate) fn ast_id_map_query(db: &impl AstDatabase, file_id: HirFileId) -> Arc<AstIdMap> { |
95 | let map = if let Some(node) = db.parse_or_expand(file_id) { | 95 | let map = if let Some(node) = db.parse_or_expand(file_id) { |
96 | AstIdMap::from_source(&*node) | 96 | AstIdMap::from_source(&node) |
97 | } else { | 97 | } else { |
98 | AstIdMap::default() | 98 | AstIdMap::default() |
99 | }; | 99 | }; |
@@ -104,9 +104,9 @@ impl AstIdMap { | |||
104 | db: &impl AstDatabase, | 104 | db: &impl AstDatabase, |
105 | file_id: HirFileId, | 105 | file_id: HirFileId, |
106 | ast_id: ErasedFileAstId, | 106 | ast_id: ErasedFileAstId, |
107 | ) -> TreeArc<SyntaxNode> { | 107 | ) -> SyntaxNode { |
108 | let node = db.parse_or_expand(file_id).unwrap(); | 108 | let node = db.parse_or_expand(file_id).unwrap(); |
109 | db.ast_id_map(file_id).arena[ast_id].to_node(&*node).to_owned() | 109 | db.ast_id_map(file_id).arena[ast_id].to_node(&node) |
110 | } | 110 | } |
111 | 111 | ||
112 | pub(crate) fn ast_id<N: AstNode>(&self, item: &N) -> FileAstId<N> { | 112 | pub(crate) fn ast_id<N: AstNode>(&self, item: &N) -> FileAstId<N> { |
@@ -131,7 +131,7 @@ impl AstIdMap { | |||
131 | // change parent's id. This means that, say, adding a new function to a | 131 | // change parent's id. This means that, say, adding a new function to a |
132 | // trait does not change ids of top-level items, which helps caching. | 132 | // trait does not change ids of top-level items, which helps caching. |
133 | bfs(node, |it| { | 133 | bfs(node, |it| { |
134 | if let Some(module_item) = ast::ModuleItem::cast(it) { | 134 | if let Some(module_item) = ast::ModuleItem::cast(it.clone()) { |
135 | res.alloc(module_item.syntax()); | 135 | res.alloc(module_item.syntax()); |
136 | } else if let Some(macro_call) = ast::MacroCall::cast(it) { | 136 | } else if let Some(macro_call) = ast::MacroCall::cast(it) { |
137 | res.alloc(macro_call.syntax()); | 137 | res.alloc(macro_call.syntax()); |
@@ -146,8 +146,8 @@ impl AstIdMap { | |||
146 | } | 146 | } |
147 | 147 | ||
148 | /// Walks the subtree in bfs order, calling `f` for each node. | 148 | /// Walks the subtree in bfs order, calling `f` for each node. |
149 | fn bfs(node: &SyntaxNode, mut f: impl FnMut(&SyntaxNode)) { | 149 | fn bfs(node: &SyntaxNode, mut f: impl FnMut(SyntaxNode)) { |
150 | let mut curr_layer = vec![node]; | 150 | let mut curr_layer = vec![node.clone()]; |
151 | let mut next_layer = vec![]; | 151 | let mut next_layer = vec![]; |
152 | while !curr_layer.is_empty() { | 152 | while !curr_layer.is_empty() { |
153 | curr_layer.drain(..).for_each(|node| { | 153 | curr_layer.drain(..).for_each(|node| { |