Skip to content

Commit

Permalink
Rollup merge of rust-lang#113556 - cuviper:trim-rls, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Don't use serde-derive in the rls shim

The already-small RLS shim can get a little smaller, and faster to
build, if we drop the serde-derive dependency and decode the one
"method" field it needs manually from `serde_json::Value`.
  • Loading branch information
matthiaskrgr authored Jul 10, 2023
2 parents 40b1c5b + dd5fa7d commit ad4f303
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3021,7 +3021,6 @@ dependencies = [
name = "rls"
version = "2.0.0"
dependencies = [
"serde",
"serde_json",
]

Expand Down
1 change: 0 additions & 1 deletion src/tools/rls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ edition = "2021"
license = "Apache-2.0/MIT"

[dependencies]
serde = { version = "1.0.143", features = ["derive"] }
serde_json = "1.0.83"
9 changes: 5 additions & 4 deletions src/tools/rls/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! This is a small stub that replaces RLS to alert the user that RLS is no
//! longer available.
use serde::Deserialize;
use serde_json::Value;
use std::error::Error;
use std::io::BufRead;
use std::io::Write;
Expand All @@ -21,7 +21,6 @@ fn main() {
}
}

#[derive(Deserialize)]
struct Message {
method: Option<String>,
}
Expand Down Expand Up @@ -88,8 +87,10 @@ fn read_message_raw<R: BufRead>(reader: &mut R) -> Result<String, Box<dyn Error>

fn read_message<R: BufRead>(reader: &mut R) -> Result<Message, Box<dyn Error>> {
let m = read_message_raw(reader)?;
match serde_json::from_str(&m) {
Ok(m) => Ok(m),
match serde_json::from_str::<Value>(&m) {
Ok(message) => Ok(Message {
method: message.get("method").and_then(|value| value.as_str().map(String::from)),
}),
Err(e) => Err(format!("failed to parse message {m}\n{e}").into()),
}
}
Expand Down

0 comments on commit ad4f303

Please sign in to comment.