Skip to content

Fix synthetic location hangs, position lookups, and snippet bounds - #1913

Merged
TwitchBronBron merged 2 commits into
flatten-locationsfrom
location-pattern-fixes
Oct 15, 2026
Merged

TwitchBronBron merged 2 commits into
flatten-locationsfrom
location-pattern-fixes

Conversation

@TwitchBronBron

@TwitchBronBron TwitchBronBron commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Stacked on #1845. Fixes weak spots in the pos/end/source pattern found while reviewing it. Parsed positions describe where code came from, so they shouldn't be changed after parsing.

  • Remove the deprecated location setters on tokens and nodes (the getters stay)
  • Remove synthetic sources. util.setLocation(target, location, sourceInfo) now requires a real source (i.e. file.sourceInfo, now public) and maps the location into it, or leaves the item without a position when the location doesn't fit. This also fixes a hang when a location ended at a sentinel line like MAX_SAFE_INTEGER
  • findChildAtPosition() only matches nodes from the source being searched. Source-less nodes (i.e. a synthetic if wrapping real code) and snippet nodes are stepped into, but never matched on their own
  • Snippet code (parsed without a srcPath) keeps its pos/end, but setBounds() prefers a source with a uri, and source maps leave uri-less code unmapped instead of pointing at the host file's lines
  • A lone \r inside a template string is now a line start, like everywhere else in the lexer

Behavior change: a synthetic node no longer matches every position in findChildAtPosition().

Verified with npm run test:nocover and npm run lint.

🤖 Generated with Claude Code

TwitchBronBron and others added 2 commits October 15, 2026 09:07
Parsed positions describe where code came from, so the deprecated `location` setters are removed.

- `setLocation()` can map into a real `SourceInfo`, and synthetic sources compute lines arithmetically (no growing `lineStarts`), clamping sentinel ranges like `MAX_SAFE_INTEGER` lines instead of hanging
- `findChildAtPosition()` only matches nodes from the searched source; source-less and snippet nodes are stepped into but never matched themselves
- `setBounds()` prefers a source with a uri over a snippet's, and source maps leave uri-less (snippet) code unmapped
- a lone `\r` in a template string is a line start, like everywhere else in the lexer
- `BrsFile.sourceInfo` is public so plugins can pass it to `setLocation()`

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Nothing in bsc calls `setLocation()`, and synthetic sources only existed to back the removed `location` setter. `setLocation(target, location, sourceInfo)` now maps into the given source, or leaves the item without a position when the location doesn't fit it. This drops the per-uri synthetic source map and the `lineLength` field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TwitchBronBron
TwitchBronBron merged commit 45792c6 into flatten-locations Oct 15, 2026
11 checks passed
@TwitchBronBron
TwitchBronBron deleted the location-pattern-fixes branch October 15, 2026 18:00
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