Add TypeScript import path resolver with tsconfig paths support#642
Open
alex4o wants to merge 4 commits intoCodeGraphContext:mainfrom
Open
Add TypeScript import path resolver with tsconfig paths support#642alex4o wants to merge 4 commits intoCodeGraphContext:mainfrom
alex4o wants to merge 4 commits intoCodeGraphContext:mainfrom
Conversation
Use the tsx tree-sitter grammar for .tsx files (the typescript grammar misparses JSX as type assertions). Override _find_calls() in TypescriptJSXTreeSitterParser to capture jsx_opening_element and jsx_self_closing_element nodes, filtering to PascalCase names only. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Resolve TS/JS import specifiers to absolute file paths during indexing so that Module nodes use resolved paths instead of raw specifiers. This makes File->Module->File traversal work correctly for relative and alias imports. - Create ts_import_resolver.py handling relative, alias (tsconfig paths), and bare specifier imports with extension/index file resolution - Fix lang routing bug: include 'typescript' and 'typescriptjsx' alongside 'javascript' in the import handling branch of graph_builder - Parse tsconfig.json once per indexing run (supports baseUrl, paths, extends, comments, trailing commas) - Store raw_specifier on Module nodes for debugging - Add test fixture files with tsconfig paths aliases (@utils/*, @models/*, @shared/*, @app/*) and corresponding source files - Add 50 unit + integration tests covering resolver, tsconfig parsing, and end-to-end resolution with real TS parser output Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Add ts_import_resolver for resolving TypeScript path aliases from tsconfig.json - Track JSX component usage as CALLS relationships in graph builder - Add TSX test fixtures and e2e test for TypeScript indexing - Update sample TypeScript project with TSX components Amp-Thread-ID: https://ampcode.com/threads/T-019c6303-d1c9-763f-b9ab-08be8da73f8a Co-authored-by: Amp <[email protected]>
|
@alex4o is attempting to deploy a commit to the shashankss1205's projects Team on Vercel. A member of the Team first needs to authorize it. |
…icity - Resolve baseUrl-only imports (e.g. "utils/foo") before dismissing as bare specifiers - Replace naive regex comment stripping with state-aware parser to avoid corrupting strings containing "//" - Sort tsconfig path patterns by specificity (longest first) to match TypeScript behavior - Remove debug log from graph_builder.py - Improve E2E test assertions to parse JSON values instead of fragile string checks - Restore .cgcignore file Co-Authored-By: Claude Opus 4.6 <[email protected]>
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.
What
Index
<JSXComponent />tags as call-sites so component usage shows up in the code graph.Resolve TS/TSX import paths (aliases from
tsconfig.jsonand relative imports) to absolute file paths so two files importing the same module share oneModulenode instead of creating duplicates.Why
Without this:
<Layout>or<Button />in.tsxfiles are invisible to the graph — noCALLSedge is created.import { capitalize } from "@utils/string-helpers"andimport { capitalize } from "./utils/string-helpers"produce two separateModulenodes for the same file, fragmenting the graph.How
JSX call-site indexing
TypescriptJSXTreeSitterParser(extends the TS parser) with a_find_callsoverride that runs a tree-sitter query forjsx_opening_element/jsx_self_closing_element.<div>) is ignored..tsxfiles now use the newtypescriptjsxparser instead of reusingtypescript.TS import resolution
ts_import_resolver.pymodule with:parse_tsconfig_paths(project_root)— readstsconfig.json(handles//comments, trailing commas, one level ofextends), returnsbaseUrl+pathsmap.resolve_ts_import(specifier, importing_file, ...)— resolves in order: relative → alias → baseUrl → bare (returnsNonefor npm packages)._try_resolve_file(base)— tries exact path →.ts/.tsx/.js/.jsx→index.{ts,tsx,js,jsx}.graph_builder.pycallsparse_tsconfig_pathsonce per indexing run, then passes the config toadd_file_to_graphwhere each import is resolved beforeMERGE (m:Module {name: $resolved_path}).Modulenodes now also storeraw_specifier(the original import string) for debugging.Example
Testing
test_ts_import_resolver.py, 25 tests):_try_resolve_file, relative imports, bare specifiers, alias imports,tsconfig.jsonparsing (comments, trailing commas, extends).test_ts_import_resolver_integration.py, 14 tests): parse the real fixtureapp-service.tswith tree-sitter, then resolve every import against the fixture'stsconfig.json.test_ts_indexing.py): index the full TS fixture into the DB and verify via Cypher that alias imports resolve to absolute paths, bare specifiers stay raw, JSX component calls are detected, and no duplicateModulenodes exist.sample_project_typescriptwithtsconfig.jsonpaths,.tsxcomponents (App.tsx,Layout.tsx,Button.tsx), alias-imported modules (string-helpers,math-helpers,user-model,constants,logger), andapp-service.tsexercising all import patterns.