Skip to content

Commit

Permalink
Fail spawning proc-macro servers when their api version is newer than…
Browse files Browse the repository at this point in the history
… r-a's
  • Loading branch information
Veykril committed Feb 3, 2023
1 parent c40b089 commit 8e998c4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/proc-macro-api/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::ProcMacroKind;
pub use crate::msg::flat::FlatTree;

pub const NO_VERSION_CHECK_VERSION: u32 = 0;
pub const API_VERSION: u32 = 1;
pub const CURRENT_API_VERSION: u32 = 1;

#[derive(Debug, Serialize, Deserialize)]
pub enum Request {
Expand Down
9 changes: 8 additions & 1 deletion crates/proc-macro-api/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use paths::{AbsPath, AbsPathBuf};
use stdx::JodChild;

use crate::{
msg::{Message, Request, Response},
msg::{Message, Request, Response, CURRENT_API_VERSION},
ProcMacroKind, ServerError,
};

Expand All @@ -36,6 +36,13 @@ impl ProcMacroProcessSrv {
let mut srv = create_srv()?;
tracing::info!("sending version check");
match srv.version_check() {
Ok(v) if v > CURRENT_API_VERSION => Err(io::Error::new(
io::ErrorKind::Other,
format!(
"proc-macro server's api version ({}) is newer than rust-analyzer's ({})",
v, CURRENT_API_VERSION
),
)),
Ok(v) => {
tracing::info!("got version {v}");
srv.version = v;
Expand Down
2 changes: 1 addition & 1 deletion crates/proc-macro-srv/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn run() -> io::Result<()> {
}
msg::Request::ExpandMacro(task) => msg::Response::ExpandMacro(srv.expand(task)),
msg::Request::ApiVersionCheck {} => {
msg::Response::ApiVersionCheck(proc_macro_api::msg::API_VERSION)
msg::Response::ApiVersionCheck(proc_macro_api::msg::CURRENT_API_VERSION)
}
};
write_response(res)?
Expand Down

0 comments on commit 8e998c4

Please sign in to comment.