mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Re-export Origin to replace ExpansionOrigin
This commit is contained in:
parent
61360fdfec
commit
b53587c7bd
4 changed files with 11 additions and 17 deletions
|
@ -58,7 +58,6 @@ pub use hir_def::{
|
||||||
type_ref::Mutability,
|
type_ref::Mutability,
|
||||||
};
|
};
|
||||||
pub use hir_expand::{
|
pub use hir_expand::{
|
||||||
name::Name, ExpansionOrigin, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId,
|
name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, Origin,
|
||||||
MacroFile,
|
|
||||||
};
|
};
|
||||||
pub use hir_ty::{display::HirDisplay, CallableDef};
|
pub use hir_ty::{display::HirDisplay, CallableDef};
|
||||||
|
|
|
@ -214,11 +214,7 @@ pub struct ExpansionInfo {
|
||||||
exp_map: Arc<mbe::TokenMap>,
|
exp_map: Arc<mbe::TokenMap>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
pub use mbe::Origin;
|
||||||
pub enum ExpansionOrigin {
|
|
||||||
Call,
|
|
||||||
Def,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ExpansionInfo {
|
impl ExpansionInfo {
|
||||||
pub fn call_node(&self) -> Option<InFile<SyntaxNode>> {
|
pub fn call_node(&self) -> Option<InFile<SyntaxNode>> {
|
||||||
|
@ -241,17 +237,15 @@ impl ExpansionInfo {
|
||||||
pub fn map_token_up(
|
pub fn map_token_up(
|
||||||
&self,
|
&self,
|
||||||
token: InFile<&SyntaxToken>,
|
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 = 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_id, origin) = self.macro_def.0.map_id_up(token_id);
|
||||||
let (token_map, tt, origin) = match origin {
|
let (token_map, tt) = match origin {
|
||||||
mbe::Origin::Call => (&self.macro_arg.1, self.arg.clone(), ExpansionOrigin::Call),
|
mbe::Origin::Call => (&self.macro_arg.1, self.arg.clone()),
|
||||||
mbe::Origin::Def => (
|
mbe::Origin::Def => {
|
||||||
&self.macro_def.1,
|
(&self.macro_def.1, self.def.as_ref().map(|tt| tt.syntax().clone()))
|
||||||
self.def.as_ref().map(|tt| tt.syntax().clone()),
|
}
|
||||||
ExpansionOrigin::Def,
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let range = token_map.range_by_token(token_id)?;
|
let range = token_map.range_by_token(token_id)?;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Utilities to work with files, produced by macros.
|
//! Utilities to work with files, produced by macros.
|
||||||
use std::iter::successors;
|
use std::iter::successors;
|
||||||
|
|
||||||
use hir::{ExpansionOrigin, InFile};
|
use hir::{InFile, Origin};
|
||||||
use ra_db::FileId;
|
use ra_db::FileId;
|
||||||
use ra_syntax::{ast, AstNode, SyntaxNode, SyntaxToken, TextRange};
|
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
|
if first.file_id != last.file_id
|
||||||
|| first_origin != last_origin
|
|| first_origin != last_origin
|
||||||
|| (kind == OriginalRangeKind::CallToken && first_origin != ExpansionOrigin::Call)
|
|| (kind == OriginalRangeKind::CallToken && first_origin != Origin::Call)
|
||||||
{
|
{
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,6 +104,7 @@ impl Shift {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
pub enum Origin {
|
pub enum Origin {
|
||||||
Def,
|
Def,
|
||||||
Call,
|
Call,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue