aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_proc_macro/src
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2020-03-31 15:01:34 +0100
committerEdwin Cheng <[email protected]>2020-03-31 15:20:19 +0100
commit02b849a2a038aee69f9997ace0295b30d8ce4c83 (patch)
treef7d191433e835b5985560842ead4dd226b9aea3b /crates/ra_proc_macro/src
parentf461dc48d116a97188ae6d9934c8e3b421c335ac (diff)
Refactor a bit
Diffstat (limited to 'crates/ra_proc_macro/src')
-rw-r--r--crates/ra_proc_macro/src/process.rs20
1 files changed, 9 insertions, 11 deletions
diff --git a/crates/ra_proc_macro/src/process.rs b/crates/ra_proc_macro/src/process.rs
index b44d6763c..df4d61682 100644
--- a/crates/ra_proc_macro/src/process.rs
+++ b/crates/ra_proc_macro/src/process.rs
@@ -29,7 +29,7 @@ pub(crate) struct ProcMacroProcessThread {
29 29
30struct Task { 30struct Task {
31 req: Request, 31 req: Request,
32 result_tx: Sender<Response>, 32 result_tx: Sender<Option<Response>>,
33} 33}
34 34
35struct Process { 35struct Process {
@@ -131,18 +131,21 @@ impl ProcMacroProcessSrv {
131 Some(it) => it, 131 Some(it) => it,
132 }; 132 };
133 sender.send(Task { req: req.into(), result_tx }).unwrap(); 133 sender.send(Task { req: req.into(), result_tx }).unwrap();
134 let res = result_rx
135 .recv()
136 .map_err(|_| ra_tt::ExpansionError::Unknown("Proc macro thread is closed.".into()))?;
134 137
135 let res = result_rx.recv().unwrap();
136 match res { 138 match res {
137 Response::Error(err) => { 139 Some(Response::Error(err)) => {
138 return Err(ra_tt::ExpansionError::ExpansionError(err.message)); 140 return Err(ra_tt::ExpansionError::ExpansionError(err.message));
139 } 141 }
140 _ => Ok(res.try_into().map_err(|err| { 142 Some(res) => Ok(res.try_into().map_err(|err| {
141 ra_tt::ExpansionError::Unknown(format!( 143 ra_tt::ExpansionError::Unknown(format!(
142 "Fail to get response, reason : {:#?} ", 144 "Fail to get response, reason : {:#?} ",
143 err 145 err
144 )) 146 ))
145 })?), 147 })?),
148 None => Err(ra_tt::ExpansionError::Unknown("Empty result".into())),
146 } 149 }
147 } 150 }
148} 151}
@@ -156,8 +159,8 @@ fn client_loop(task_rx: Receiver<Task>, mut process: Process) {
156 for task in task_rx { 159 for task in task_rx {
157 let Task { req, result_tx } = task; 160 let Task { req, result_tx } = task;
158 161
159 let res = match send_request(&mut stdin, &mut stdout, req) { 162 match send_request(&mut stdin, &mut stdout, req) {
160 Ok(res) => res, 163 Ok(res) => result_tx.send(res).unwrap(),
161 Err(_err) => { 164 Err(_err) => {
162 let res = Response::Error(ResponseError { 165 let res = Response::Error(ResponseError {
163 code: ErrorCode::ServerErrorEnd, 166 code: ErrorCode::ServerErrorEnd,
@@ -174,12 +177,7 @@ fn client_loop(task_rx: Receiver<Task>, mut process: Process) {
174 }; 177 };
175 stdin = stdio.0; 178 stdin = stdio.0;
176 stdout = stdio.1; 179 stdout = stdio.1;
177 continue;
178 } 180 }
179 };
180
181 if let Some(res) = res {
182 result_tx.send(res).unwrap();
183 } 181 }
184 } 182 }
185} 183}