diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-08-12 15:49:48 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-08-12 15:49:48 +0100 |
commit | 6dba0e1c4de3b225556f7fce70518c8ebff170a6 (patch) | |
tree | 1bf923c652e0bdb325240e27bb07e3c552a1aa07 /crates/ra_proc_macro | |
parent | 147547e7b85e80e2e30aa1a5ba4d9d0969908398 (diff) | |
parent | 550d7fbe3cbf2af4a47fca6c9bbefaf798cd7b7b (diff) |
Merge #5725
5725: Rename ra_tt -> tt
r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_proc_macro')
-rw-r--r-- | crates/ra_proc_macro/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_proc_macro/src/lib.rs | 17 | ||||
-rw-r--r-- | crates/ra_proc_macro/src/msg.rs | 3 | ||||
-rw-r--r-- | crates/ra_proc_macro/src/process.rs | 38 | ||||
-rw-r--r-- | crates/ra_proc_macro/src/rpc.rs | 13 |
5 files changed, 36 insertions, 37 deletions
diff --git a/crates/ra_proc_macro/Cargo.toml b/crates/ra_proc_macro/Cargo.toml index c4b6e9e7b..d2d1bc228 100644 --- a/crates/ra_proc_macro/Cargo.toml +++ b/crates/ra_proc_macro/Cargo.toml | |||
@@ -10,7 +10,7 @@ license = "MIT OR Apache-2.0" | |||
10 | doctest = false | 10 | doctest = false |
11 | 11 | ||
12 | [dependencies] | 12 | [dependencies] |
13 | ra_tt = { path = "../ra_tt" } | 13 | tt = { path = "../tt" } |
14 | serde = { version = "1.0", features = ["derive"] } | 14 | serde = { version = "1.0", features = ["derive"] } |
15 | serde_json = "1.0" | 15 | serde_json = "1.0" |
16 | log = "0.4.8" | 16 | log = "0.4.8" |
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; | |||
9 | mod process; | 9 | mod process; |
10 | pub mod msg; | 10 | pub mod msg; |
11 | 11 | ||
12 | use process::{ProcMacroProcessSrv, ProcMacroProcessThread}; | ||
13 | use ra_tt::{SmolStr, Subtree}; | ||
14 | use std::{ | 12 | use std::{ |
15 | ffi::OsStr, | 13 | ffi::OsStr, |
16 | io, | 14 | io, |
@@ -18,6 +16,10 @@ use std::{ | |||
18 | sync::Arc, | 16 | sync::Arc, |
19 | }; | 17 | }; |
20 | 18 | ||
19 | use tt::{SmolStr, Subtree}; | ||
20 | |||
21 | use crate::process::{ProcMacroProcessSrv, ProcMacroProcessThread}; | ||
22 | |||
21 | pub use rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind}; | 23 | pub use rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind}; |
22 | 24 | ||
23 | #[derive(Debug, Clone)] | 25 | #[derive(Debug, Clone)] |
@@ -36,12 +38,12 @@ impl PartialEq for ProcMacroProcessExpander { | |||
36 | } | 38 | } |
37 | } | 39 | } |
38 | 40 | ||
39 | impl ra_tt::TokenExpander for ProcMacroProcessExpander { | 41 | impl tt::TokenExpander for ProcMacroProcessExpander { |
40 | fn expand( | 42 | fn expand( |
41 | &self, | 43 | &self, |
42 | subtree: &Subtree, | 44 | subtree: &Subtree, |
43 | _attr: Option<&Subtree>, | 45 | _attr: Option<&Subtree>, |
44 | ) -> Result<Subtree, ra_tt::ExpansionError> { | 46 | ) -> Result<Subtree, tt::ExpansionError> { |
45 | self.process.custom_derive(&self.dylib_path, subtree, &self.name) | 47 | self.process.custom_derive(&self.dylib_path, subtree, &self.name) |
46 | } | 48 | } |
47 | } | 49 | } |
@@ -72,10 +74,7 @@ impl ProcMacroClient { | |||
72 | ProcMacroClient { kind: ProcMacroClientKind::Dummy } | 74 | ProcMacroClient { kind: ProcMacroClientKind::Dummy } |
73 | } | 75 | } |
74 | 76 | ||
75 | pub fn by_dylib_path( | 77 | pub fn by_dylib_path(&self, dylib_path: &Path) -> Vec<(SmolStr, Arc<dyn tt::TokenExpander>)> { |
76 | &self, | ||
77 | dylib_path: &Path, | ||
78 | ) -> Vec<(SmolStr, Arc<dyn ra_tt::TokenExpander>)> { | ||
79 | match &self.kind { | 78 | match &self.kind { |
80 | ProcMacroClientKind::Dummy => vec![], | 79 | ProcMacroClientKind::Dummy => vec![], |
81 | ProcMacroClientKind::Process { process, .. } => { | 80 | ProcMacroClientKind::Process { process, .. } => { |
@@ -94,7 +93,7 @@ impl ProcMacroClient { | |||
94 | match kind { | 93 | match kind { |
95 | ProcMacroKind::CustomDerive => { | 94 | ProcMacroKind::CustomDerive => { |
96 | let name = SmolStr::new(&name); | 95 | let name = SmolStr::new(&name); |
97 | let expander: Arc<dyn ra_tt::TokenExpander> = | 96 | let expander: Arc<dyn tt::TokenExpander> = |
98 | Arc::new(ProcMacroProcessExpander { | 97 | Arc::new(ProcMacroProcessExpander { |
99 | process: process.clone(), | 98 | process: process.clone(), |
100 | name: name.clone(), | 99 | 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::{ | |||
5 | io::{self, BufRead, Write}, | 5 | io::{self, BufRead, Write}, |
6 | }; | 6 | }; |
7 | 7 | ||
8 | use serde::{de::DeserializeOwned, Deserialize, Serialize}; | ||
9 | |||
8 | use crate::{ | 10 | use crate::{ |
9 | rpc::{ListMacrosResult, ListMacrosTask}, | 11 | rpc::{ListMacrosResult, ListMacrosTask}, |
10 | ExpansionResult, ExpansionTask, | 12 | ExpansionResult, ExpansionTask, |
11 | }; | 13 | }; |
12 | use serde::{de::DeserializeOwned, Deserialize, Serialize}; | ||
13 | 14 | ||
14 | #[derive(Debug, Serialize, Deserialize, Clone)] | 15 | #[derive(Debug, Serialize, Deserialize, Clone)] |
15 | pub enum Request { | 16 | 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 @@ | |||
1 | //! Handle process life-time and message passing for proc-macro client | 1 | //! Handle process life-time and message passing for proc-macro client |
2 | 2 | ||
3 | use crossbeam_channel::{bounded, Receiver, Sender}; | ||
4 | use ra_tt::Subtree; | ||
5 | |||
6 | use crate::msg::{ErrorCode, Message, Request, Response, ResponseError}; | ||
7 | use crate::rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind}; | ||
8 | |||
9 | use io::{BufRead, BufReader}; | ||
10 | use std::{ | 3 | use std::{ |
11 | convert::{TryFrom, TryInto}, | 4 | convert::{TryFrom, TryInto}, |
12 | ffi::{OsStr, OsString}, | 5 | ffi::{OsStr, OsString}, |
13 | io::{self, Write}, | 6 | io::{self, BufRead, BufReader, Write}, |
14 | path::{Path, PathBuf}, | 7 | path::{Path, PathBuf}, |
15 | process::{Child, Command, Stdio}, | 8 | process::{Child, Command, Stdio}, |
16 | sync::{Arc, Weak}, | 9 | sync::{Arc, Weak}, |
17 | }; | 10 | }; |
18 | 11 | ||
12 | use crossbeam_channel::{bounded, Receiver, Sender}; | ||
13 | use tt::Subtree; | ||
14 | |||
15 | use crate::{ | ||
16 | msg::{ErrorCode, Message, Request, Response, ResponseError}, | ||
17 | rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind}, | ||
18 | }; | ||
19 | |||
19 | #[derive(Debug, Default)] | 20 | #[derive(Debug, Default)] |
20 | pub(crate) struct ProcMacroProcessSrv { | 21 | pub(crate) struct ProcMacroProcessSrv { |
21 | inner: Option<Weak<Sender<Task>>>, | 22 | inner: Option<Weak<Sender<Task>>>, |
@@ -50,7 +51,7 @@ impl ProcMacroProcessSrv { | |||
50 | pub fn find_proc_macros( | 51 | pub fn find_proc_macros( |
51 | &self, | 52 | &self, |
52 | dylib_path: &Path, | 53 | dylib_path: &Path, |
53 | ) -> Result<Vec<(String, ProcMacroKind)>, ra_tt::ExpansionError> { | 54 | ) -> Result<Vec<(String, ProcMacroKind)>, tt::ExpansionError> { |
54 | let task = ListMacrosTask { lib: dylib_path.to_path_buf() }; | 55 | let task = ListMacrosTask { lib: dylib_path.to_path_buf() }; |
55 | 56 | ||
56 | let result: ListMacrosResult = self.send_task(Request::ListMacro(task))?; | 57 | let result: ListMacrosResult = self.send_task(Request::ListMacro(task))?; |
@@ -62,7 +63,7 @@ impl ProcMacroProcessSrv { | |||
62 | dylib_path: &Path, | 63 | dylib_path: &Path, |
63 | subtree: &Subtree, | 64 | subtree: &Subtree, |
64 | derive_name: &str, | 65 | derive_name: &str, |
65 | ) -> Result<Subtree, ra_tt::ExpansionError> { | 66 | ) -> Result<Subtree, tt::ExpansionError> { |
66 | let task = ExpansionTask { | 67 | let task = ExpansionTask { |
67 | macro_body: subtree.clone(), | 68 | macro_body: subtree.clone(), |
68 | macro_name: derive_name.to_string(), | 69 | macro_name: derive_name.to_string(), |
@@ -74,38 +75,35 @@ impl ProcMacroProcessSrv { | |||
74 | Ok(result.expansion) | 75 | Ok(result.expansion) |
75 | } | 76 | } |
76 | 77 | ||
77 | pub fn send_task<R>(&self, req: Request) -> Result<R, ra_tt::ExpansionError> | 78 | pub fn send_task<R>(&self, req: Request) -> Result<R, tt::ExpansionError> |
78 | where | 79 | where |
79 | R: TryFrom<Response, Error = &'static str>, | 80 | R: TryFrom<Response, Error = &'static str>, |
80 | { | 81 | { |
81 | let sender = match &self.inner { | 82 | let sender = match &self.inner { |
82 | None => return Err(ra_tt::ExpansionError::Unknown("No sender is found.".to_string())), | 83 | None => return Err(tt::ExpansionError::Unknown("No sender is found.".to_string())), |
83 | Some(it) => it, | 84 | Some(it) => it, |
84 | }; | 85 | }; |
85 | 86 | ||
86 | let (result_tx, result_rx) = bounded(0); | 87 | let (result_tx, result_rx) = bounded(0); |
87 | let sender = match sender.upgrade() { | 88 | let sender = match sender.upgrade() { |
88 | None => { | 89 | None => { |
89 | return Err(ra_tt::ExpansionError::Unknown("Proc macro process is closed.".into())) | 90 | return Err(tt::ExpansionError::Unknown("Proc macro process is closed.".into())) |
90 | } | 91 | } |
91 | Some(it) => it, | 92 | Some(it) => it, |
92 | }; | 93 | }; |
93 | sender.send(Task { req, result_tx }).unwrap(); | 94 | sender.send(Task { req, result_tx }).unwrap(); |
94 | let res = result_rx | 95 | let res = result_rx |
95 | .recv() | 96 | .recv() |
96 | .map_err(|_| ra_tt::ExpansionError::Unknown("Proc macro thread is closed.".into()))?; | 97 | .map_err(|_| tt::ExpansionError::Unknown("Proc macro thread is closed.".into()))?; |
97 | 98 | ||
98 | match res { | 99 | match res { |
99 | Some(Response::Error(err)) => { | 100 | Some(Response::Error(err)) => { |
100 | return Err(ra_tt::ExpansionError::ExpansionError(err.message)); | 101 | return Err(tt::ExpansionError::ExpansionError(err.message)); |
101 | } | 102 | } |
102 | Some(res) => Ok(res.try_into().map_err(|err| { | 103 | Some(res) => Ok(res.try_into().map_err(|err| { |
103 | ra_tt::ExpansionError::Unknown(format!( | 104 | tt::ExpansionError::Unknown(format!("Fail to get response, reason : {:#?} ", err)) |
104 | "Fail to get response, reason : {:#?} ", | ||
105 | err | ||
106 | )) | ||
107 | })?), | 105 | })?), |
108 | None => Err(ra_tt::ExpansionError::Unknown("Empty result".into())), | 106 | None => Err(tt::ExpansionError::Unknown("Empty result".into())), |
109 | } | 107 | } |
110 | } | 108 | } |
111 | } | 109 | } |
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 @@ | |||
1 | //! Data struture serialization related stuff for RPC | 1 | //! Data struture serialization related stuff for RPC |
2 | //! | 2 | //! |
3 | //! Defines all necessary rpc serialization data structures, | 3 | //! Defines all necessary rpc serialization data structures, |
4 | //! which includes `ra_tt` related data and some task messages. | 4 | //! which includes `tt` related data and some task messages. |
5 | //! Although adding `Serialize` and `Deserialize` traits to `ra_tt` directly seems | 5 | //! Although adding `Serialize` and `Deserialize` traits to `tt` directly seems |
6 | //! to be much easier, we deliberately duplicate `ra_tt` structs with `#[serde(with = "XXDef")]` | 6 | //! to be much easier, we deliberately duplicate `tt` structs with `#[serde(with = "XXDef")]` |
7 | //! for separation of code responsibility. | 7 | //! for separation of code responsibility. |
8 | 8 | ||
9 | use ra_tt::{ | 9 | use std::path::PathBuf; |
10 | |||
11 | use serde::{Deserialize, Serialize}; | ||
12 | use tt::{ | ||
10 | Delimiter, DelimiterKind, Ident, Leaf, Literal, Punct, SmolStr, Spacing, Subtree, TokenId, | 13 | Delimiter, DelimiterKind, Ident, Leaf, Literal, Punct, SmolStr, Spacing, Subtree, TokenId, |
11 | TokenTree, | 14 | TokenTree, |
12 | }; | 15 | }; |
13 | use serde::{Deserialize, Serialize}; | ||
14 | use std::path::PathBuf; | ||
15 | 16 | ||
16 | #[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize)] | 17 | #[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize)] |
17 | pub struct ListMacrosTask { | 18 | pub struct ListMacrosTask { |