Encode disabled proc-macros via boolean flag, not special Expander

This commit is contained in:
Lukas Wirth 2024-02-12 13:34:38 +01:00
parent ab50ec9863
commit e2a985e93f
8 changed files with 91 additions and 148 deletions

View file

@ -18,7 +18,6 @@ use itertools::Itertools;
use proc_macro_api::{MacroDylib, ProcMacroServer};
use project_model::{CargoConfig, PackageRoot, ProjectManifest, ProjectWorkspace};
use span::Span;
use tt::DelimSpan;
use vfs::{file_set::FileSetConfig, loader::Handle, AbsPath, AbsPathBuf, VfsPath};
pub struct LoadCargoConfig {
@ -357,16 +356,8 @@ fn expander_to_proc_macro(
proc_macro_api::ProcMacroKind::FuncLike => ProcMacroKind::FuncLike,
proc_macro_api::ProcMacroKind::Attr => ProcMacroKind::Attr,
};
let expander: sync::Arc<dyn ProcMacroExpander> =
if ignored_macros.iter().any(|replace| &**replace == name) {
match kind {
ProcMacroKind::Attr => sync::Arc::new(IdentityExpander),
_ => sync::Arc::new(EmptyExpander),
}
} else {
sync::Arc::new(Expander(expander))
};
ProcMacro { name, kind, expander }
let disabled = ignored_macros.iter().any(|replace| **replace == name);
ProcMacro { name, kind, expander: sync::Arc::new(Expander(expander)), disabled }
}
#[derive(Debug)]
@ -391,48 +382,6 @@ impl ProcMacroExpander for Expander {
}
}
/// Dummy identity expander, used for attribute proc-macros that are deliberately ignored by the user.
#[derive(Debug)]
struct IdentityExpander;
impl ProcMacroExpander for IdentityExpander {
fn expand(
&self,
subtree: &tt::Subtree<Span>,
_: Option<&tt::Subtree<Span>>,
_: &Env,
_: Span,
_: Span,
_: Span,
) -> Result<tt::Subtree<Span>, ProcMacroExpansionError> {
Ok(subtree.clone())
}
fn should_expand(&self) -> bool {
false
}
}
/// Empty expander, used for proc-macros that are deliberately ignored by the user.
#[derive(Debug)]
struct EmptyExpander;
impl ProcMacroExpander for EmptyExpander {
fn expand(
&self,
_: &tt::Subtree<Span>,
_: Option<&tt::Subtree<Span>>,
_: &Env,
call_site: Span,
_: Span,
_: Span,
) -> Result<tt::Subtree<Span>, ProcMacroExpansionError> {
Ok(tt::Subtree::empty(DelimSpan { open: call_site, close: call_site }))
}
fn should_expand(&self) -> bool {
false
}
}
#[cfg(test)]
mod tests {
use ide_db::base_db::SourceDatabase;