Skip to content

fix(parse): stop an editor's parse of an unclosed block at end of input - #91

Open
brenelz wants to merge 1 commit into
solidjs:mainfrom
brenelz:fix/parse-unclosed-block
Open

brenelz wants to merge 1 commit into
solidjs:mainfrom
brenelz:fix/parse-unclosed-block

Conversation

@brenelz

@brenelz brenelz commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

The recovering parse an editor uses (parse_program_recovering, behind analyze) did not stop on a block that is still open when the input ends. Typing a handler such as

export default component App() {
  <button onClick={() => { c

made analyze run for 8 to 27 seconds in the playground from #70, and the same input reaches the language server through the same code.

Root cause

In a recovering parse, a missing expression is read as an empty one and recorded as an error, so parse_stmt returns Ok without advancing. parse_block loops while !c.starts_with("}") with nothing between statements that has to be there, so at the end of input, or at any character a statement cannot start with, each pass reads nothing and the loop goes round again. The list loops (arguments, arrays, records, imports) do not have this problem: they break when the , is missing.

Change

parse_block records the cursor before each statement and breaks when a pass has not moved it. The expect("}") that follows then fails as it would for any unclosed block, and the recovering loader records that as the parse error. The strict parse (parse_program) is unaffected: there parse_stmt either advances or returns Err, so the new branch is never taken.

Verification

  • cargo test --release --manifest-path compiler/Cargo.toml: 11 lib tests pass, including the new an_unclosed_block_at_the_end_of_input_stops, which finishes in under 10 ms with one recorded error.
  • With the guard removed, that test did not finish in several minutes, so a regression shows up as a hang rather than a failed assertion.
  • cargo check --manifest-path compiler/Cargo.toml --all-targets.
  • In Add a playground that shows .rx as Solid 2.0 primitives #70, every prefix and every one-character deletion of the playground's six examples was replayed through analyze with this change: the slowest call took 4 ms.

🤖 Generated with Claude Code

The recovering parse reads a missing statement as an empty one without advancing, so parse_block looped until it found a closing brace. A half-typed handler like `onClick={() => { c` made analyze take 8 to 27 seconds.

This branch has not been deployed

No deployments
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.

1 participant