Tighten import handling and fix SetComprehension typo#9607
Open
manzt wants to merge 2 commits into
Open
Conversation
Follow up to #9379 `ImportStatement` was collecting every `VariableName` direct child as a binding, including the module path in `from m import ...` and the imported name when shadowed by `as`. Also: - Removed the dead `ImportFromStatement` branch — the Lezer Python grammar only emits `ImportStatement`, so it never matched. - Fixed pre-existing `SetComprehension` typo in reactive-references/analyzer.ts (grammar node is `SetComprehensionExpression`); set comprehensions now correctly create a scope.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
for more information, see https://pre-commit.ci
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens Python import handling in the CodeMirror AST analyzers used for reactive-variable highlighting and go-to-definition, and fixes a grammar-node typo so set comprehensions correctly create a scope.
Changes:
- Fix set comprehension scoping by using the correct Lezer node name (
SetComprehensionExpression). - Refine
ImportStatementbinding collection sofrom m import x as ydoesn’t treatmorxas local bindings (onlyybinds). - Prevent import-statement names from being treated as reactive uses.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/src/core/codemirror/reactive-references/analyzer.ts | Fixes set-comprehension scope creation; improves import binding collection; skips import nodes during reactive-use scan. |
| frontend/src/core/codemirror/reactive-references/tests/analyzer.test.ts | Adds regression tests for set-comprehension scoping and from-import binding/reactive behavior. |
| frontend/src/core/codemirror/go-to-definition/commands.ts | Improves import binding parsing for scoped declaration collection; adjusts fallback behavior when usagePosition is provided. |
| frontend/src/core/codemirror/go-to-definition/tests/utils.test.ts | Adds regression test ensuring cross-cell resolution isn’t blocked by module-path “declarations” in from-imports. |
| frontend/src/core/codemirror/go-to-definition/tests/commands.test.ts | Adds tests covering from-import alias binding semantics and module-path non-binding behavior. |
Comment on lines
+314
to
+321
| if (subCursor.name === "VariableName") { | ||
| commit(); | ||
| pending = options.state.doc.sliceString( | ||
| subCursor.from, | ||
| subCursor.to, | ||
| ); | ||
| // Add to the current innermost scope | ||
| const currentScope = | ||
| currentScopeStack[currentScopeStack.length - 1] ?? -1; | ||
| if (!allDeclarations.has(currentScope)) { | ||
| allDeclarations.set(currentScope, new Set()); | ||
| } | ||
| allDeclarations.get(currentScope)?.add(varName); | ||
| } else if (subCursor.name === ",") { | ||
| commit(); |
Comment on lines
+341
to
352
| if (subCursor.name === "VariableName") { | ||
| // Flush any previous pending name (no `as` followed it). | ||
| commit(); | ||
| pending = { | ||
| from: subCursor.from, | ||
| matches: | ||
| state.doc.sliceString(subCursor.from, subCursor.to) === | ||
| variableName, | ||
| }; | ||
| } else if (subCursor.name === ",") { | ||
| commit(); | ||
| } |
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.
Follow up to #9379
ImportStatementwas collecting everyVariableNamedirect child as a binding, including the module path infrom m import ...and the imported name when shadowed byas.Also:
ImportFromStatementbranch — the Lezer Python grammar only emitsImportStatement, so it never matched.SetComprehensiontypo in reactive-references/analyzer.ts (grammar node isSetComprehensionExpression); set comprehensions now correctly create a scope.