Skip to content

Commit 3b9b615

Browse files
committed
merge
1 parent 3fcf764 commit 3b9b615

File tree

3 files changed

+17
-42
lines changed

3 files changed

+17
-42
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/qmd-syntax-helper/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ anyhow = "1.0"
2323
regex = "1.10"
2424
colored = "2.1"
2525
quarto-markdown-pandoc.workspace = true
26+
quarto-error-reporting.workspace = true
2627
include_dir = "0.7"
2728
serde = { version = "1.0", features = ["derive"] }
2829
serde_json = "1.0"

crates/qmd-syntax-helper/src/conversions/div_whitespace.rs

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,20 @@
11
use anyhow::{Context, Result};
22
use colored::Colorize;
3-
use serde::{Deserialize, Serialize};
43
use std::fs;
54
use std::path::Path;
65

76
use crate::rule::{CheckResult, ConvertResult, Rule};
87
use crate::utils::file_io::{read_file, write_file};
98

10-
#[derive(Debug, Serialize, Deserialize)]
11-
struct ErrorLocation {
12-
row: usize,
13-
column: usize,
14-
byte_offset: usize,
15-
size: usize,
16-
}
17-
18-
#[derive(Debug, Serialize, Deserialize)]
19-
struct ParseError {
20-
filename: String,
21-
title: String,
22-
message: String,
23-
location: ErrorLocation,
24-
}
25-
269
pub struct DivWhitespaceConverter {}
2710

2811
impl DivWhitespaceConverter {
2912
pub fn new() -> Result<Self> {
3013
Ok(Self {})
3114
}
3215

33-
/// Parse a file and get error locations as JSON
34-
fn get_parse_errors(&self, file_path: &Path) -> Result<Vec<ParseError>> {
16+
/// Parse a file and get diagnostic messages
17+
fn get_parse_errors(&self, file_path: &Path) -> Result<Vec<quarto_error_reporting::DiagnosticMessage>> {
3518
let content = fs::read_to_string(file_path)
3619
.with_context(|| format!("Failed to read file: {}", file_path.display()))?;
3720

@@ -48,31 +31,15 @@ impl DivWhitespaceConverter {
4831

4932
match result {
5033
Ok(_) => Ok(Vec::new()), // No errors
51-
Err(error_messages) => {
52-
// Parse the JSON error output
53-
// The error messages come as a single JSON array string
54-
if error_messages.is_empty() {
55-
return Ok(Vec::new());
56-
}
57-
58-
let json_str = error_messages.join("");
59-
60-
// Try to parse as JSON array
61-
match serde_json::from_str::<Vec<ParseError>>(&json_str) {
62-
Ok(errors) => Ok(errors),
63-
Err(_) => {
64-
// If parsing fails, the messages are likely plain text warnings/debug messages
65-
// rather than actual syntax errors. These don't indicate div whitespace issues,
66-
// so we can safely ignore them for this specific rule.
67-
Ok(Vec::new())
68-
}
69-
}
34+
Err(diagnostics) => {
35+
// Return diagnostic messages directly
36+
Ok(diagnostics)
7037
}
7138
}
7239
}
7340

7441
/// Find div fence errors that need whitespace fixes
75-
fn find_div_whitespace_errors(&self, content: &str, errors: &[ParseError]) -> Vec<usize> {
42+
fn find_div_whitespace_errors(&self, content: &str, errors: &[quarto_error_reporting::DiagnosticMessage]) -> Vec<usize> {
7643
let mut fix_positions = Vec::new();
7744
let lines: Vec<&str> = content.lines().collect();
7845

@@ -85,12 +52,18 @@ impl DivWhitespaceConverter {
8552
continue;
8653
}
8754

55+
// Extract row from location (if available)
56+
// SourceInfo uses 0-indexed rows, div_whitespace uses them too
57+
let error_row = error.location.as_ref()
58+
.map(|loc| loc.range.start.row)
59+
.unwrap_or(0);
60+
8861
// The error might be on the line itself or the line before (for div fences)
8962
// Check both the current line and the previous line
90-
let lines_to_check = if error.location.row > 0 {
91-
vec![error.location.row - 1, error.location.row]
63+
let lines_to_check = if error_row > 0 {
64+
vec![error_row - 1, error_row]
9265
} else {
93-
vec![error.location.row]
66+
vec![error_row]
9467
};
9568

9669
for &line_idx in &lines_to_check {

0 commit comments

Comments
 (0)