Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

feat(core): improve debug formatting for `Suggestion` (#2619)

Steve Kurch9245594a2694
diff --git a/harper-core/src/linting/suggestion.rs b/harper-core/src/linting/suggestion.rs
index bb357f0ab..26a58ab47 100644
--- a/harper-core/src/linting/suggestion.rs
+++ b/harper-core/src/linting/suggestion.rs
@@ -1,4 +1,7 @@
-use std::{borrow::Borrow, fmt::Display};
+use std::{
+ borrow::Borrow,
+ fmt::{Debug, Display},
+};
use is_macro::Is;
use serde::{Deserialize, Serialize};
@@ -6,7 +9,7 @@ use serde::{Deserialize, Serialize};
use crate::{Span, case};
/// A suggested edit that could resolve a [`Lint`](super::Lint).
-#[derive(Debug, Clone, Serialize, Deserialize, Is, PartialEq, Eq, Hash)]
+#[derive(Clone, Serialize, Deserialize, Is, PartialEq, Eq, Hash)]
pub enum Suggestion {
/// Replace the offending text with a specific character sequence.
ReplaceWith(Vec<char>),
@@ -83,6 +86,15 @@ impl Display for Suggestion {
}
}
+// To make debug output more readable.
+// The default debug implementation for Vec<char> isn't ideal in this scenario, as it prints
+// characters one at a time, line by line.
+impl Debug for Suggestion {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ <Self as Display>::fmt(self, f)
+ }
+}
+
pub trait SuggestionCollectionExt {
fn to_replace_suggestions(
self,