-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add request handling #1682
base: spr/main/2ceebe3f
Are you sure you want to change the base?
Add request handling #1682
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use serde::Serialize; | ||
|
||
#[derive(Serialize)] | ||
pub struct ErrResponse { | ||
message: String, | ||
} | ||
|
||
impl ErrResponse { | ||
pub fn new(message: String) -> Self { | ||
Self { message } | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please start adding tests for this system starting with this PR |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,41 @@ | ||
use crate::compiler::plugin::proc_macro::ProcMacroHost; | ||
use anyhow::Result; | ||
use anyhow::{anyhow, Result}; | ||
use connection::Connection; | ||
use json_rpc::ErrResponse; | ||
use proc_macro_server_api::RpcResponse; | ||
|
||
mod connection; | ||
mod json_rpc; | ||
|
||
pub fn start_proc_macro_server(proc_macros: ProcMacroHost) -> Result<()> { | ||
let connection = Connection::new(); | ||
|
||
//TODO | ||
for i in 0..4 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
let receiver = connection.receiver.clone(); | ||
let sender = connection.sender.clone(); | ||
|
||
std::thread::Builder::new() | ||
.name(format!("proc-macro-server-worker-thread-{i}")) | ||
.spawn(move || { | ||
for request in receiver { | ||
let response = match request.method.as_str() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the indentation is going crazy here, please:
|
||
//TODO add method handlers | ||
_ => Err(anyhow!("method not found")), | ||
}; | ||
|
||
let value = response.unwrap_or_else(|err| { | ||
serde_json::to_value(ErrResponse::new(err.to_string())).unwrap() | ||
}); | ||
let res = RpcResponse { | ||
id: request.id, | ||
value, | ||
}; | ||
|
||
sender.send(res).unwrap(); | ||
} | ||
}) | ||
.expect("failed to spawn thread"); | ||
} | ||
|
||
connection.join(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should probably reside in proc-macros-server-api crate. I made a related comment about this in that PR: #1678 (comment)