Skip to content

feat: add TypeScript and TSX analyzer#610

Open
davidsuarezcdo wants to merge 1 commit intoFalkorDB:stagingfrom
davidsuarezcdo:feat/typescript-analyzer
Open

feat: add TypeScript and TSX analyzer#610
davidsuarezcdo wants to merge 1 commit intoFalkorDB:stagingfrom
davidsuarezcdo:feat/typescript-analyzer

Conversation

@davidsuarezcdo
Copy link

@davidsuarezcdo davidsuarezcdo commented Mar 12, 2026

Summary

  • Adds TypeScriptAnalyzer following the exact same pattern as PythonAnalyzer, JavaAnalyzer, and CSharpAnalyzer
  • Supports .ts and .tsx file extensions (shared analyzer instance)
  • Extracts class_declaration, interface_declaration, function_declaration, and method_definition entities
  • Captures inheritance (extends), interface implementation (implements), method calls, parameters, and return types for LSP symbol resolution
  • Registers typescript-language-server via multilspy in second_pass() for cross-file symbol resolution
  • Adds tree-sitter-typescript>=0.23.2,<0.24.0 to pyproject.toml

Test plan

  • Verify TypeScriptAnalyzer instantiates correctly (from api.analyzers.typescript.analyzer import TypeScriptAnalyzer)
  • Confirm .ts and .tsx appear in SourceAnalyzer.supported_types()
  • Run analyze_sources against a TypeScript project and verify classes/functions/interfaces appear in the graph
  • Confirm typescript-language-server resolves cross-file symbols (requires typescript-language-server installed globally)

Summary by CodeRabbit

  • New Features

    • Added TypeScript and TSX file analysis and parsing capabilities.
    • Extended symbol resolution and dependency management to support TypeScript projects.
    • Analysis framework now covers TypeScript alongside Java, Python, and C#.
  • Chores

    • Added TypeScript parser dependency.

@vercel
Copy link

vercel bot commented Mar 12, 2026

@davidsuarezcdo is attempting to deploy a commit to the FalkorDB Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2026

📝 Walkthrough

Walkthrough

TypeScript language support is integrated into the source analyzer framework. A new TypeScriptAnalyzer class implements parsing, entity extraction, and symbol resolution for .ts and .tsx files using tree-sitter. The analyzer is registered in the main analyzer dispatcher and configured with LSP support. A tree-sitter-typescript dependency is added.

Changes

Cohort / File(s) Summary
TypeScript Analyzer Integration
api/analyzers/source_analyzer.py
Import TypeScriptAnalyzer; register .ts and .tsx file extensions; initialize TypeScript LSP server when TypeScript files present; include TypeScript patterns in source file discovery.
TypeScript Analyzer Implementation
api/analyzers/typescript/analyzer.py
New TypeScriptAnalyzer class extending AbstractAnalyzer with methods for dependency handling, entity identification (label, name, docstring), symbol extraction (base classes, interfaces, function parameters, call references), and multi-file resolution workflows via LSP integration.
Dependency Management
pyproject.toml
Add tree-sitter-typescript>=0.23.2,<0.24.0 dependency.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 A rabbit hops through TypeScript trees so bright,
With tree-sitter parsing each node just right,
LSP servers dance, symbols resolve true,
From .ts to .tsx, the analyzer's all new!
Happy hopping through type-safe delight!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding TypeScript and TSX analyzer support to the codebase.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can suggest fixes for GitHub Check annotations.

Configure the reviews.tools.github-checks setting to adjust the time to wait for GitHub Checks to complete.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
api/analyzers/source_analyzer.py (1)

30-32: Consider sharing a single TypeScriptAnalyzer instance for .ts and .tsx.

Currently, two separate TypeScriptAnalyzer() instances are created. While functionally correct, sharing a single instance (like Python does for .py) would be more memory efficient.

However, note that the more significant concern is whether the TypeScript grammar correctly parses TSX files (flagged separately in analyzer.py).

♻️ Proposed fix to share instance
+_ts_analyzer = TypeScriptAnalyzer()
 analyzers: dict[str, AbstractAnalyzer] = {
     # '.c': CAnalyzer(),
     # '.h': CAnalyzer(),
     '.py': PythonAnalyzer(),
     '.java': JavaAnalyzer(),
-    '.cs': CSharpAnalyzer(),
-    '.ts': TypeScriptAnalyzer(),
-    '.tsx': TypeScriptAnalyzer()}
+    '.cs': CSharpAnalyzer(),
+    '.ts': _ts_analyzer,
+    '.tsx': _ts_analyzer}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/analyzers/source_analyzer.py` around lines 30 - 32, The mapping currently
constructs two separate TypeScriptAnalyzer() instances for '.ts' and '.tsx';
change it to create a single TypeScriptAnalyzer instance (e.g., ts_analyzer =
TypeScriptAnalyzer()) and reuse that instance for both keys so both '.ts' and
'.tsx' reference the same TypeScriptAnalyzer object (update the dict entries
that reference TypeScriptAnalyzer() accordingly).
api/analyzers/typescript/analyzer.py (1)

5-5: Replace star import with explicit imports.

The star import makes it unclear which names are being used and triggers static analysis warnings (F403, F405). Based on usage in this file, explicitly import the required entities.

♻️ Proposed fix
-from ...entities import *
+from ...entities import Entity, File
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/analyzers/typescript/analyzer.py` at line 5, Replace the wildcard import
"from ...entities import *" in analyzer.py with an explicit import list
containing only the symbols actually referenced in this file; open analyzer.py,
identify every name used from the entities module (types, classes, constants,
e.g., any Entity/Result/Error types you reference) and change the import to
"from ...entities import NameA, NameB, NameC" accordingly, then run the
linter/pytest to ensure F403/F405 warnings are resolved.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@api/analyzers/typescript/analyzer.py`:
- Around line 19-23: The add_dependencies function currently ignores the files
parameter, calls npm without check=True so failures are silent, and uses the
bare "npm" executable which is a security risk; update add_dependencies to (1)
rename or use the files parameter (or change it to _files) to satisfy linting,
(2) resolve the full npm path via shutil.which and raise/log a clear error if
not found, and (3) call subprocess.run with check=True (and optionally
capture_output=True) inside a try/except to handle and surface installation
failures (log or re-raise with context), referencing the add_dependencies method
and the path argument to locate where to implement these changes.

---

Nitpick comments:
In `@api/analyzers/source_analyzer.py`:
- Around line 30-32: The mapping currently constructs two separate
TypeScriptAnalyzer() instances for '.ts' and '.tsx'; change it to create a
single TypeScriptAnalyzer instance (e.g., ts_analyzer = TypeScriptAnalyzer())
and reuse that instance for both keys so both '.ts' and '.tsx' reference the
same TypeScriptAnalyzer object (update the dict entries that reference
TypeScriptAnalyzer() accordingly).

In `@api/analyzers/typescript/analyzer.py`:
- Line 5: Replace the wildcard import "from ...entities import *" in analyzer.py
with an explicit import list containing only the symbols actually referenced in
this file; open analyzer.py, identify every name used from the entities module
(types, classes, constants, e.g., any Entity/Result/Error types you reference)
and change the import to "from ...entities import NameA, NameB, NameC"
accordingly, then run the linter/pytest to ensure F403/F405 warnings are
resolved.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9c0d19f3-2266-4cdf-9632-367d1b34a8a5

📥 Commits

Reviewing files that changed from the base of the PR and between 73ddd82 and a5f1bff.

📒 Files selected for processing (4)
  • api/analyzers/source_analyzer.py
  • api/analyzers/typescript/__init__.py
  • api/analyzers/typescript/analyzer.py
  • pyproject.toml

Comment on lines +19 to +23
def add_dependencies(self, path: Path, files: list[Path]):
if Path(f"{path}/node_modules").is_dir():
return
if Path(f"{path}/package.json").is_file():
subprocess.run(["npm", "install"], cwd=str(path))
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Add error handling for npm install and consider security implications.

  1. The files parameter is unused (Ruff ARG002).
  2. subprocess.run without check=True silently ignores failures.
  3. Using partial executable path "npm" (Ruff S607) could be a security concern in certain environments.
🛡️ Proposed fix with error handling
-    def add_dependencies(self, path: Path, files: list[Path]):
+    def add_dependencies(self, path: Path, files: list[Path]):  # noqa: ARG002
         if Path(f"{path}/node_modules").is_dir():
             return
         if Path(f"{path}/package.json").is_file():
-            subprocess.run(["npm", "install"], cwd=str(path))
+            try:
+                subprocess.run(["npm", "install"], cwd=str(path), check=True)
+            except subprocess.CalledProcessError as e:
+                logger.warning(f"npm install failed: {e}")
🧰 Tools
🪛 Ruff (0.15.5)

[warning] 19-19: Unused method argument: files

(ARG002)


[error] 23-23: Starting a process with a partial executable path

(S607)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/analyzers/typescript/analyzer.py` around lines 19 - 23, The
add_dependencies function currently ignores the files parameter, calls npm
without check=True so failures are silent, and uses the bare "npm" executable
which is a security risk; update add_dependencies to (1) rename or use the files
parameter (or change it to _files) to satisfy linting, (2) resolve the full npm
path via shutil.which and raise/log a clear error if not found, and (3) call
subprocess.run with check=True (and optionally capture_output=True) inside a
try/except to handle and surface installation failures (log or re-raise with
context), referencing the add_dependencies method and the path argument to
locate where to implement these changes.

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