fix(lsp): apply diagnostic offset for plugin diagnostics in Vue/Astro/Svelte files #9012
+266
−8
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.
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 inhandlers/analysis.rs) and pass it todiagnostic_to_lspinstead ofNone. Guarded bysupports_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
DiagnosticSignalwith a newPluginSignal<L>for plugin diagnostics.DiagnosticSignalconvertsRuleDiagnostic→Error→DiagnosticKind::Raw, which is skipped byadd_diagnostic_offset.PluginSignalpreservesDiagnosticKind::RuleviaAnalyzerDiagnostic::from(RuleDiagnostic).This doesn't change current behavior since
pull_diagnosticspassesdiagnostic_offset: Nonefor 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 ensuresadd_diagnostic_offsetwould work correctly if the offset strategy changes in the future.Test plan
check_plugin_diagnostic_offset_in_vue_fileCLI snapshot test: a GritQL plugin targetingfoobindings, 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>.