Skip to content

Commit 41eddb6

Browse files
committed
Fixes remainder of issues with serde + DocChars changes. Pinned to custom serde now.
1 parent 1c2fa2c commit 41eddb6

File tree

15 files changed

+415
-260
lines changed

15 files changed

+415
-260
lines changed

Cargo.lock

+278-186
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

edit-client/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ matches = "0.1.6"
1919
pulldown-cmark = "0.1.2"
2020
pulldown-cmark-to-cmark = "1.1.0"
2121
rand = "0.4"
22-
ron = "0.2"
22+
ron = "0.4"
2323
serde = "^1.0.27"
2424
serde_derive = "^1.0.27"
2525
serde_json = "^1.0.6"

edit-common/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pulldown-cmark = "0.1.2"
1616
pulldown-cmark-to-cmark = "1.1.0"
1717
rand = "0.4"
1818
regex = "1"
19-
ron = "0.2"
19+
ron = "0.4"
2020
serde = "1.0.27"
2121
serde_derive = "1.0.27"
2222
serde_json = "1.0.6"

edit-server/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ md5 = "0.3.7"
1818
mime_guess = "1.8.4"
1919
pulldown-cmark = "0.1.2"
2020
pulldown-cmark-to-cmark = "1.1.0"
21-
quicli = "0.3"
21+
quicli = "0.4"
2222
r2d2 = "0.8.2"
2323
r2d2-diesel = "1.0.0"
2424
open = "1.2.2"
2525
rand = "0.4"
2626
reqwest = "0.8.5"
27-
ron = "0.2"
27+
ron = "0.4"
2828
libsqlite3-sys = { version = "*", features = ["bundled"] }
2929
serde = "1.0.27"
3030
serde_derive = "1.0.27"

edit-server/src/bin/edit-server-logs.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
#![feature(extern_in_paths)]
2-
3-
#[macro_use]
4-
extern crate quicli;
5-
61
use serde_json;
7-
2+
use failure::*;
83
use edit_server::db::*;
9-
use quicli::prelude::*;
4+
use structopt::*;
5+
use diesel::connection::Connection;
106

117
#[derive(Debug, StructOpt)]
128
enum Cli {
@@ -20,8 +16,8 @@ enum Cli {
2016
Clear,
2117
}
2218

23-
main!(|args: Cli| {
24-
use diesel::connection::Connection;
19+
fn main() -> Result<(), Error> {
20+
let args = Cli::from_args();
2521

2622
let db = db_connection();
2723

@@ -46,4 +42,6 @@ main!(|args: Cli| {
4642
}
4743
}
4844
}
49-
});
45+
46+
Ok(())
47+
}

edit-server/src/bin/edit-server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ fn run_http_server(port: u16, client_proxy: bool) {
385385
&get_or_create_page_graphql(
386386
&id,
387387
&Doc(doc_span![DocGroup({"tag": "h1"}, [DocChars(&id)])]),
388-
).unwrap().0
388+
).expect("Received malformed content from db, aborting").0
389389
).unwrap();
390390

391391
let payload = reg.render_template(&template, &json!({

oatie/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ failure = "0.1.1"
1414
log = "0.3.1"
1515
maplit = "1.0.0"
1616
regex = "0.2.10"
17-
ron = "0.2.0"
18-
serde = "1.0"
19-
serde_derive = "1.0"
17+
ron = "0.4"
18+
serde = "^1.0.82"
19+
serde_derive = "1"
2020
serde_json = "1.0"
2121
term-painter = "0.2.2"
2222
yansi = "0.3.4"

oatie/src/core/apply.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use super::doc::*;
44
use crate::stepper::*;
5+
use crate::style::*;
56

67
fn apply_add_inner<M: DocMutator>(
78
bc: &mut M,
@@ -53,7 +54,7 @@ fn apply_add_inner<M: DocMutator>(
5354
d = AddStyles(count - value.char_len(), styles.clone());
5455
chars_styles.extend(&styles);
5556
bc.delete(1);
56-
bc.InsertDocString(value.clone());
57+
bc.InsertDocString(value.clone(), OpaqueStyleMap::from(styles.clone()));
5758
// partial = false;
5859
res.place(&DocChars(value, chars_styles));
5960
nextdel = false;
@@ -62,15 +63,15 @@ fn apply_add_inner<M: DocMutator>(
6263
let mut left_styles = chars_styles.clone();
6364
left_styles.extend(&styles);
6465
bc.delete(1);
65-
bc.InsertDocString(left.clone());
66+
bc.InsertDocString(left.clone(), OpaqueStyleMap::from(styles.clone()));
6667
// partial = false;
6768
res.place(&DocChars(left, left_styles));
6869
first = Some(DocChars(right, chars_styles));
6970
nextfirst = false;
7071
} else {
7172
chars_styles.extend(&styles);
7273
bc.delete(1);
73-
bc.InsertDocString(value.clone());
74+
bc.InsertDocString(value.clone(), OpaqueStyleMap::from(styles.clone()));
7475
// partial = false;
7576
res.place(&DocChars(value, chars_styles));
7677
}
@@ -121,7 +122,7 @@ fn apply_add_inner<M: DocMutator>(
121122
AddChars(value, styles) => {
122123
// TODO where do you skip anything, exactly
123124
// need to manifest the place issue externally as well
124-
bc.InsertDocString(value.clone());
125+
bc.InsertDocString(value.clone(), styles.clone());
125126
res.place(&DocChars(value, styles));
126127
nextfirst = false;
127128
}
@@ -261,22 +262,22 @@ fn apply_del_inner<M: DocMutator>(bc: &mut M, spanvec: &DocSpan, addvec: &DelSpa
261262
d = DelStyles(count - value.char_len(), styles.clone());
262263
chars_styles.remove(&styles);
263264
bc.delete(1);
264-
bc.InsertDocString(value.clone());
265+
bc.InsertDocString(value.clone(), chars_styles.clone());
265266
res.place(&DocChars(value, chars_styles));
266267
nextdel = false;
267268
} else if value.char_len() > count {
268269
let (left, right) = value.split_at(count);
269270
let mut left_styles = chars_styles.clone();
270271
left_styles.remove(&styles);
271272
bc.delete(1);
272-
bc.InsertDocString(left.clone());
273+
bc.InsertDocString(left.clone(), chars_styles.clone());
273274
res.place(&DocChars(left, chars_styles.clone()));
274275
first = DocChars(right, chars_styles);
275276
nextfirst = false;
276277
} else {
277278
chars_styles.remove(&styles);
278279
bc.delete(1);
279-
bc.InsertDocString(value.clone());
280+
bc.InsertDocString(value.clone(), chars_styles.clone());
280281
res.place(&DocChars(value, chars_styles));
281282
}
282283
}

oatie/src/core/doc.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,14 @@ pub type CurSpan = Vec<CurElement>;
2020

2121
pub type Op = (DelSpan, AddSpan);
2222

23-
fn style_map_is_empty(map: &OpaqueStyleMap) -> bool {
23+
/// Returns true if the style map can be omitted.
24+
fn is_stylemap_empty(map: &OpaqueStyleMap) -> bool {
2425
map.iter().count() == 0
2526
}
2627

27-
// fn docchars_deserialize<'de, D>(mut d: D) -> Result<(DocString, OpaqueStyleMap), D::Error>
28-
// where D: Deserializer<'de> + Clone
29-
// {
30-
// <(DocString, OpaqueStyleMap) as Deserialize>::deserialize(d)
31-
// .or_else(|_| <DocString as Deserialize>::deserialize(d).map(|string| (string, OpaqueStyleMap::new())))
32-
// }
33-
34-
use serde::de::Deserializer;
35-
3628
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
3729
pub enum DocElement {
38-
// #[serde(deserialize_with = "docchars_deserialize")]
39-
DocChars(DocString, #[serde(skip_serializing_if = "style_map_is_empty", skip_deserializing)] OpaqueStyleMap),
30+
DocChars(DocString, #[serde(default, skip_serializing_if = "is_stylemap_empty")] OpaqueStyleMap),
4031
DocGroup(Attrs, DocSpan),
4132
}
4233

@@ -45,6 +36,10 @@ pub use self::DocElement::*;
4536
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
4637
pub struct Doc(pub Vec<DocElement>);
4738

39+
40+
41+
// [DocChars("birds snakes and aeroplanes",[Bold,],),]
42+
4843
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
4944
pub enum DelElement {
5045
DelSkip(usize),
@@ -65,8 +60,7 @@ pub use self::DelElement::*;
6560
pub enum AddElement {
6661
AddSkip(usize),
6762
AddWithGroup(AddSpan),
68-
// #[serde(deserialize_with = "docchars_deserialize")]
69-
AddChars(DocString, #[serde(skip_serializing_if = "style_map_is_empty", skip_deserializing)] OpaqueStyleMap),
63+
AddChars(DocString, #[serde(default, skip_serializing_if = "is_stylemap_empty")] OpaqueStyleMap),
7064
AddGroup(Attrs, AddSpan),
7165
AddStyles(usize, StyleMap),
7266
}

oatie/src/core/style.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<'de> Deserialize<'de> for OpaqueStyleMap {
5252
where
5353
D: Deserializer<'de>,
5454
{
55-
Ok(OpaqueStyleMap::from(StyleMap::deserialize(deserializer)?))
55+
Ok(OpaqueStyleMap::from(StyleSet::deserialize(deserializer)?.into_iter().map(|k| (k, None)).collect()))
5656
}
5757
}
5858

oatie/src/stepper/docmutator.rs

+25-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::*;
22
use wasm_bindgen::prelude::*;
3+
use crate::style::*;
34

45
impl Program {
56
pub fn new() -> Program {
@@ -64,7 +65,7 @@ pub trait DocMutator {
6465
unimplemented!();
6566
}
6667

67-
fn InsertDocString(&mut self, _docstring: DocString) {
68+
fn InsertDocString(&mut self, _docstring: DocString, _styles: OpaqueStyleMap) {
6869
unimplemented!();
6970
}
7071

@@ -105,7 +106,7 @@ impl DocMutator for NullDocMutator {
105106
// no-op
106107
}
107108

108-
fn InsertDocString(&mut self, _docstring: DocString) {
109+
fn InsertDocString(&mut self, _docstring: DocString, _style: OpaqueStyleMap) {
109110
// no-op
110111
}
111112

@@ -129,7 +130,7 @@ pub enum Bytecode {
129130
Exit,
130131
AdvanceElements(usize),
131132
DeleteElements(usize),
132-
InsertDocString(DocString),
133+
InsertDocString(DocString, OpaqueStyleMap),
133134
WrapPrevious(usize, Attrs),
134135
UnwrapSelf,
135136
JoinTextLeft,
@@ -172,12 +173,14 @@ impl<'a> RecordingDocMutator<'a> {
172173
// Partial string.
173174
let partial = self.stepper.char_cursor_expect().right().expect("hey now");
174175
// console_log!("🏟 {:?}", partial);
175-
self.bc.place(Bytecode::InsertDocString(partial.clone()));
176-
unimplemented!();
177-
// FIXME this is broken
178-
// self.writer.place(&DocChars(partial.clone()));
179-
// self.stepper.next();
180-
// return true;
176+
if let Some(&DocChars(ref text, ref styles)) = self.stepper.head_raw() {
177+
self.bc.place(Bytecode::InsertDocString(partial.clone(), styles.clone()));
178+
self.writer.place(&DocChars(partial.clone(), styles.clone()));
179+
} else {
180+
unreachable!();
181+
}
182+
self.stepper.next();
183+
return true;
181184
} else if let (Some(ref previous), Some(ref head)) =
182185
(self.writer.past.last(), self.stepper.head())
183186
{
@@ -269,13 +272,12 @@ impl<'a> DocMutator for RecordingDocMutator<'a> {
269272
}
270273
}
271274

272-
fn InsertDocString(&mut self, docstring: DocString) {
273-
self.bc.place(Bytecode::InsertDocString(docstring.clone()));
275+
fn InsertDocString(&mut self, docstring: DocString, styles: OpaqueStyleMap) {
276+
self.bc.place(Bytecode::InsertDocString(docstring.clone(), styles.clone()));
274277

275278
// No-op stepper
276279

277-
// FIXME
278-
// self.writer.place(&DocChars(docstring));
280+
self.writer.place(&DocChars(docstring, styles));
279281
}
280282

281283
fn UnwrapSelf(&mut self) {
@@ -320,7 +322,11 @@ impl<'a> DocMutator for RecordingDocMutator<'a> {
320322
if let Some(left) = cursor.left() {
321323
if left.char_len() == count {
322324
self.bc.place(Bytecode::DeleteElements(1)); // It's over, delete time
323-
self.InsertDocString(left.clone()); // Insert the left part of string
325+
if let Some(&DocChars(_, ref styles)) = self.stepper.head_raw() {
326+
self.InsertDocString(left.clone(), styles.to_owned()); // Insert the left part of string
327+
} else {
328+
unreachable!();
329+
}
324330
// The right part of the string is added WHEN
325331
return;
326332
} else {
@@ -331,7 +337,11 @@ impl<'a> DocMutator for RecordingDocMutator<'a> {
331337
text.seek_start_forward(count);
332338
}
333339
// console_log!("\n\n\nPARTIAL ADVANEMENET {:?}\n\n\n", text);
334-
self.InsertDocString(text);
340+
if let Some(&DocChars(_, ref styles)) = self.stepper.head_raw() {
341+
self.InsertDocString(text, styles.clone());
342+
} else {
343+
unreachable!();
344+
}
335345
}
336346
}
337347
}

oatie/src/stepper/docstepper.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::stepper::*;
2-
use crate::style::OpaqueStyleMap;
32

43
// DocStepper
54

@@ -36,7 +35,6 @@ impl<'a> DocStepper<'a> {
3635
/// If head is a group, clear the char_cursor.
3736
// TODO rename char_cursor_reset ?
3837
// TODO Make this pub(crate) once walkers.rs doesn't repend on it.
39-
#[inline(never)]
4038
pub fn char_cursor_update(&mut self) {
4139
self.char_cursor = if let Some(&DocChars(ref text, ref styles)) = self.head_raw() {
4240
Some(CharCursor::from_docstring(text, styles.to_owned()))
@@ -316,6 +314,7 @@ impl<'a> DocStepper<'a> {
316314
#[cfg(test)]
317315
mod tests {
318316
use super::*;
317+
use crate::style::*;
319318

320319
fn test_doc_0() -> DocSpan {
321320
doc_span![

oatie/src/string/docstring.rs

+12-16
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use serde::de::{
44
Visitor,
55
};
66
use serde::{
7-
ser::SerializeSeq,
87
Deserialize,
98
Deserializer,
109
Serialize,
@@ -125,14 +124,11 @@ impl PartialEq for DocString {
125124
impl Eq for DocString {}
126125

127126
impl Serialize for DocString {
128-
#[inline(never)]
129127
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
130128
where
131129
S: Serializer,
132130
{
133-
let mut s = serializer.serialize_seq(Some(1))?;
134-
s.serialize_element(self.as_str())?;
135-
s.end()
131+
serializer.serialize_str(self.as_str())
136132
}
137133
}
138134

@@ -150,26 +146,26 @@ impl<'de> Deserialize<'de> for DocString {
150146
formatter.write_str("docstring")
151147
}
152148

153-
fn visit_str<E>(self, value: &str) -> Result<DocString, E>
149+
fn visit_seq<V>(self, mut seq: V) -> Result<Self::Value, V::Error>
154150
where
155-
E: de::Error,
151+
V: SeqAccess<'de>,
156152
{
157-
Ok(DocString::from_str(value))
153+
// Deserialize the one we care about.
154+
let ret: String = seq.next_element()?
155+
.ok_or_else(|| de::Error::invalid_length(1, &self))?;
156+
157+
158+
Ok(DocString::from_string(ret))
158159
}
159160

160-
fn visit_seq<A>(self, mut seq: A) -> Result<DocString, A::Error>
161+
fn visit_str<E>(self, value: &str) -> Result<DocString, E>
161162
where
162-
A: SeqAccess<'de>,
163+
E: de::Error,
163164
{
164-
if let Some(inner) = seq.next_element::<String>()? {
165-
Ok(DocString::from_string(inner))
166-
} else {
167-
Err(de::Error::unknown_field("0", FIELDS))
168-
}
165+
Ok(DocString::from_str(value))
169166
}
170167
}
171168

172-
const FIELDS: &'static [&'static str] = &["docstring"];
173169
deserializer.deserialize_any(FieldVisitor)
174170
}
175171
}

0 commit comments

Comments
 (0)