aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2020-03-08 10:02:14 +0000
committerFlorian Diebold <[email protected]>2020-03-08 10:10:48 +0000
commitafdf08e964345ac4a884a5630772611ba81f6969 (patch)
treeb72b06310a3cd9bcec2234b0f38ff93eb6a8feb0 /crates/ra_hir/src
parentf617455d10084da30a13cc49ffdd6b86c6049ba1 (diff)
Move hypothetical expansion to hir_expand
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/semantics.rs24
1 files changed, 3 insertions, 21 deletions
diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs
index 56bd763c7..3782a9984 100644
--- a/crates/ra_hir/src/semantics.rs
+++ b/crates/ra_hir/src/semantics.rs
@@ -12,8 +12,7 @@ use hir_expand::ExpansionInfo;
12use ra_db::{FileId, FileRange}; 12use ra_db::{FileId, FileRange};
13use ra_prof::profile; 13use ra_prof::profile;
14use ra_syntax::{ 14use ra_syntax::{
15 algo::{self, skip_trivia_token}, 15 algo::skip_trivia_token, ast, AstNode, Direction, SyntaxNode, SyntaxToken, TextRange, TextUnit,
16 ast, AstNode, Direction, SyntaxNode, SyntaxToken, TextRange, TextUnit,
17}; 16};
18use rustc_hash::{FxHashMap, FxHashSet}; 17use rustc_hash::{FxHashMap, FxHashSet};
19 18
@@ -74,7 +73,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
74 pub fn expand_hypothetical( 73 pub fn expand_hypothetical(
75 &self, 74 &self,
76 actual_macro_call: &ast::MacroCall, 75 actual_macro_call: &ast::MacroCall,
77 hypothetical_call: &ast::MacroCall, 76 hypothetical_args: &ast::TokenTree,
78 token_to_map: SyntaxToken, 77 token_to_map: SyntaxToken,
79 ) -> Option<(SyntaxNode, SyntaxToken)> { 78 ) -> Option<(SyntaxNode, SyntaxToken)> {
80 let macro_call = 79 let macro_call =
@@ -82,24 +81,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
82 let sa = self.analyze2(macro_call.map(|it| it.syntax()), None); 81 let sa = self.analyze2(macro_call.map(|it| it.syntax()), None);
83 let macro_call_id = macro_call 82 let macro_call_id = macro_call
84 .as_call_id(self.db, |path| sa.resolver.resolve_path_as_macro(self.db, &path))?; 83 .as_call_id(self.db, |path| sa.resolver.resolve_path_as_macro(self.db, &path))?;
85 let macro_file = macro_call_id.as_file().macro_file().unwrap(); 84 hir_expand::db::expand_hypothetical(self.db, macro_call_id, hypothetical_args, token_to_map)
86 let (tt, tmap_1) =
87 hir_expand::syntax_node_to_token_tree(hypothetical_call.token_tree().unwrap().syntax())
88 .unwrap();
89 let range = token_to_map
90 .text_range()
91 .checked_sub(hypothetical_call.token_tree().unwrap().syntax().text_range().start())?;
92 let token_id = tmap_1.token_by_range(range)?;
93 let macro_def = hir_expand::db::expander(self.db, macro_call_id)?;
94 let (node, tmap_2) = hir_expand::db::parse_macro_with_arg(
95 self.db,
96 macro_file,
97 Some(std::sync::Arc::new((tt, tmap_1))),
98 )?;
99 let token_id = macro_def.0.map_id_down(token_id);
100 let range = tmap_2.range_by_token(token_id)?.by_kind(token_to_map.kind())?;
101 let token = algo::find_covering_element(&node.syntax_node(), range).into_token()?;
102 Some((node.syntax_node(), token))
103 } 85 }
104 86
105 pub fn descend_into_macros(&self, token: SyntaxToken) -> SyntaxToken { 87 pub fn descend_into_macros(&self, token: SyntaxToken) -> SyntaxToken {