You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf: parse code once and share the AST via context - #594
(If the above is not checked) I have reviewed the AI-generated content before submitting.
What is the purpose of this pull request?
Every component that called useAST() parsed the code on its own. Up to three are mounted at once (App, EsquerySelectorInput, and the AST or Scope tab), so each code edit could trigger three parses. Even typing in the ESQuery selector re-parsed the code in each of them.
The Scope tab had a separate problem. The React Compiler silently skipped the Scope component because of a conditional inside a try/catch. With nothing memoized, eslintScope.analyze ran on every render of the tab, including on every selector keystroke.
What changes did you make? (Give an overview)
Added an ASTProvider that parses the code once and shares the result through context. useAST() now reads from that context.
Memoized the parse and the ESQuery match separately, so typing in the selector reruns only the match.
Moved the try/catch in Scope into an analyzeScope helper and memoized the analysis on the AST and the JS options.
Exported the ExplorerState type for the parse input, and updated docs/adding-languages.md to point to the new file.
Reviewing files that changed from the base of the PR and between cd374e2 and 8456248.
📒 Files selected for processing: 5
docs/adding-languages.md
src/components/scope/index.tsx
src/hooks/use-ast.tsx
src/hooks/use-explorer.ts
src/index.tsx
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
📝 Walkthrough
AST parsing and selector matching now run through ASTProvider, which supplies AST results through context. Scope memoizes scope analysis and displays analysis errors. The language-adding guide now documents the provider and language-specific parse options.
Changes: AST and Scope Analysis
Layer / File(s)
Summary
AST result provider and integration src/hooks/use-ast.tsx, src/hooks/use-explorer.ts, src/index.tsx, docs/adding-languages.md
ASTProvider reads parsing inputs and the selector, memoizes parsing and node matching, and supplies AST results through context. The entry point wraps App with the provider. The guide documents ParseInput options and the provider.
Scope analysis and error display src/components/scope/index.tsx
Scope memoizes analysis using the AST result and JavaScript options. Scope analysis returns a scope manager or an error, and Scope displays errors.
sequenceDiagram
participant App
participant ASTProvider
participant ExplorerState
participant parseCode
participant addEsqueryMatchedNodes
participant useAST
App->>ASTProvider: Render inside provider
ASTProvider->>ExplorerState: Read parsing inputs and selector
ASTProvider->>parseCode: Parse language, source, and options
parseCode-->>ASTProvider: Return parse result
ASTProvider->>addEsqueryMatchedNodes: Match nodes using parse result and selector
ASTProvider-->>useAST: Supply AST result through context
Loading
Suggested reviewers:pixel998
Merge Risk:⚪ Minimal · up to 84562
No actionable merge-blocking risk was found; the change is ready for normal checks.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 4 files. (1 skipped: 1 …
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly and concisely describes the main performance change: parsing code once and sharing the AST through context.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 4 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
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
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.
Prerequisites checklist
AI acknowledgment
What is the purpose of this pull request?
Every component that called
useAST()parsed the code on its own. Up to three are mounted at once (App,EsquerySelectorInput, and the AST or Scope tab), so each code edit could trigger three parses. Even typing in the ESQuery selector re-parsed the code in each of them.The Scope tab had a separate problem. The React Compiler silently skipped the
Scopecomponent because of a conditional inside atry/catch. With nothing memoized,eslintScope.analyzeran on every render of the tab, including on every selector keystroke.What changes did you make? (Give an overview)
ASTProviderthat parses the code once and shares the result through context.useAST()now reads from that context.try/catchinScopeinto ananalyzeScopehelper and memoized the analysis on the AST and the JS options.ExplorerStatetype for the parse input, and updateddocs/adding-languages.mdto point to the new file.Related Issues
#64
Is there anything you'd like reviewers to focus on?
Summary by CodeRabbit
Bug Fixes
Refactor
Documentation