Re-export Origin to replace ExpansionOrigin
This commit is contained in:
parent
61360fdfec
commit
b53587c7bd
@ -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};
|
||||
|
@ -214,11 +214,7 @@ pub struct ExpansionInfo {
|
||||
exp_map: Arc<mbe::TokenMap>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ExpansionOrigin {
|
||||
Call,
|
||||
Def,
|
||||
}
|
||||
pub use mbe::Origin;
|
||||
|
||||
impl ExpansionInfo {
|
||||
pub fn call_node(&self) -> Option<InFile<SyntaxNode>> {
|
||||
@ -241,17 +237,15 @@ impl ExpansionInfo {
|
||||
pub fn map_token_up(
|
||||
&self,
|
||||
token: InFile<&SyntaxToken>,
|
||||
) -> Option<(InFile<SyntaxToken>, ExpansionOrigin)> {
|
||||
) -> Option<(InFile<SyntaxToken>, 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)?;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -104,6 +104,7 @@ impl Shift {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub enum Origin {
|
||||
Def,
|
||||
Call,
|
||||
|
Loading…
x
Reference in New Issue
Block a user