Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit e100664

Browse files
committed
Add serde implementation to complement rustc-serialize
We want to transition off of rustc-serialize and onto serde, so this commit sets up both to co-exist, gated by feature flags. Due to the fact that they implement the same functions, only one feature flag can be active at a time. To compile rls-analysis with serde, it is necessary to run cargo build with the `--no-default-features` flag and the `--features "serialize-serde"` flag. The tests in this commit will still work with the default feature flags but will need to be changed before the serde implementation can pass tests.
1 parent 6a1b5a9 commit e100664

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

rls-analysis/Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,22 @@ exclude = [
1111
]
1212

1313
[dependencies]
14-
rustc-serialize = "0.3"
14+
rustc-serialize = { version = "0.3", optional = true }
1515
log = "0.4"
1616
rls-data = "= 0.18.2"
1717
rls-span = "0.4"
1818
derive-new = "0.5"
1919
fst = { version = "0.3", default-features = false }
2020
itertools = "0.7.3"
2121
json = "0.11.13"
22+
serde = { version = "1.0", optional = true }
23+
serde_json = { version = "1.0", optional = true }
2224

2325
[dev-dependencies]
2426
lazy_static = "1"
2527
env_logger = "0.5"
28+
29+
[features]
30+
default = ["serialize-rustc"]
31+
serialize-rustc = ["rustc-serialize", "rls-data/serialize-rustc", "rls-span/serialize-rustc"]
32+
serialize-serde = ["serde", "serde_json", "rls-data/serialize-serde", "rls-span/serialize-serde"]

rls-analysis/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ extern crate itertools;
1515
extern crate json;
1616
extern crate rls_data as data;
1717
extern crate rls_span as span;
18+
#[cfg(feature = "serialize-rustc")]
1819
extern crate rustc_serialize;
20+
#[cfg(feature = "serialize-serde")]
21+
extern crate serde;
22+
#[cfg(feature = "serialize-serde")]
23+
extern crate serde_json;
1924

2025
mod analysis;
2126
mod listings;

rls-analysis/src/raw.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn read_crate_data(path: &Path) -> Option<Analysis> {
123123
Err(err)
124124
})
125125
.ok()?;
126-
let s = ::rustc_serialize::json::decode(&buf)
126+
let s = read_analysis(&buf)
127127
.or_else(|err| {
128128
warn!("deserialisation error: {:?}", err);
129129
json::parse(&buf)
@@ -157,6 +157,16 @@ fn read_crate_data(path: &Path) -> Option<Analysis> {
157157
s
158158
}
159159

160+
#[cfg(feature = "serialize-rustc")]
161+
fn read_analysis(buf: &String) -> Result<Option<Analysis>, rustc_serialize::json::DecoderError> {
162+
::rustc_serialize::json::decode(&buf)
163+
}
164+
165+
#[cfg(feature = "serialize-serde")]
166+
fn read_analysis(buf: &String) -> Result<Option<Analysis>, serde_json::Error> {
167+
::serde_json::from_str(buf)
168+
}
169+
160170
pub fn name_space_for_def_kind(dk: DefKind) -> char {
161171
match dk {
162172
DefKind::Enum

0 commit comments

Comments
 (0)