Skip to content

fix: show inlay hints in scripts that come after other content - #3150

Open
RaphaelFakhri wants to merge 1 commit into
sveltejs:masterfrom
RaphaelFakhri:fix/inlay-hints-script-order
Open

RaphaelFakhri wants to merge 1 commit into
sveltejs:masterfrom
RaphaelFakhri:fix/inlay-hints-script-order

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Fixes #2078.

Problem

Inlay hints are missing inside a <script> tag when anything comes before it in the file, for example <svelte:options runes />, a comment, or the instance script above a module script.

svelte2tsx moves the scripts before the template in the generated code. The inlay hint provider maps only the start and end of the requested range to the generated code, so the generated span skips the script that moved:

<svelte:options runes />

<script lang="ts">
  let a = 1; // no `: number` hint
</script>

Fix

convertToTargetTextSpan also maps the part of each script that is inside the requested range and widens the generated span to include it.

Test plan

  • Added the content-before-script and module-script-after-instance-script inlay hint fixtures.
  • Without the source change, both fixtures fail (17 passing, 2 failing). With it, all inlay hint tests pass (19 passing).
  • pnpm test in packages/language-server passes (830 passing, 0 failing). tsc --noEmit and prettier --check are clean.

@changeset-bot

changeset-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5472010

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte-language-server Patch

Not sure what this means? Click here to learn what changesets are.

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inlay hints do not work if there is content before script tag

1 participant