Fail spawning proc-macro servers when their api version is newer than r-a's

This commit is contained in:
Lukas Wirth 2023-02-03 10:38:38 +01:00
parent c40b0895f0
commit 8e998c4aa7
3 changed files with 10 additions and 3 deletions

View File

@ -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 {

View File

@ -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,
};
@ -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;

View File

@ -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)?