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

Commit 3fd923f

Browse files
committed
rls-span: Bring back optional rustc-serialize support
This is to reduce churn on Racer side in case the switch to serde in the compiler won't go as planned.
1 parent 1499f37 commit 3fd923f

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

rls-span/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ categories = ["development-tools"]
1010

1111

1212
[dependencies]
13+
rustc-serialize = { version = "0.3.24", optional = true }
1314
serde = "1.0"
1415
serde_derive = { version = "1.0", optional = true }
1516

1617
[features]
1718
default = []
19+
serialize-rustc = ["rustc-serialize"]
1820
derive = ["serde_derive"]

rls-span/src/compiler.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::path::PathBuf;
66
use crate::{Column, OneIndexed, Row, Span};
77

88
#[cfg_attr(feature = "derive", derive(Deserialize))]
9+
#[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable))]
910
#[derive(Debug, Clone)]
1011
pub struct DiagnosticSpan {
1112
pub file_name: String,
@@ -46,6 +47,7 @@ impl DiagnosticSpan {
4647
}
4748

4849
#[cfg_attr(feature = "derive", derive(Deserialize))]
50+
#[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable))]
4951
#[derive(Debug, Clone)]
5052
pub struct DiagnosticSpanLine {
5153
pub text: String,
@@ -57,6 +59,7 @@ pub struct DiagnosticSpanLine {
5759
}
5860

5961
#[cfg_attr(feature = "derive", derive(Deserialize))]
62+
#[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable))]
6063
#[derive(Debug, Clone)]
6164
pub struct DiagnosticSpanMacroExpansion {
6265
/// span where macro was applied to generate this code; note that

rls-span/src/lib.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ impl<'dt, I: Indexed> Deserialize<'dt> for Column<I> {
4444
}
4545
}
4646

47+
#[cfg(feature = "serialize-rustc")]
48+
impl<I: Indexed> rustc_serialize::Decodable for Column<I> {
49+
fn decode<D: rustc_serialize::Decoder>(d: &mut D) -> Result<Column<I>, D::Error> {
50+
d.read_u32().map(Column::new)
51+
}
52+
}
53+
54+
#[cfg(feature = "serialize-rustc")]
55+
impl<I: Indexed> rustc_serialize::Encodable for Column<I> {
56+
fn encode<S: rustc_serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
57+
s.emit_u32(self.0)
58+
}
59+
}
60+
4761
impl Column<OneIndexed> {
4862
pub fn new_one_indexed(c: u32) -> Column<OneIndexed> {
4963
Column(c, PhantomData)
@@ -93,6 +107,20 @@ impl<'dt, I: Indexed> serde::Deserialize<'dt> for Row<I> {
93107
}
94108
}
95109

110+
#[cfg(feature = "serialize-rustc")]
111+
impl<I: Indexed> rustc_serialize::Decodable for Row<I> {
112+
fn decode<D: rustc_serialize::Decoder>(d: &mut D) -> Result<Row<I>, D::Error> {
113+
d.read_u32().map(Row::new)
114+
}
115+
}
116+
117+
#[cfg(feature = "serialize-rustc")]
118+
impl<I: Indexed> rustc_serialize::Encodable for Row<I> {
119+
fn encode<S: rustc_serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
120+
s.emit_u32(self.0)
121+
}
122+
}
123+
96124
impl Row<OneIndexed> {
97125
pub fn new_one_indexed(c: u32) -> Row<OneIndexed> {
98126
Row(c, PhantomData)
@@ -114,6 +142,7 @@ impl Row<ZeroIndexed> {
114142
}
115143

116144
#[cfg_attr(feature = "derive", derive(Serialize, Deserialize))]
145+
#[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
117146
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
118147
pub struct Position<I: Indexed> {
119148
pub row: Row<I>,
@@ -147,6 +176,7 @@ impl Position<ZeroIndexed> {
147176
}
148177

149178
#[cfg_attr(feature = "derive", derive(Serialize, Deserialize))]
179+
#[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
150180
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
151181
pub struct Range<I: Indexed> {
152182
pub row_start: Row<I>,
@@ -209,6 +239,7 @@ impl Range<ZeroIndexed> {
209239
}
210240

211241
#[cfg_attr(feature = "derive", derive(Serialize, Deserialize))]
242+
#[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
212243
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
213244
pub struct Location<I: Indexed> {
214245
pub file: PathBuf,
@@ -244,6 +275,7 @@ impl Location<ZeroIndexed> {
244275
}
245276

246277
#[cfg_attr(feature = "derive", derive(Serialize, Deserialize))]
278+
#[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
247279
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
248280
pub struct Span<I: Indexed> {
249281
pub file: PathBuf,
@@ -295,11 +327,13 @@ impl Span<ZeroIndexed> {
295327
pub trait Indexed {}
296328

297329
#[cfg_attr(feature = "derive", derive(Serialize, Deserialize))]
330+
#[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
298331
#[derive(Hash, PartialEq, Eq, Debug, PartialOrd, Ord)]
299332
pub struct ZeroIndexed;
300333
impl Indexed for ZeroIndexed {}
301334

302335
#[cfg_attr(feature = "derive", derive(Serialize, Deserialize))]
336+
#[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
303337
#[derive(Hash, PartialEq, Eq, Debug, PartialOrd, Ord)]
304338
pub struct OneIndexed;
305339
impl Indexed for OneIndexed {}

0 commit comments

Comments
 (0)