Skip to content

chore(lib): upgrade fluent-uri dependency, address TOUCH-UP comments #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ bitflags = "1.0.1"
serde = { version = "1.0.34", features = ["derive"] }
serde_json = "1.0.50"
serde_repr = "0.1"
fluent-uri = "0.1.4"
fluent-uri = "0.3.2"

[features]
default = []
Expand Down
23 changes: 14 additions & 9 deletions src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ pub struct CompletionItem {
/// insertText is ignored.
///
/// Most editors support two different operation when accepting a completion item. One is to insert a

/// completion text and the other is to replace an existing text with a completion text. Since this can
/// usually not predetermined by a server it can report both ranges. Clients need to signal support for
/// `InsertReplaceEdits` via the `textDocument.completion.insertReplaceSupport` client capability
Expand Down Expand Up @@ -578,20 +577,26 @@ mod tests {

#[test]
fn test_tag_support_deserialization() {
let mut empty = CompletionItemCapability::default();
empty.tag_support = None;
let empty = CompletionItemCapability {
tag_support: None,
..Default::default()
};

test_deserialization(r#"{}"#, &empty);
test_deserialization(r#"{"tagSupport": false}"#, &empty);

let mut t = CompletionItemCapability::default();
t.tag_support = Some(TagSupport { value_set: vec![] });
let t = CompletionItemCapability {
tag_support: Some(TagSupport { value_set: vec![] }),
..Default::default()
};
test_deserialization(r#"{"tagSupport": true}"#, &t);

let mut t = CompletionItemCapability::default();
t.tag_support = Some(TagSupport {
value_set: vec![CompletionItemTag::DEPRECATED],
});
let t = CompletionItemCapability {
tag_support: Some(TagSupport {
value_set: vec![CompletionItemTag::DEPRECATED],
}),
..Default::default()
};
test_deserialization(r#"{"tagSupport": {"valueSet": [1]}}"#, &t);
}

Expand Down
1 change: 1 addition & 0 deletions src/inline_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ pub struct InlineValueEvaluatableExpression {
/// - directly as a text value (class InlineValueText).
/// - as a name to use for a variable lookup (class InlineValueVariableLookup)
/// - as an evaluatable expression (class InlineValueEvaluatableExpression)
///
/// The InlineValue types combines all inline value types into one type.
///
/// @since 3.17.0
Expand Down
34 changes: 5 additions & 29 deletions src/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{hash::Hash, ops::Deref, str::FromStr};
use serde::{de::Error, Deserialize, Serialize};

/// Newtype struct around `fluent_uri::Uri<String>` with serialization implementations that use `as_str()` and 'from_str()' respectively.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Uri(fluent_uri::Uri<String>);

impl Serialize for Uri {
Expand All @@ -21,9 +21,9 @@ impl<'de> Deserialize<'de> for Uri {
D: serde::Deserializer<'de>,
{
let string = String::deserialize(deserializer)?;
fluent_uri::Uri::<String>::parse_from(string)
fluent_uri::Uri::<String>::parse(string)
.map(Uri)
.map_err(|(_, error)| Error::custom(error.to_string()))
.map_err(|error| Error::custom(error.to_string()))
}
}

Expand All @@ -40,15 +40,10 @@ impl PartialOrd for Uri {
}

impl FromStr for Uri {
type Err = fluent_uri::ParseError;
type Err = fluent_uri::error::ParseError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
// TOUCH-UP:
// Use upstream `FromStr` implementation if and when
// https://github.com/yescallop/fluent-uri-rs/pull/10
// gets merged.
// fluent_uri::Uri::from_str(s).map(Self)
fluent_uri::Uri::parse(s).map(|uri| Self(uri.to_owned()))
fluent_uri::Uri::from_str(s).map(Self)
}
}

Expand All @@ -59,22 +54,3 @@ impl Deref for Uri {
&self.0
}
}

/*
TOUCH-UP: `PartialEq`, `Eq` and `Hash` could all be derived
if and when the respective implementations get merged upstream:
https://github.com/yescallop/fluent-uri-rs/pull/9
*/
impl PartialEq for Uri {
fn eq(&self, other: &Self) -> bool {
self.as_str() == other.as_str()
}
}

impl Eq for Uri {}

impl Hash for Uri {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.as_str().hash(state)
}
}
6 changes: 4 additions & 2 deletions tests/lsif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ fn run() {

let jsonl = include_str!("tsc-unix.lsif");
for json in jsonl.lines() {
let r = serde_json::from_str::<Entry>(&json).expect(&format!("can not parse {}", json));
let x = serde_json::to_string(&r).expect(&format!("can not serialize {}", json));
let r = serde_json::from_str::<Entry>(json)
.unwrap_or_else(|e| panic!("can not parse {} -- {e}", json));
let x = serde_json::to_string(&r)
.unwrap_or_else(|e| panic!("can not serialize {} -- {e}", json));
assert_eq!(
serde_json::from_str::<serde_json::Value>(&x).unwrap(),
serde_json::from_str::<serde_json::Value>(json).unwrap(),
Expand Down
Loading