Skip to content

Fix bare script variable scoping#68

Merged
JesseHerrick merged 1 commit into
mainfrom
fix-bare-script-var-scoping
Jun 11, 2026
Merged

Fix bare script variable scoping#68
JesseHerrick merged 1 commit into
mainfrom
fix-bare-script-var-scoping

Conversation

@JesseHerrick

@JesseHerrick JesseHerrick commented Jun 3, 2026

Copy link
Copy Markdown
Member

The Problem: Go to definition wasn't working for variables in the top level of an exs script.

Solution: Properly handle this case.


Note

Medium Risk
Changes core rename/go-to-definition scoping and parser index references; incorrect boundaries could mis-rename or miss symbols, mitigated by extensive new tests and an index version bump.

Overview
Fixes variable scoping for bare .exs scripts (e.g. config/runtime.exs) so top-level bindings are treated as file-scoped, while nested def/defmodule bodies stay isolated for rename, occurrence collection, and collision checks.

In internal/treesitter/variables.go, scope discovery now stops at the source root and at defmodule/defprotocol/defimpl calls; traversals skip nested function and module definitions so same-named locals do not leak across boundaries. Bare top-level identifiers that are only zero-arity calls are not misclassified as variables when a same-named binding exists inside a nested def.

The tokenized parser resolves import / use / require module names via ResolveModuleRef (aliases + current module) instead of plain resolveModule, improving indexing in scripts without an enclosing module.

Adds LSP rename coverage for plain alias + require short name in the same config file, plus tree-sitter tests for top-level and cross-boundary cases. IndexVersion is bumped to 12 for index rebuilds.

Reviewed by Cursor Bugbot for commit 900c89e. Bugbot is set up for automated code reviews on this repo. Configure here.

@JesseHerrick JesseHerrick self-assigned this Jun 3, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 35b1e90. Configure here.

Comment thread internal/treesitter/variables.go
Treat top-level scripts, module bodies, and definition bodies as
separate variable scopes during rename. Resolve plain alias-backed
require/import/use references so related rename edits stay consistent.
@JesseHerrick JesseHerrick force-pushed the fix-bare-script-var-scoping branch from fc226e9 to 900c89e Compare June 11, 2026 03:01
@JesseHerrick JesseHerrick merged commit 3df64e1 into main Jun 11, 2026
5 checks passed
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