language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

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

Open BlueGreenMagick opened this issue 2 years ago • 0 comments

Describe the bug

Inlay hints do not show up if 1) svelte file does not start immediately with script tag, or 2) instance script appears above module scripts

Reproduction

text
<script lang="ts">
  let a = 1;
</script>

Inlay hints inside instance script(let a[: number] = 1;) do not show up for above code. Even a white space or a newline causes this.

<script lang="ts">
  let a = 1;
</script>

<script lang="ts" context="module">
  let b = 1;
</script>

Inlay hints inside module script(let b[: number] = 1;) do not show up.

Expected behaviour

Inlay hints should show up

System Info

  • OS: macOS
  • IDE: VSCode

Which package is the issue about?

svelte-language-server

Additional Information, eg. Screenshots

The cause is in this function: https://github.com/sveltejs/language-tools/blob/0f2396e1a567040f5a33a27d6ddd98712a81f0b9/packages/language-server/src/plugins/typescript/features/InlayHintProvider.ts#L91-L93

The problem occurs when source document has content ordered as [A, B, C], and the contents are remapped in generated document to [B, A, C]. Then convertToTargetTextSpan() only contains [A, C] of the generated document, so inlay hints for B is not generated.

In the above example where there is content before instance script, A is the content before script, B is the script, and C is the content after script.

BlueGreenMagick avatar Jun 29 '23 08:06 BlueGreenMagick