Rename at a shared source boundary executes at two generated positions when unmapped text is injected between chunks

Author: johnsoncodehkCreated Aug 26, 2026Updated Aug 26, 2026

Problem

Source mappings are closed intervals: when two mapped chunks are adjacent in the source, the shared source offset is claimed by both the preceding chunk's end and the following chunk's start. As long as the two chunks are also adjacent in the generated code, both claims resolve to the same generated position and the double-claim is harmless.

But when unmapped text is injected between the two chunks in the generated code, the shared boundary resolves to two disjoint generated positions. Rename (and similar position-driven features) then executes at both positions — and the first one lands on whatever the injected text contains.

Concrete case (surfaced by #6184)

#6184 emits setup-binding reads as __VLS_unwrap(foo, ...) — an unmapped prefix immediately before the mapped foo chunk:

source:    {{ foo +foo }}
generated:    __VLS_unwrap(foo, ...) + __VLS_unwrap(foo, ...)

Renaming foo at its left boundary (+|foo) resolves the source offset at two generated positions:

  1. the end of the preceding chunk → lands on the __VLS_unwrap identifier,
  2. the start of the binding chunk → lands on foo (the intended one).

Since __VLS_unwrap is declared in a real file (packages/language-core/types/template-helpers.d.ts), the rename produces an edit that renames the helper declaration itself — user code ends up rewriting library internals.

This already exists on master — it is just invisible

The same double-claim mechanism exists on master via the __VLS_ctx.* path (options API / undeclared bindings), where generated code is e.g. __VLS_ctx.foo + __VLS_ctx.foo. Renaming at the same boundary position additionally targets __VLS_ctx — but __VLS_ctx is a virtual-unmapped synthetic variable, so its edits cannot map back to the source and are silently dropped. Verified locally: {{ foo +|foo }} on an options-API component produces clean rename locations only because the extra edits are discarded.

On master, setup bindings are emitted as foo.value / bare foo with no injected text between adjacent chunks, so the double-claim resolves to a single position there as well.

Where the fix belongs

Not in codegen. Any codegen-side workaround (detaching boundary characters, reshaping chunks) trades one mapping ambiguity for another.

The fix belongs at the position-translation / rename layer: when a source position maps to multiple generated positions because of a boundary double-claim, rename should recognize that the extra positions come from the same shared boundary — or simply not execute rename at a generated position that the user could not have intended (e.g. positions claimed only via the end edge of a mapping while another claim via the start edge exists). Upstream Volar.js may be the right place.

Reproduction

  1. Check out #6184.
  2. Open a <script setup> component with const foo = 1 and template {{ foo +foo }}.
  3. Rename foo with the cursor at the left boundary of the second foo.
  4. Observe an additional rename location in packages/language-core/types/template-helpers.d.ts (the __VLS_unwrap declaration).