Skip to content

Commit

Permalink
build(deps): upgrade indexmap crate (#2673)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos committed May 1, 2024
1 parent 47662b3 commit 7aed8d9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 63 deletions.
26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ crossbeam = "0.8.4"
dashmap = "5.4.0"
getrandom = "0.2.14"
ignore = "0.4.21"
indexmap = "1.9.3"
indexmap = { version = "2.2.6", features = ["serde"] }
insta = "1.38.0"
lazy_static = "1.4.0"
oxc_resolver = "1.4.0"
Expand Down
63 changes: 15 additions & 48 deletions crates/biome_deserialize/src/string_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ use crate::{self as biome_deserialize, Merge};
use biome_deserialize_macros::Deserializable;
use indexmap::set::IntoIter;
use indexmap::IndexSet;
use serde::de::{SeqAccess, Visitor};
use serde::ser::SerializeSeq;
use serde::{Deserialize, Serialize};
use std::ops::{Deref, DerefMut};
use std::str::FromStr;

// To implement serde's traits, we encapsulate `IndexSet<String>` in a new type `StringSet`.
// To implement schemars trait, we encapsulate `IndexSet<String>` in a new type `StringSet`.

#[derive(Clone, Default, Debug, Deserializable, Eq, PartialEq)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(
Clone, Default, Debug, Deserializable, Eq, PartialEq, serde::Deserialize, serde::Serialize,
)]
pub struct StringSet(IndexSet<String>);

impl StringSet {
Expand All @@ -35,6 +33,17 @@ impl StringSet {
}
}

#[cfg(feature = "schema")]
impl schemars::JsonSchema for StringSet {
fn schema_name() -> String {
String::from("StringSet")
}

fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
<std::collections::HashSet<String>>::json_schema(gen)
}
}

impl Deref for StringSet {
type Target = IndexSet<String>;

Expand All @@ -57,35 +66,6 @@ impl FromStr for StringSet {
}
}

impl<'de> Deserialize<'de> for StringSet {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
struct IndexVisitor;
impl<'de> Visitor<'de> for IndexVisitor {
type Value = IndexSet<String>;

// Format a message stating what data this Visitor expects to receive.
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("expecting a sequence")
}

fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: SeqAccess<'de>,
{
let mut index_set = IndexSet::with_capacity(seq.size_hint().unwrap_or(0));
while let Some(value) = seq.next_element()? {
index_set.insert(value);
}
Ok(index_set)
}
}
deserializer.deserialize_seq(IndexVisitor).map(StringSet)
}
}

impl FromIterator<String> for StringSet {
fn from_iter<T: IntoIterator<Item = String>>(iter: T) -> Self {
StringSet::new(IndexSet::from_iter(iter))
Expand All @@ -106,16 +86,3 @@ impl Merge for StringSet {
self.extend(other)
}
}

impl Serialize for StringSet {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let mut sequence = serializer.serialize_seq(Some(self.len()))?;
for item in self.0.iter() {
sequence.serialize_element(&item)?;
}
sequence.end()
}
}
2 changes: 1 addition & 1 deletion crates/biome_formatter/src/printed_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl PrintedTokens {
let mut offsets = self.offsets.clone();

for token in root.descendants_tokens(Direction::Next) {
if !offsets.remove(&token.text_trimmed_range().start()) {
if !offsets.shift_remove(&token.text_trimmed_range().start()) {
panic!("token has not been seen by the formatter: {token:#?}.\
\nUse `format_replaced` if you want to replace a token from the formatted output.\
\nUse `format_removed` if you want to remove a token from the formatted output.\n\
Expand Down

0 comments on commit 7aed8d9

Please sign in to comment.