From b53587c7bdd67c63bd33a745fdaeb22a847b6c2f Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sun, 15 Dec 2019 01:46:39 +0800 Subject: Re-export Origin to replace ExpansionOrigin --- crates/ra_hir/src/lib.rs | 3 +-- crates/ra_hir_expand/src/lib.rs | 20 +++++++------------- crates/ra_ide/src/expand.rs | 4 ++-- crates/ra_mbe/src/lib.rs | 1 + 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 2bf729b6d..8b9562722 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -58,7 +58,6 @@ pub use hir_def::{ type_ref::Mutability, }; pub use hir_expand::{ - name::Name, ExpansionOrigin, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, - MacroFile, + name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, Origin, }; pub use hir_ty::{display::HirDisplay, CallableDef}; diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index d1a43fe6c..cb4e1950b 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs @@ -214,11 +214,7 @@ pub struct ExpansionInfo { exp_map: Arc, } -#[derive(Debug, Clone, PartialEq, Eq)] -pub enum ExpansionOrigin { - Call, - Def, -} +pub use mbe::Origin; impl ExpansionInfo { pub fn call_node(&self) -> Option> { @@ -241,17 +237,15 @@ impl ExpansionInfo { pub fn map_token_up( &self, token: InFile<&SyntaxToken>, - ) -> Option<(InFile, ExpansionOrigin)> { + ) -> Option<(InFile, Origin)> { let token_id = self.exp_map.token_by_range(token.value.text_range())?; let (token_id, origin) = self.macro_def.0.map_id_up(token_id); - let (token_map, tt, origin) = match origin { - mbe::Origin::Call => (&self.macro_arg.1, self.arg.clone(), ExpansionOrigin::Call), - mbe::Origin::Def => ( - &self.macro_def.1, - self.def.as_ref().map(|tt| tt.syntax().clone()), - ExpansionOrigin::Def, - ), + let (token_map, tt) = match origin { + mbe::Origin::Call => (&self.macro_arg.1, self.arg.clone()), + mbe::Origin::Def => { + (&self.macro_def.1, self.def.as_ref().map(|tt| tt.syntax().clone())) + } }; let range = token_map.range_by_token(token_id)?; diff --git a/crates/ra_ide/src/expand.rs b/crates/ra_ide/src/expand.rs index 327393dbb..258478bc1 100644 --- a/crates/ra_ide/src/expand.rs +++ b/crates/ra_ide/src/expand.rs @@ -1,7 +1,7 @@ //! Utilities to work with files, produced by macros. use std::iter::successors; -use hir::{ExpansionOrigin, InFile}; +use hir::{InFile, Origin}; use ra_db::FileId; use ra_syntax::{ast, AstNode, SyntaxNode, SyntaxToken, TextRange}; @@ -45,7 +45,7 @@ pub(crate) fn original_range_by_kind( if first.file_id != last.file_id || first_origin != last_origin - || (kind == OriginalRangeKind::CallToken && first_origin != ExpansionOrigin::Call) + || (kind == OriginalRangeKind::CallToken && first_origin != Origin::Call) { return None; } diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs index 0d2d43bef..ce2deadf6 100644 --- a/crates/ra_mbe/src/lib.rs +++ b/crates/ra_mbe/src/lib.rs @@ -104,6 +104,7 @@ impl Shift { } } +#[derive(Debug, Eq, PartialEq)] pub enum Origin { Def, Call, -- cgit v1.2.3