Use relative paths in tree-sitter extractor diagnostics#21844
Open
redsun82 wants to merge 4 commits into
Open
Conversation
Diagnostic `location.file` entries were using absolute paths (e.g. `/home/runner/work/...`), causing broken links in the GitHub UI. Now relativize against CWD (the source root during extraction), falling back to a properly percent-encoded `file:` URI for paths outside it. Fixes #21802 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates shared tree-sitter extractor diagnostics to emit repository-relative file paths where possible, improving Code Scanning file links for parse and Ruby encoding diagnostics.
Changes:
- Adds a shared diagnostic path relativization helper using
file:URI fallback. - Routes shared parse diagnostics and Ruby-specific encoding diagnostics through the new helper.
- Updates dependency metadata and Ruby diagnostics integration expectations.
Show a summary per file
| File | Description |
|---|---|
shared/tree-sitter-extractor/src/file_paths.rs |
Adds diagnostic path relativization and tests. |
shared/tree-sitter-extractor/src/extractor/mod.rs |
Uses relative diagnostic paths for shared parse errors. |
shared/tree-sitter-extractor/Cargo.toml |
Adds the url dependency. |
ruby/extractor/src/extractor.rs |
Uses relative diagnostic paths for Ruby encoding diagnostics. |
ruby/ql/integration-tests/diagnostics/unknown-encoding/diagnostics.expected |
Updates expected diagnostic file path. |
ruby/ql/integration-tests/diagnostics/syntax-error/diagnostics.expected |
Updates expected parse diagnostic file paths. |
Cargo.lock |
Records the new shared extractor dependency edge. |
ql/Cargo.lock |
Updates QL extractor lockfile dependencies. |
Copilot's findings
- Files reviewed: 6/8 changed files
- Comments generated: 3
Drop the `url` crate dependency. When a path can't be relativized against the source root, emit it as a bare absolute path and let the CLI's SARIF generator handle URI conversion downstream. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Canonicalize `current_dir()` to match canonicalized file paths (avoids `\\?\` prefix mismatch on Windows), and normalize backslashes to forward slashes in relative diagnostic paths. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Diagnostic
location.fileentries from the shared tree-sitter extractor were using absolute paths (e.g./home/runner/work/repo/src/foo.rb), which caused the GitHub Code Scanning UI to generate broken file links.This adds
relativize_for_diagnostic()to the shared extractor, which strips the source root prefix (CWD during extraction) from diagnostic paths. If the path happens to be outside the source root (shouldn't happen in practice, since the CLI invokes extractors with--working-dir=.), it falls back to the absolute path as-is and lets the CLI's SARIF generator handle it downstream.The fix covers:
unknown-character-encoding,character-decoding-error) that were emitting paths directlycurrent_dir()to match canonicalized file paths (avoids\\?\prefix mismatch), and normalizes backslashes to forward slashes in relative pathsThe Python extractor has the same bug but lives in a separate codebase and will need a separate fix.
Fixes #21802.