refactor(analyzers): extract TreeSitterAnalyzer base class (T15 #663)#690
refactor(analyzers): extract TreeSitterAnalyzer base class (T15 #663)#690DvirDukhan wants to merge 1 commit into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
📝 WalkthroughWalkthroughThis PR extracts shared tree-sitter boilerplate into a new ChangesTreeSitterAnalyzer Base Class and Migration
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
api/analyzers/tree_sitter_base.py (1)
45-107: ⚡ Quick winAdd a resolver-focused regression.
This refactor moves type/call resolution into shared code, but the new fixture coverage only asserts entity counts and
DEFINESedges. A badtype_resolution_keys/_extract_*/ dispatch change here would still pass, so please add at least one inheritance edge and one call edge assertion that exerciseresolve_symbol.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@api/analyzers/tree_sitter_base.py` around lines 45 - 107, The tests only assert entity counts and DEFINES edges but miss exercising resolve_symbol; add assertions that exercise type and call resolution by creating at least one inheritance edge and one call edge: update the test fixture or test case to trigger TreeSitterBase.resolve_symbol via the existing dispatch keys (ensure type_resolution_keys and method_resolution_keys include the test keys) and/or by customizing _extract_type_target / _extract_call_target to return the captured nodes; then assert an INHERITS (or similar) edge exists for the resolved type (using resolve_type/resolve_symbol) and a CALLS (or similar) edge exists for the resolved callable (using resolve_method/resolve_symbol) so failures in resolve_symbol/type/callor extraction are detected.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@api/analyzers/kotlin/analyzer.py`:
- Around line 112-115: The current object_declaration branch discards the kind
info from _get_delegation_types and always calls
entity.add_symbol("implement_interface"), turning delegated base-class relations
into interfaces; change the loop to unpack the second value returned by
_get_delegation_types (e.g., for node, kind in types) and branch on that kind:
when kind indicates a constructor_invocation (the superclass case) call
entity.add_symbol using the superclass relation symbol (e.g., "extend_class" or
the project’s existing superclass symbol), otherwise call
entity.add_symbol("implement_interface") to preserve interface relations.
---
Nitpick comments:
In `@api/analyzers/tree_sitter_base.py`:
- Around line 45-107: The tests only assert entity counts and DEFINES edges but
miss exercising resolve_symbol; add assertions that exercise type and call
resolution by creating at least one inheritance edge and one call edge: update
the test fixture or test case to trigger TreeSitterBase.resolve_symbol via the
existing dispatch keys (ensure type_resolution_keys and method_resolution_keys
include the test keys) and/or by customizing _extract_type_target /
_extract_call_target to return the captured nodes; then assert an INHERITS (or
similar) edge exists for the resolved type (using resolve_type/resolve_symbol)
and a CALLS (or similar) edge exists for the resolved callable (using
resolve_method/resolve_symbol) so failures in resolve_symbol/type/callor
extraction are detected.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9e0be41b-01fa-4693-a9fe-0b21241282e7
📒 Files selected for processing (9)
api/analyzers/javascript/analyzer.pyapi/analyzers/kotlin/analyzer.pyapi/analyzers/python/analyzer.pyapi/analyzers/tree_sitter_base.pytests/analyzers/__init__.pytests/analyzers/fixtures/multilang/sample.jstests/analyzers/fixtures/multilang/sample.kttests/analyzers/fixtures/multilang/sample.pytests/analyzers/test_tree_sitter_base.py
| elif entity.node.type == 'object_declaration': | ||
| types = self._get_delegation_types(entity) | ||
| for node, _ in types: | ||
| entity.add_symbol("implement_interface", node) |
There was a problem hiding this comment.
Preserve superclass vs interface symbols for object declarations.
_get_delegation_types() already tells you whether a delegated type came from a constructor_invocation, but this branch drops that bit and records every entry as implement_interface. That turns object Foo : Base() into an interface relation instead of a base-class relation, which changes graph semantics in this “non-functional” refactor.
Suggested fix
elif entity.node.type == 'object_declaration':
types = self._get_delegation_types(entity)
- for node, _ in types:
- entity.add_symbol("implement_interface", node)
+ for node, is_class in types:
+ if is_class:
+ entity.add_symbol("base_class", node)
+ else:
+ entity.add_symbol("implement_interface", node)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@api/analyzers/kotlin/analyzer.py` around lines 112 - 115, The current
object_declaration branch discards the kind info from _get_delegation_types and
always calls entity.add_symbol("implement_interface"), turning delegated
base-class relations into interfaces; change the loop to unpack the second value
returned by _get_delegation_types (e.g., for node, kind in types) and branch on
that kind: when kind indicates a constructor_invocation (the superclass case)
call entity.add_symbol using the superclass relation symbol (e.g.,
"extend_class" or the project’s existing superclass symbol), otherwise call
entity.add_symbol("implement_interface") to preserve interface relations.
Summary
TreeSitterAnalyzerwithout changing analyzer graph semantics.Before/after line counts
api/analyzers/tree_sitter_base.py: 0 -> 107api/analyzers/python/analyzer.py: 124 -> 100api/analyzers/javascript/analyzer.py: 172 -> 128api/analyzers/kotlin/analyzer.py: 157 -> 155Base-class hooks
entity_node_typesdrives default entity types and labels.type_definition_node_types/callable_definition_node_typesdrive shared parent resolution.type_resolution_keys/method_resolution_keysdriveresolve_symboldispatch._extract_type_targetand_extract_call_targetpreserve Python/JavaScript AST target normalization.resolve_methodoverride for child-identifier iteration.Closes #663
Summary by CodeRabbit
Release Notes
Refactor
Tests