Repository navigation
fix(language-server): list <script> body declarations as document symbols - #1277
Merged
jonkwheeler merged 2 commits intoNov 12, 2026
Merged
Conversation
…ymbols (tsrx-org#137) Since script bodies became blocks appended to the generated TSX, TypeScript's navigation tree skips them, so their declarations were missing from the Outline, breadcrumbs and Go to Symbol in File on every backend. The document symbol plugin now adds a `<script>` symbol for each body of code the compiler reports in its script mappings (data blocks have none), with the body's top-level declarations as children. The body is parsed where it stands in the source, the rest of the file blanked, so every offset stays a source offset and maps through the body's mapping. The `<script>` symbols are top-level, like the CSS rules of `<style>` blocks: React hoists a static `<script>` element out of its component, so under the component it would break the range the component maps back to. The TSRX virtual code keeps the compiler's script regions for this. Enum declarations become symbols too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ceb4d0b. Configure here.
The `<script>` symbol's element was found by searching the text for `<script` before the body and `</script>` after it. A valid `</script >` made the range run on to the next script, or dropped the symbol when no script followed, and a `<script` in an attribute value took over the range and the selection. Each symbol now comes from its element in the source AST, looked up by where its body starts: the range runs from the opening tag's name to the closing tag's name, and the opening tag's name selects it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
jonkwheeler
marked this pull request as ready for review
October 29, 2026 14:59
This was referenced Nov 17, 2026
jonkwheeler
added a commit
that referenced
this pull request
Nov 18, 2026
…ainers as in children lists (#1367) * fix(core, solid): print edge whitespace in JSX inside expression containers as in children lists The spaces and tabs at the edges of an element's children print as `{' '}` (#1277), but JSX inside a `{…}` container kept its text as written on React, Preact, Hono and Solid, so `<><div> 123 </div>{<div> 123 </div>}</>` printed two forms (#1351). - React, Preact, Hono: a static hoisted out of a container (#1279) leaves the walk that applies the rule. lower_static_script_bodies, renamed lower_static_jsx, already redoes the walk's `<script>` lowering for a static; it now also wraps each children list in the static. This covers a container inside a bare static element too. - Solid: create_element_children returns wrapEdgeWhitespace(...), so JSX in a container, an attribute value, a callback, a `const`, a module-level declaration or nested in a control-flow body gets the rule. Solid's compiler collapses a whitespace run in JSX text but keeps a `{' '}` literal, so `{<b> 1 </b>}` now renders " 1 " like a children list instead of " 1 ". - Vue already printed both forms the same; its output is unchanged. In those places an element's text with edge whitespace now gets three children instead of one string, as in a children list, so React's existing <textarea>/<title> problem with that shape reaches them too. wrapEdgeWhitespace returns its input when it wraps nothing, and gives the trimmed text the location of what is left of it: with the whole text's location, a `@` after a space (`<div> @</div>`) mapped one character early and got no directive completion, in a children list and now in a container. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
jonkwheeler
added a commit
that referenced
this pull request
Nov 19, 2026
…s one literal (#1381) * fix(core, solid): print an element's only text with edge whitespace as one literal The spaces and tabs at the edges of an element's text print as `{' '}` (#1277), so an element whose only child was ` a ` got three children: `<textarea>{' '}a{' '}</textarea>`. React's `<textarea>` throws for more than one child, `<title>` renders empty, a `<pre>` loses a leading ` ` in SSR, and a component whose `children` is typed `string` gets something else, which TypeScript reports as TS2322 in the editor (#1368). An element's only text with a space or tab at an edge now prints as one literal of its value, `<textarea>{' a '}</textarea>`. wrapEdgeWhitespace takes a second argument that says the children are an element's, which the element paths pass (core's create_element_children and lower_static_jsx, Solid's create_element_children). A fragment's only text keeps the split, so the fragment stays, and so does text beside other children. only_text_value gives the parser's value, which is how TypeScript, esbuild and oxc read such a text for React, Preact and Hono. Solid's and Vue's compilers read some of these texts differently (a whitespace run, `⟨`, a decoded line feed) and now render the literal as written. The split stays for a text where the literal could differ from that reading: one that spans lines or holds whitespace other than spaces and tabs (vue-jsx-vapor keeps a text's lines, Solid's compiler turns a non-breaking space into a space and drops a CR), a character reference the parser leaves as written or decodes where they don't (`&#+65;`, `©` without a semicolon, `A`), and a reference to a control character or a lone surrogate. The container gets the text's location. segments.js maps the text to the container that prints the literal where the text's start maps (it can also map to the `return` a template body adds), so a type error on the literal shows at the text, and maps an `@` that starts the text into the literal for directive completions, as it does for JSX text. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46 * fix(core): keep the split for an only text whose literal would differ on Solid, Vue or in the printed source An independent review of the one-literal rule for an element's only text (#1368) found two more texts where the literal changes what was rendered: - A named reference the parser doesn't decode, such as `✓` (the review counted 1,476 HTML names of up to eight letters and digits that the parser's XHTML table lacks): Solid's and Vue's HTML templates read it in the split text (" ✓ "), while the literal keeps it as written (" ✓ "). only_text_value now keeps the split when the parser left a `&name;` in the text undecoded. names_all_decoded finds that in one pass over the text and its value, following each reference to where it went, so `&amp;` (value `&`) still prints one literal. - `
`, `
` and `` decode to U+2028, U+2029 and U+FEFF, which the literal prints as is. JavaScript reads the first two as line breaks where the source map doesn't, so positions after them are off. They join the control characters that keep the split. The changeset also names the SWC change the review found: SWC trimmed a line feed written as ` ` at the edge of the split text, and the literal keeps it, as TypeScript, esbuild and oxc do. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Declarations inside
<script>bodies show up again in the Outline, breadcrumbs and Go to Symbol in File. Before, they appeared on no path. Since script bodies became blocks of the generated TypeScript (#135), they were type-checked in place but never listed, because TypeScript's navigation tree skips bare blocks. Now each body appears as a<script>symbol with the body's top-level declarations as children:lists
<script>›analyticsEnabled. The children are variables, functions, classes, interfaces, type aliases and enums, with the locals and members other declarations already show (a function's locals, a class's methods). Data blocks such as<script type="application/json">get no symbol, matching the compiler, which gives them no region. Scoping is unchanged.How
documentSymbolPluginadds one<script>symbol (SymbolKind.Module) for each region in the compiler'sscriptMappings.TSRXVirtualCodenow keeps those regions asscriptRegions.pluginandnativebackends too.<script>element in the source AST, found by where its body starts. The range runs from the opening tag's name to the closing tag's name, the parts of the element that map to the generated TSX. The opening tag's name is the selection. A</script >or a<scriptin an attribute value or the body doesn't change either.<script>symbols are top-level and in source order, after the component that renders them, like the CSS rules of<style>blocks. The element's generated JSX can sit outside its component's generated code (React hoists a static<script>to module scope). Nested under the component, it widened the component's fallback range backwards and broke the component's mapped range: the component symbol disappeared in a test.SymbolKind.Enum), in script bodies and elsewhere in a.tsrxfile, since the issue listsenumamong the declarations to show.packages/content-mapper/COMPATIBILITY.mdrow 46 now describes the restored behaviour.Verification
documentSymbolPlugin.test.js: new test covering two code<script>bodies and a JSON data block. It checks the symbol tree, kinds, nested children, and the source ranges of the<script>symbol and its children.documentSymbolPlugin.test.js: a second test covers</script >closers and<scriptinside an attribute value and the body. Each range stays within its own element, with the opening tag's name as the selection.nativeBackendLsp.test.js: the assertion that pinned the old behaviour now expects<script>›analyticsEnabled, with the range starting at the tag. It runs on thenative,pluginandclassicbackends.<script>element on each.npx vitest run: 176 files, 10010 passed, 82 skipped.pnpm typecheck,prettier --checkandpnpm changeset:checkare clean.Related
Fixes #137
🤖 Generated with Claude Code