Remove deps on tt_mbe

This commit is contained in:
Edwin Cheng 2020-03-27 00:41:44 +08:00
parent 72e68d0caf
commit db162df264
10 changed files with 58 additions and 49 deletions

View file

@ -5,56 +5,29 @@
//! is used to provide basic infrastructure for communication between two
//! processes: Client (RA itself), Server (the external program)
use ra_mbe::ExpandError;
use ra_tt::Subtree;
use ra_tt::{SmolStr, Subtree};
use std::{
path::{Path, PathBuf},
sync::Arc,
};
trait ProcMacroExpander: std::fmt::Debug + Send + Sync + std::panic::RefUnwindSafe {
fn custom_derive(&self, subtree: &Subtree, derive_name: &str) -> Result<Subtree, ExpandError>;
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProcMacroProcessExpander {
process: Arc<ProcMacroProcessSrv>,
name: SmolStr,
}
impl ProcMacroExpander for ProcMacroProcessExpander {
fn custom_derive(
impl ra_tt::TokenExpander for ProcMacroProcessExpander {
fn expand(
&self,
_subtree: &Subtree,
_derive_name: &str,
) -> Result<Subtree, ExpandError> {
_attr: Option<&Subtree>,
) -> Result<Subtree, ra_tt::ExpansionError> {
// FIXME: do nothing for now
Ok(Subtree::default())
}
}
#[derive(Debug, Clone)]
pub struct ProcMacro {
expander: Arc<dyn ProcMacroExpander>,
name: String,
}
impl Eq for ProcMacro {}
impl PartialEq for ProcMacro {
fn eq(&self, other: &ProcMacro) -> bool {
self.name == other.name && Arc::ptr_eq(&self.expander, &other.expander)
}
}
impl ProcMacro {
pub fn name(&self) -> String {
self.name.clone()
}
pub fn custom_derive(&self, subtree: &Subtree) -> Result<Subtree, ExpandError> {
self.expander.custom_derive(subtree, &self.name)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProcMacroProcessSrv {
path: PathBuf,
@ -76,7 +49,10 @@ impl ProcMacroClient {
ProcMacroClient::Dummy
}
pub fn by_dylib_path(&self, _dylib_path: &Path) -> Vec<ProcMacro> {
pub fn by_dylib_path(
&self,
_dylib_path: &Path,
) -> Vec<(SmolStr, Arc<dyn ra_tt::TokenExpander>)> {
// FIXME: return empty for now
vec![]
}