Send languageId 'typescriptreact' / 'javascriptreact' for .tsx / .jsx files (#1436)

* Fix: send languageId 'typescriptreact' / 'javascriptreact' for .tsx / .jsx

Without this, .tsx files are opened with languageId 'typescript', so
tsserver parses JSX as syntax errors and recovers by truncating the
enclosing symbol's range at the first multi-line JSX expression. The
resulting symptoms:

- find_symbol(name, include_body=True) on a React component returns a
  body that ends mid-component, hiding everything below.
- The same component shows up as multiple Method-kind symbols (one per
  call site) plus a separately-tracked Constant for the definition,
  because tsserver mistakes JSX-tag tokens for member access.

Reproducer (before fix, real-world TSX file):
  SidebarPDF range = [11:1-25:207]   (truncated at first JSX, line 25)
After fix:
  SidebarPDF range = [11:1-281:2]    (full body)

The base SolidLanguageServer._get_language_id_for_file is explicitly
designed for this — its docstring says "Override in subclasses to
return file-specific language IDs." This change just exercises that
hook for the React file extensions.

Adds a regression test + jsx_component.tsx fixture covering the same
arrow-function-with-multi-line-JSX-ternary pattern that triggers the
truncation in real codebases (see oraios/serena#1029 for an earlier
report whose root cause was not identified).
This commit is contained in:
Robin Jehn authored and GitHub committed 2026-04-29 18:03:41 +02:00
1 parent 28c2866bf4
commit 37c837ffd3
4 files changed
+87 -2

No files matched your search

@@ -0,0 +1,44 @@
// Regression fixture: mirrors the real-world pattern that caused
// languageId=typescript (instead of typescriptreact) to truncate symbol
// ranges at the first multi-line JSX expression.
import * as React from "react"
type SectionProps = { title: string; emphasised?: boolean }
function Section({ title, emphasised }: SectionProps) {
return emphasised ? (
<h1 style={{ color: "red" }}>{title}</h1>
) : (
<h2 style={{ color: "gray" }}>{title}</h2>
)
}
export function JsxComponent({ heading, items }: { heading: string; items: string[] }) {
const renderHeader = (title: string) =>
title.length > 10 ? (
<Section title={title} emphasised />
) : (
<Section title={title} />
)
// The truncation bug used to cut JsxComponent's range right around here,
// hiding everything below from find_symbol. Keep this comment so the
// regression test can assert the function body extends past it.
const renderItem = (item: string, idx: number) => (
<li key={idx} style={{ marginBottom: 4 }}>
{item}
</li>
)
return (
<div>
{renderHeader(heading)}
<ul>{items.map(renderItem)}</ul>
</div>
)
}
export function trailingHelper(): string {
return "this symbol is invisible to find_symbol when JsxComponent's range is truncated"
}
@@ -5,7 +5,8 @@
"strict": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true
"skipLibCheck": true,
"jsx": "react"
},
"include": ["**/*.ts"]
"include": ["**/*.ts", "**/*.tsx"]
}