Skip to content
Merged
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
25 changes: 23 additions & 2 deletions crates/quarto-error-reporting/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ impl DiagnosticMessage {
.or_else(|| self.details.iter().find_map(|d| d.location.as_ref()));

if let Some(loc) = location {
if let Some(ariadne_output) = self.render_ariadne_source_context(loc, ctx.unwrap(), options.enable_hyperlinks)
if let Some(ariadne_output) =
self.render_ariadne_source_context(loc, ctx.unwrap(), options.enable_hyperlinks)
{
result.push_str(&ariadne_output);
true
Expand Down Expand Up @@ -581,6 +582,7 @@ impl DiagnosticMessage {
/// and other terminal emulators for opening files at specific positions.
///
/// Returns the wrapped path if conditions are met, otherwise returns the original path.
#[cfg(not(target_family = "wasm"))]
fn wrap_path_with_hyperlink(
path: &str,
has_disk_file: bool,
Expand Down Expand Up @@ -624,6 +626,19 @@ impl DiagnosticMessage {
format!("\x1b]8;;{}\x1b\\{}\x1b]8;;\x1b\\", file_url, path)
}

/// WASM version: hyperlinks don't make sense in WASM environments (no file system).
/// Just return the path unmodified.
#[cfg(target_family = "wasm")]
fn wrap_path_with_hyperlink(
path: &str,
_has_disk_file: bool,
_line: Option<usize>,
_column: Option<usize>,
_enable_hyperlinks: bool,
) -> String {
path.to_string()
}

/// Render source context using ariadne (private helper for to_text).
///
/// This produces the visual source code snippet with highlighting.
Expand Down Expand Up @@ -662,7 +677,13 @@ impl DiagnosticMessage {
// Line and column numbers are 1-indexed for display (start_mapped.location uses 0-indexed)
let line = Some(start_mapped.location.row + 1);
let column = Some(start_mapped.location.column + 1);
let display_path = Self::wrap_path_with_hyperlink(&file.path, is_disk_file, line, column, enable_hyperlinks);
let display_path = Self::wrap_path_with_hyperlink(
&file.path,
is_disk_file,
line,
column,
enable_hyperlinks,
);

// Determine report kind and color
let (report_kind, main_color) = match self.kind {
Expand Down
4 changes: 3 additions & 1 deletion crates/quarto-error-reporting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,6 @@ pub mod macros;
// Re-export main types for convenience
pub use builder::DiagnosticMessageBuilder;
pub use catalog::{ERROR_CATALOG, ErrorCodeInfo, get_docs_url, get_error_info, get_subsystem};
pub use diagnostic::{DetailItem, DetailKind, DiagnosticKind, DiagnosticMessage, MessageContent, TextRenderOptions};
pub use diagnostic::{
DetailItem, DetailKind, DiagnosticKind, DiagnosticMessage, MessageContent, TextRenderOptions,
};