save-analysis: Use serde instead of libserialize to dump JSON data

This commit is contained in:
Igor Matuszewski 2019-04-17 21:34:35 +02:00
parent 4d9c6cd722
commit 25451967ee
4 changed files with 11 additions and 9 deletions

View File

@ -2933,11 +2933,11 @@ dependencies = [
"rls-data 0.18.2 (registry+https://github.com/rust-lang/crates.io-index)", "rls-data 0.18.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rls-span 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "rls-span 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc 0.0.0", "rustc 0.0.0",
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_codegen_utils 0.0.0", "rustc_codegen_utils 0.0.0",
"rustc_data_structures 0.0.0", "rustc_data_structures 0.0.0",
"rustc_target 0.0.0", "rustc_target 0.0.0",
"rustc_typeck 0.0.0", "rustc_typeck 0.0.0",
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
"syntax 0.0.0", "syntax 0.0.0",
"syntax_pos 0.0.0", "syntax_pos 0.0.0",
] ]

View File

@ -16,9 +16,8 @@ rustc_data_structures = { path = "../librustc_data_structures" }
rustc_codegen_utils = { path = "../librustc_codegen_utils" } rustc_codegen_utils = { path = "../librustc_codegen_utils" }
rustc_target = { path = "../librustc_target" } rustc_target = { path = "../librustc_target" }
rustc_typeck = { path = "../librustc_typeck" } rustc_typeck = { path = "../librustc_typeck" }
serde_json = "1"
syntax = { path = "../libsyntax" } syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" } syntax_pos = { path = "../libsyntax_pos" }
rls-data = "0.18.1" rls-data = "0.18.1"
rls-span = "0.4" rls-span = "0.4"
# FIXME(#40527) should move rustc serialize out of tree
rustc-serialize = "0.3"

View File

@ -1,7 +1,5 @@
use std::io::Write; use std::io::Write;
use rustc_serialize::json::as_json;
use rls_data::config::Config; use rls_data::config::Config;
use rls_data::{self, Analysis, CompilationOptions, CratePreludeData, Def, DefKind, Impl, Import, use rls_data::{self, Analysis, CompilationOptions, CratePreludeData, Def, DefKind, Impl, Import,
MacroRef, Ref, RefKind, Relation}; MacroRef, Ref, RefKind, Relation};
@ -31,8 +29,8 @@ pub struct WriteOutput<'b, W: Write> {
impl<'b, W: Write> DumpOutput for WriteOutput<'b, W> { impl<'b, W: Write> DumpOutput for WriteOutput<'b, W> {
fn dump(&mut self, result: &Analysis) { fn dump(&mut self, result: &Analysis) {
if write!(self.output, "{}", as_json(&result)).is_err() { if let Err(e) = serde_json::to_writer(self.output.by_ref(), result) {
error!("Error writing output"); error!("Can't serialize save-analysis: {:?}", e);
} }
} }
} }

View File

@ -1141,10 +1141,15 @@ fn find_config(supplied: Option<Config>) -> Config {
if let Some(config) = supplied { if let Some(config) = supplied {
return config; return config;
} }
match env::var_os("RUST_SAVE_ANALYSIS_CONFIG") { match env::var_os("RUST_SAVE_ANALYSIS_CONFIG") {
Some(config_string) => rustc_serialize::json::decode(config_string.to_str().unwrap())
.expect("Could not deserialize save-analysis config"),
None => Config::default(), None => Config::default(),
Some(config) => config.to_str()
.ok_or(())
.map_err(|_| error!("`RUST_SAVE_ANALYSIS_CONFIG` isn't UTF-8"))
.and_then(|cfg| serde_json::from_str(cfg)
.map_err(|_| error!("Could not deserialize save-analysis config"))
).unwrap_or_default()
} }
} }