From 550d7fbe3cbf2af4a47fca6c9bbefaf798cd7b7b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 12 Aug 2020 16:46:20 +0200 Subject: Rename ra_tt -> tt --- crates/ra_proc_macro/src/lib.rs | 17 ++++++++--------- crates/ra_proc_macro/src/msg.rs | 3 ++- crates/ra_proc_macro/src/process.rs | 38 ++++++++++++++++++------------------- crates/ra_proc_macro/src/rpc.rs | 13 +++++++------ 4 files changed, 35 insertions(+), 36 deletions(-) (limited to 'crates/ra_proc_macro/src') diff --git a/crates/ra_proc_macro/src/lib.rs b/crates/ra_proc_macro/src/lib.rs index 004943b9e..15db57eb2 100644 --- a/crates/ra_proc_macro/src/lib.rs +++ b/crates/ra_proc_macro/src/lib.rs @@ -9,8 +9,6 @@ mod rpc; mod process; pub mod msg; -use process::{ProcMacroProcessSrv, ProcMacroProcessThread}; -use ra_tt::{SmolStr, Subtree}; use std::{ ffi::OsStr, io, @@ -18,6 +16,10 @@ use std::{ sync::Arc, }; +use tt::{SmolStr, Subtree}; + +use crate::process::{ProcMacroProcessSrv, ProcMacroProcessThread}; + pub use rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind}; #[derive(Debug, Clone)] @@ -36,12 +38,12 @@ impl PartialEq for ProcMacroProcessExpander { } } -impl ra_tt::TokenExpander for ProcMacroProcessExpander { +impl tt::TokenExpander for ProcMacroProcessExpander { fn expand( &self, subtree: &Subtree, _attr: Option<&Subtree>, - ) -> Result { + ) -> Result { self.process.custom_derive(&self.dylib_path, subtree, &self.name) } } @@ -72,10 +74,7 @@ impl ProcMacroClient { ProcMacroClient { kind: ProcMacroClientKind::Dummy } } - pub fn by_dylib_path( - &self, - dylib_path: &Path, - ) -> Vec<(SmolStr, Arc)> { + pub fn by_dylib_path(&self, dylib_path: &Path) -> Vec<(SmolStr, Arc)> { match &self.kind { ProcMacroClientKind::Dummy => vec![], ProcMacroClientKind::Process { process, .. } => { @@ -94,7 +93,7 @@ impl ProcMacroClient { match kind { ProcMacroKind::CustomDerive => { let name = SmolStr::new(&name); - let expander: Arc = + let expander: Arc = Arc::new(ProcMacroProcessExpander { process: process.clone(), name: name.clone(), diff --git a/crates/ra_proc_macro/src/msg.rs b/crates/ra_proc_macro/src/msg.rs index 95d9b8804..f84ebdbc5 100644 --- a/crates/ra_proc_macro/src/msg.rs +++ b/crates/ra_proc_macro/src/msg.rs @@ -5,11 +5,12 @@ use std::{ io::{self, BufRead, Write}, }; +use serde::{de::DeserializeOwned, Deserialize, Serialize}; + use crate::{ rpc::{ListMacrosResult, ListMacrosTask}, ExpansionResult, ExpansionTask, }; -use serde::{de::DeserializeOwned, Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize, Clone)] pub enum Request { diff --git a/crates/ra_proc_macro/src/process.rs b/crates/ra_proc_macro/src/process.rs index 37dd3f496..51ffcaa78 100644 --- a/crates/ra_proc_macro/src/process.rs +++ b/crates/ra_proc_macro/src/process.rs @@ -1,21 +1,22 @@ //! Handle process life-time and message passing for proc-macro client -use crossbeam_channel::{bounded, Receiver, Sender}; -use ra_tt::Subtree; - -use crate::msg::{ErrorCode, Message, Request, Response, ResponseError}; -use crate::rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind}; - -use io::{BufRead, BufReader}; use std::{ convert::{TryFrom, TryInto}, ffi::{OsStr, OsString}, - io::{self, Write}, + io::{self, BufRead, BufReader, Write}, path::{Path, PathBuf}, process::{Child, Command, Stdio}, sync::{Arc, Weak}, }; +use crossbeam_channel::{bounded, Receiver, Sender}; +use tt::Subtree; + +use crate::{ + msg::{ErrorCode, Message, Request, Response, ResponseError}, + rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind}, +}; + #[derive(Debug, Default)] pub(crate) struct ProcMacroProcessSrv { inner: Option>>, @@ -50,7 +51,7 @@ impl ProcMacroProcessSrv { pub fn find_proc_macros( &self, dylib_path: &Path, - ) -> Result, ra_tt::ExpansionError> { + ) -> Result, tt::ExpansionError> { let task = ListMacrosTask { lib: dylib_path.to_path_buf() }; let result: ListMacrosResult = self.send_task(Request::ListMacro(task))?; @@ -62,7 +63,7 @@ impl ProcMacroProcessSrv { dylib_path: &Path, subtree: &Subtree, derive_name: &str, - ) -> Result { + ) -> Result { let task = ExpansionTask { macro_body: subtree.clone(), macro_name: derive_name.to_string(), @@ -74,38 +75,35 @@ impl ProcMacroProcessSrv { Ok(result.expansion) } - pub fn send_task(&self, req: Request) -> Result + pub fn send_task(&self, req: Request) -> Result where R: TryFrom, { let sender = match &self.inner { - None => return Err(ra_tt::ExpansionError::Unknown("No sender is found.".to_string())), + None => return Err(tt::ExpansionError::Unknown("No sender is found.".to_string())), Some(it) => it, }; let (result_tx, result_rx) = bounded(0); let sender = match sender.upgrade() { None => { - return Err(ra_tt::ExpansionError::Unknown("Proc macro process is closed.".into())) + return Err(tt::ExpansionError::Unknown("Proc macro process is closed.".into())) } Some(it) => it, }; sender.send(Task { req, result_tx }).unwrap(); let res = result_rx .recv() - .map_err(|_| ra_tt::ExpansionError::Unknown("Proc macro thread is closed.".into()))?; + .map_err(|_| tt::ExpansionError::Unknown("Proc macro thread is closed.".into()))?; match res { Some(Response::Error(err)) => { - return Err(ra_tt::ExpansionError::ExpansionError(err.message)); + return Err(tt::ExpansionError::ExpansionError(err.message)); } Some(res) => Ok(res.try_into().map_err(|err| { - ra_tt::ExpansionError::Unknown(format!( - "Fail to get response, reason : {:#?} ", - err - )) + tt::ExpansionError::Unknown(format!("Fail to get response, reason : {:#?} ", err)) })?), - None => Err(ra_tt::ExpansionError::Unknown("Empty result".into())), + None => Err(tt::ExpansionError::Unknown("Empty result".into())), } } } diff --git a/crates/ra_proc_macro/src/rpc.rs b/crates/ra_proc_macro/src/rpc.rs index 4ce485926..5e5d78d06 100644 --- a/crates/ra_proc_macro/src/rpc.rs +++ b/crates/ra_proc_macro/src/rpc.rs @@ -1,17 +1,18 @@ //! Data struture serialization related stuff for RPC //! //! Defines all necessary rpc serialization data structures, -//! which includes `ra_tt` related data and some task messages. -//! Although adding `Serialize` and `Deserialize` traits to `ra_tt` directly seems -//! to be much easier, we deliberately duplicate `ra_tt` structs with `#[serde(with = "XXDef")]` +//! which includes `tt` related data and some task messages. +//! Although adding `Serialize` and `Deserialize` traits to `tt` directly seems +//! to be much easier, we deliberately duplicate `tt` structs with `#[serde(with = "XXDef")]` //! for separation of code responsibility. -use ra_tt::{ +use std::path::PathBuf; + +use serde::{Deserialize, Serialize}; +use tt::{ Delimiter, DelimiterKind, Ident, Leaf, Literal, Punct, SmolStr, Spacing, Subtree, TokenId, TokenTree, }; -use serde::{Deserialize, Serialize}; -use std::path::PathBuf; #[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize)] pub struct ListMacrosTask { -- cgit v1.2.3