rust/crates/ra_proc_macro/src/lib.rs

60 lines
1.5 KiB
Rust
Raw Normal View History

2020-03-18 07:56:46 -05:00
//! Client-side Proc-Macro crate
//!
//! We separate proc-macro expanding logic to an extern program to allow
//! different implementations (e.g. wasm or dylib loading). And this crate
2020-03-25 21:49:23 -05:00
//! is used to provide basic infrastructure for communication between two
//! processes: Client (RA itself), Server (the external program)
2020-03-18 07:56:46 -05:00
2020-03-26 11:41:44 -05:00
use ra_tt::{SmolStr, Subtree};
2020-03-18 07:56:46 -05:00
use std::{
path::{Path, PathBuf},
sync::Arc,
};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProcMacroProcessExpander {
2020-03-25 21:49:23 -05:00
process: Arc<ProcMacroProcessSrv>,
2020-03-26 11:41:44 -05:00
name: SmolStr,
2020-03-18 07:56:46 -05:00
}
2020-03-26 11:41:44 -05:00
impl ra_tt::TokenExpander for ProcMacroProcessExpander {
fn expand(
2020-03-18 07:56:46 -05:00
&self,
_subtree: &Subtree,
2020-03-26 11:41:44 -05:00
_attr: Option<&Subtree>,
) -> Result<Subtree, ra_tt::ExpansionError> {
2020-03-18 07:56:46 -05:00
// FIXME: do nothing for now
Ok(Subtree::default())
}
}
2020-03-25 21:49:23 -05:00
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProcMacroProcessSrv {
path: PathBuf,
}
2020-03-18 07:56:46 -05:00
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ProcMacroClient {
2020-03-25 21:49:23 -05:00
Process { process: Arc<ProcMacroProcessSrv> },
2020-03-18 07:56:46 -05:00
Dummy,
}
impl ProcMacroClient {
pub fn extern_process(process_path: &Path) -> ProcMacroClient {
2020-03-25 21:49:23 -05:00
let process = ProcMacroProcessSrv { path: process_path.into() };
ProcMacroClient::Process { process: Arc::new(process) }
2020-03-18 07:56:46 -05:00
}
pub fn dummy() -> ProcMacroClient {
ProcMacroClient::Dummy
}
2020-03-26 11:41:44 -05:00
pub fn by_dylib_path(
&self,
_dylib_path: &Path,
) -> Vec<(SmolStr, Arc<dyn ra_tt::TokenExpander>)> {
2020-03-18 07:56:46 -05:00
// FIXME: return empty for now
vec![]
2020-03-18 04:47:59 -05:00
}
}