As AI coding assistants generate hundreds of lines of code across numerous files, traditional code review practices are becoming increasingly difficult to sustain. Writing code guided by large language models often outpaces a developer's ability to maintain architectural context. Addressing this challenge requires treating a codebase not merely as a collection of individual files, but as a structured call graph where functions act as nodes and calls serve as edges. A technical article published by freeCodeCamp details how developers can leverage TypeScript and VS Code's internal language APIs to automatically generate multi-hop code graphs.
Leveraging Language Server Intelligence
Rather than writing custom parsers for individual programming languages, developers can extract rich semantic information directly from VS Code's extension infrastructure. By making use of command providers like executeDocumentSymbolProvider and prepareCallHierarchy, custom extensions can query language servers such as TypeScript's native service, gopls for Go, or Pyright for Python. This approach offloads cross-file symbol resolution and import tracking to the editor's existing intelligence layer.
Stable Identification and Deduplication
To construct an accurate call graph across complex codebases, function names alone are insufficient due to potential collisions across different files. The published architecture uses a combination of file URIs and start positions—specifically selectionRange properties—to derive stable symbol identifiers. A unified symbol registry tracks incoming and outgoing calls to deduplicate references, ensuring that functions imported across multiple files collapse into single logical nodes within the visual output.
BFS Traversal and Concurrency Control
Navigating multi-hop call relationships requires systematically traversing incoming and outgoing calls starting from an active file or symbol. Utilizing Breadth-First Search (BFS) allows the graph engine to explore dependencies level by level up to a defined depth limit. Because querying language servers involves asynchronous extension calls, controlling execution limits through concurrent operational queues prevents performance bottlenecks during deep graph exploration.
AI-generated editorial illustration; not a documentary photograph.
Source:
How to Build a Code Graph in TypeScript Using VS Code's Language APIs

Leave a Reply