From f6c40c09e0b5afa1b341ab7675c815862e07d22a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 9 Nov 2019 12:49:35 +0300 Subject: Minor cleanup --- crates/ra_hir_expand/src/lib.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'crates/ra_hir_expand/src') diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index b219b8fbf..151d1d785 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs @@ -151,19 +151,21 @@ pub struct ExpansionInfo { impl ExpansionInfo { pub fn find_range(&self, from: TextRange) -> Option<(HirFileId, TextRange)> { - fn look_in_rev_map(exp_map: &mbe::RevTokenMap, from: TextRange) -> Option { - exp_map.ranges.iter().find(|&it| it.0.is_subrange(&from)).map(|it| it.1) - } - let token_id = look_in_rev_map(&self.exp_map, from)?; - let (token_map, file_offset, token_id) = if token_id.0 >= self.shift { + + let (token_map, (file_id, start_offset), token_id) = if token_id.0 >= self.shift { (&self.macro_arg.1, self.arg_start, tt::TokenId(token_id.0 - self.shift).into()) } else { (&self.macro_def.1, self.def_start, token_id) }; let range = token_map.relative_range_of(token_id)?; - Some((file_offset.0, TextRange::offset_len(range.start() + file_offset.1, range.len()))) + + return Some((file_id, range + start_offset)); + + fn look_in_rev_map(exp_map: &mbe::RevTokenMap, from: TextRange) -> Option { + exp_map.ranges.iter().find(|&it| it.0.is_subrange(&from)).map(|it| it.1) + } } } -- cgit v1.2.3 From 70f2a21b55c1b09e575798a75807e13991f2cfec Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 9 Nov 2019 13:14:10 +0300 Subject: Remove typed macro parsing API We do type-erasure on every path anyway, so it doesn't make much sense to duplicate this function for every type --- crates/ra_hir_expand/src/db.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'crates/ra_hir_expand/src') diff --git a/crates/ra_hir_expand/src/db.rs b/crates/ra_hir_expand/src/db.rs index b789c6e7b..b4dafe1d8 100644 --- a/crates/ra_hir_expand/src/db.rs +++ b/crates/ra_hir_expand/src/db.rs @@ -4,6 +4,7 @@ use std::sync::Arc; use mbe::MacroRules; use ra_db::{salsa, SourceDatabase}; +use ra_parser::FragmentKind; use ra_prof::profile; use ra_syntax::{AstNode, Parse, SyntaxNode}; @@ -108,12 +109,10 @@ pub(crate) fn parse_macro( }) .ok()?; - match macro_file.macro_file_kind { - MacroFileKind::Items => { - mbe::token_tree_to_items(&tt).ok().map(|(p, map)| (p.to_syntax(), Arc::new(map))) - } - MacroFileKind::Expr => { - mbe::token_tree_to_expr(&tt).ok().map(|(p, map)| (p.to_syntax(), Arc::new(map))) - } - } + let fragment_kind = match macro_file.macro_file_kind { + MacroFileKind::Items => FragmentKind::Items, + MacroFileKind::Expr => FragmentKind::Expr, + }; + let (parse, rev_token_map) = mbe::token_tree_to_syntax_node(&tt, fragment_kind).ok()?; + Some((parse, Arc::new(rev_token_map))) } -- cgit v1.2.3