aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/macros.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-23 14:37:10 +0000
committerAleksey Kladov <[email protected]>2019-01-23 14:37:10 +0000
commit7b901f86cd1d0198994e5a2ab7eea18f444dd148 (patch)
treedfe8364efeeaca6f8f32e1d922fb615119b8012b /crates/ra_hir/src/macros.rs
parent81fcfc55d247bfe6090741f2e4ae9aa89947bf32 (diff)
move SyntaxPtr to ra_syntax
Diffstat (limited to 'crates/ra_hir/src/macros.rs')
-rw-r--r--crates/ra_hir/src/macros.rs13
1 files changed, 6 insertions, 7 deletions
diff --git a/crates/ra_hir/src/macros.rs b/crates/ra_hir/src/macros.rs
index 220bee94e..7ca34d434 100644
--- a/crates/ra_hir/src/macros.rs
+++ b/crates/ra_hir/src/macros.rs
@@ -9,9 +9,8 @@
9/// those yet, so all macros are string based at the moment! 9/// those yet, so all macros are string based at the moment!
10use std::sync::Arc; 10use std::sync::Arc;
11 11
12use ra_db::LocalSyntaxPtr;
13use ra_syntax::{ 12use ra_syntax::{
14 TextRange, TextUnit, SourceFile, AstNode, SyntaxNode, TreeArc, 13 TextRange, TextUnit, SourceFile, AstNode, SyntaxNode, TreeArc, SyntaxNodePtr,
15 ast::{self, NameOwner}, 14 ast::{self, NameOwner},
16}; 15};
17 16
@@ -80,7 +79,7 @@ impl MacroDef {
80 let file = SourceFile::parse(&text); 79 let file = SourceFile::parse(&text);
81 let match_expr = file.syntax().descendants().find_map(ast::MatchExpr::cast)?; 80 let match_expr = file.syntax().descendants().find_map(ast::MatchExpr::cast)?;
82 let match_arg = match_expr.expr()?; 81 let match_arg = match_expr.expr()?;
83 let ptr = LocalSyntaxPtr::new(match_arg.syntax()); 82 let ptr = SyntaxNodePtr::new(match_arg.syntax());
84 let src_range = TextRange::offset_len(0.into(), TextUnit::of_str(&input.text)); 83 let src_range = TextRange::offset_len(0.into(), TextUnit::of_str(&input.text));
85 let ranges_map = vec![(src_range, match_arg.syntax().range())]; 84 let ranges_map = vec![(src_range, match_arg.syntax().range())];
86 let res = MacroExpansion { 85 let res = MacroExpansion {
@@ -94,7 +93,7 @@ impl MacroDef {
94 let text = format!(r"fn dummy() {{ {}; }}", input.text); 93 let text = format!(r"fn dummy() {{ {}; }}", input.text);
95 let file = SourceFile::parse(&text); 94 let file = SourceFile::parse(&text);
96 let array_expr = file.syntax().descendants().find_map(ast::ArrayExpr::cast)?; 95 let array_expr = file.syntax().descendants().find_map(ast::ArrayExpr::cast)?;
97 let ptr = LocalSyntaxPtr::new(array_expr.syntax()); 96 let ptr = SyntaxNodePtr::new(array_expr.syntax());
98 let src_range = TextRange::offset_len(0.into(), TextUnit::of_str(&input.text)); 97 let src_range = TextRange::offset_len(0.into(), TextUnit::of_str(&input.text));
99 let ranges_map = vec![(src_range, array_expr.syntax().range())]; 98 let ranges_map = vec![(src_range, array_expr.syntax().range())];
100 let res = MacroExpansion { 99 let res = MacroExpansion {
@@ -119,7 +118,7 @@ impl MacroDef {
119 let file = SourceFile::parse(&text); 118 let file = SourceFile::parse(&text);
120 let trait_def = file.syntax().descendants().find_map(ast::TraitDef::cast)?; 119 let trait_def = file.syntax().descendants().find_map(ast::TraitDef::cast)?;
121 let name = trait_def.name()?; 120 let name = trait_def.name()?;
122 let ptr = LocalSyntaxPtr::new(trait_def.syntax()); 121 let ptr = SyntaxNodePtr::new(trait_def.syntax());
123 let ranges_map = vec![(src_range, name.syntax().range())]; 122 let ranges_map = vec![(src_range, name.syntax().range())];
124 let res = MacroExpansion { 123 let res = MacroExpansion {
125 text, 124 text,
@@ -146,7 +145,7 @@ pub struct MacroExpansion {
146 /// Implementation detail: internally, a macro is expanded to the whole file, 145 /// Implementation detail: internally, a macro is expanded to the whole file,
147 /// even if it is an expression. This `ptr` selects the actual expansion from 146 /// even if it is an expression. This `ptr` selects the actual expansion from
148 /// the expanded file. 147 /// the expanded file.
149 ptr: LocalSyntaxPtr, 148 ptr: SyntaxNodePtr,
150} 149}
151 150
152impl MacroExpansion { 151impl MacroExpansion {
@@ -157,7 +156,7 @@ impl MacroExpansion {
157 } 156 }
158 157
159 pub fn syntax(&self) -> TreeArc<SyntaxNode> { 158 pub fn syntax(&self) -> TreeArc<SyntaxNode> {
160 self.ptr.resolve(&self.file()) 159 self.ptr.to_node(&self.file()).to_owned()
161 } 160 }
162 /// Maps range in the source code to the range in the expanded code. 161 /// Maps range in the source code to the range in the expanded code.
163 pub fn map_range_forward(&self, src_range: TextRange) -> Option<TextRange> { 162 pub fn map_range_forward(&self, src_range: TextRange) -> Option<TextRange> {