Skip to content

Conversation

@kiroushi
Copy link

@kiroushi kiroushi commented Feb 9, 2026

Summary

Plugin diagnostics (GritQL) in Vue/Astro/Svelte SFC files report incorrect positions in the LSP — the byte offsets are relative to the extracted <script> block but are sent to the editor without adding the script block's offset within the file, causing diagnostics to appear in the <template> section instead of the <script> section.

LSP fix (biome_lsp)

In update_diagnostics_for_document, compute the script block offset for Vue/Astro/Svelte files (matching the existing pattern in handlers/analysis.rs) and pass it to diagnostic_to_lsp instead of None. Guarded by supports_full_html_support() since full HTML mode produces file-relative positions that don't need adjustment.

This is the fix that changes behavior and resolves the bug.

Analyzer correctness (biome_analyze)

Replace DiagnosticSignal with a new PluginSignal<L> for plugin diagnostics. DiagnosticSignal converts RuleDiagnosticErrorDiagnosticKind::Raw, which is skipped by add_diagnostic_offset. PluginSignal preserves DiagnosticKind::Rule via AnalyzerDiagnostic::from(RuleDiagnostic).

This doesn't change current behavior since pull_diagnostics passes diagnostic_offset: None for Vue files — the offset is applied post-hoc by the CLI and LSP layers. However, it's the correct semantic representation (plugin diagnostics are rule diagnostics) and ensures add_diagnostic_offset would work correctly if the offset strategy changes in the future.

Test plan

  • Added check_plugin_diagnostic_offset_in_vue_file CLI snapshot test: a GritQL plugin targeting foo bindings, run against a Vue file with a multi-line <template> preceding the <script>. The snapshot confirms both the lint and plugin diagnostics point to the correct line in <script>.

…/Svelte files

Plugin diagnostics in Vue, Astro, and Svelte SFC files reported incorrect
positions in the LSP. The diagnostic spans pointed into the <template>
section instead of the <script> section because the embedded language
byte offset was not applied to the diagnostics.

Root cause: Session::update_diagnostics_for_document called
diagnostic_to_lsp with offset: None for all files, including
Vue/Astro/Svelte SFCs where the JavaScript content is extracted from
the <script> block with a byte offset from the start of the file.

Fixes:

1. LSP session (session.rs): Compute the script block byte offset for
   Vue/Astro/Svelte files and pass it to diagnostic_to_lsp, matching
   the existing pattern in handlers/analysis.rs and handlers/formatting.rs.

2. Analyzer plugin signal (signals.rs): Introduce PluginSignal<L> that
   preserves DiagnosticKind::Rule instead of converting through
   DiagnosticSignal which produces DiagnosticKind::Raw. This ensures
   add_diagnostic_offset correctly adjusts plugin diagnostic spans in
   the embedded HTML content path.
@changeset-bot
Copy link

changeset-bot bot commented Feb 9, 2026

⚠️ No Changeset found

Latest commit: 199da90

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added A-CLI Area: CLI A-Linter Area: linter A-LSP Area: language server protocol labels Feb 9, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 9, 2026

Walkthrough

This change introduces a new PluginSignal<L> type to replace DiagnosticSignal in the analyzer plugin wiring. The PluginSignal directly wraps a RuleDiagnostic and implements AnalyzerSignal<L> with empty actions and transformations. The LSP session is updated to compute diagnostic offsets for Vue, Svelte, and Astro files when full HTML support is unavailable, ensuring correct offset mapping. A test is added to verify diagnostic offset handling for plugins in Vue files.

Possibly related PRs

Suggested labels

A-LSP, A-Diagnostic, L-JavaScript, L-HTML, L-Grit, A-CLI

Suggested reviewers

  • dyc3
  • arendjr
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing diagnostic offset application for plugin diagnostics in Vue/Astro/Svelte files via LSP.
Description check ✅ Passed The description thoroughly explains the bug, the fix across multiple components, and includes a test plan directly addressing the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ematipico
Copy link
Member

Clearly AI. Restore our template and adhere to it. Please disclose the use of AI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CLI Area: CLI A-Linter Area: linter A-LSP Area: language server protocol

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants