close
Skip to content
Open
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 crates/parser/src/frontmatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ pub fn strip_ws_lines(input: &str) -> Option<usize> {
/// True if `c` is considered a whitespace according to Rust language definition.
/// See [Rust language reference](https://doc.rust-lang.org/reference/whitespace.html)
/// for definitions of these classes.
fn is_whitespace(c: char) -> bool {
pub(crate) fn is_whitespace(c: char) -> bool {
// This is Pattern_White_Space.
//
// Note that this set is stable (ie, it doesn't change with different
Expand Down
7 changes: 7 additions & 0 deletions crates/parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ pub use crate::{
syntax_kind::SyntaxKind,
};

/// True if `c` is whitespace in Rust source (Unicode Pattern_White_Space as in the language reference).
///
/// See <https://doc.rust-lang.org/reference/whitespace.html>.
pub fn is_rust_whitespace(c: char) -> bool {
frontmatter::is_whitespace(c)
}

/// Parse the whole of the input as a given syntactic construct.
///
/// This covers two main use-cases:
Expand Down
11 changes: 6 additions & 5 deletions crates/rust-analyzer/src/cli/analysis_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,8 @@ impl flags::AnalysisStats {
continue;
};

fn trim(s: &str) -> String {
s.chars().filter(|c| !c.is_whitespace()).collect()
fn drop_whitespace(s: &str) -> String {
s.chars().filter(|c| !parser::is_rust_whitespace(*c)).collect()
}

let todo = syntax::ast::make::ext::expr_todo().to_string();
Expand All @@ -608,7 +608,8 @@ impl flags::AnalysisStats {
display_target,
)
.unwrap();
syntax_hit_found |= trim(&original_text) == trim(&generated);
syntax_hit_found |=
drop_whitespace(&original_text) == drop_whitespace(&generated);

// Validate if type-checks
let mut txt = file_txt.text(db).to_string();
Expand Down Expand Up @@ -662,7 +663,7 @@ impl flags::AnalysisStats {
let msg = move || {
format!(
"processing: {:<50}",
trim(&original_text).chars().take(50).collect::<String>()
drop_whitespace(&original_text).chars().take(50).collect::<String>()
)
};
if verbosity.is_spammy() {
Expand Down Expand Up @@ -1646,5 +1647,5 @@ impl fmt::Display for PrettyItemStats {
// fn syntax_len(node: SyntaxNode) -> usize {
// // Macro expanded code doesn't contain whitespace, so erase *all* whitespace
// // to make macro and non-macro code comparable.
// node.to_string().replace(|it: char| it.is_ascii_whitespace(), "").len()
// drop_whitespace(&node.to_string()).len()
// }