diff --git a/crates/diagnostics/src/build_log.rs b/crates/diagnostics/src/build_log.rs index 1234567..abcdefg 100644 --- a/crates/diagnostics/src/build_log.rs +++ b/crates/diagnostics/src/build_log.rs @@ -14,8 +14,13 @@ pub fn update( let data = log_document.data.as_log()?; - let parents = deps::parents(workspace, log_document); - let root_document = parents.iter().next()?; + // Try to find the compiled .tex file from the log file name first. + // This handles subfile compilation where the subfile is the actual root. + let root_document = find_compiled_document(workspace, log_document) + .or_else(|| { + // Fallback to original behavior: find parent via dependency graph + deps::parents(workspace, log_document).into_iter().next() + })?; let base_path = root_document .path @@ -57,3 +62,14 @@ fn find_range_of_hint(document: &Document, error: &BuildError) -> Option `/path/to/chapter.tex` +fn find_compiled_document<'a>( + workspace: &'a Workspace, + log_document: &Document, +) -> Option<&'a Document> { + let log_path = log_document.path.as_ref()?; + let tex_path = log_path.with_extension("tex"); + let tex_uri = Url::from_file_path(&tex_path).ok()?; + workspace.lookup(&tex_uri) +}