From 7dccddd258c51c82660bdd9c09734147ae433c57 Mon Sep 17 00:00:00 2001 From: WillLillis Date: Sun, 16 Mar 2025 23:24:06 -0400 Subject: [PATCH 1/2] chore(lib): upgrade `fluent-uri` dependency, address TOUCH-UP comments --- Cargo.toml | 2 +- src/uri.rs | 34 +++++----------------------------- 2 files changed, 6 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ae08a87..9705de3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 = [] diff --git a/src/uri.rs b/src/uri.rs index 6f82d58..e0f7b87 100644 --- a/src/uri.rs +++ b/src/uri.rs @@ -3,7 +3,7 @@ use std::{hash::Hash, ops::Deref, str::FromStr}; use serde::{de::Error, Deserialize, Serialize}; /// Newtype struct around `fluent_uri::Uri` 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); impl Serialize for Uri { @@ -21,9 +21,9 @@ impl<'de> Deserialize<'de> for Uri { D: serde::Deserializer<'de>, { let string = String::deserialize(deserializer)?; - fluent_uri::Uri::::parse_from(string) + fluent_uri::Uri::::parse(string) .map(Uri) - .map_err(|(_, error)| Error::custom(error.to_string())) + .map_err(|error| Error::custom(error.to_string())) } } @@ -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 { - // 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) } } @@ -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(&self, state: &mut H) { - self.as_str().hash(state) - } -} From 559fc92537f24d0d0a0441876c714d2603758410 Mon Sep 17 00:00:00 2001 From: WillLillis Date: Sun, 16 Mar 2025 23:36:09 -0400 Subject: [PATCH 2/2] chore: appease clippy --- src/completion.rs | 23 ++++++++++++++--------- src/inline_value.rs | 1 + tests/lsif.rs | 6 ++++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/completion.rs b/src/completion.rs index bdf60fb..1e10193 100644 --- a/src/completion.rs +++ b/src/completion.rs @@ -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 @@ -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); } diff --git a/src/inline_value.rs b/src/inline_value.rs index dd29fbb..73e98d4 100644 --- a/src/inline_value.rs +++ b/src/inline_value.rs @@ -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 diff --git a/tests/lsif.rs b/tests/lsif.rs index 3b90c8b..3fead4d 100644 --- a/tests/lsif.rs +++ b/tests/lsif.rs @@ -5,8 +5,10 @@ fn run() { let jsonl = include_str!("tsc-unix.lsif"); for json in jsonl.lines() { - let r = serde_json::from_str::(&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::(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::(&x).unwrap(), serde_json::from_str::(json).unwrap(),