scip-typescript: a new TypeScript and JavaScript indexer
We are excited to announce the release of scip-typescript, a new indexer that allows you to navigate TypeScript and JavaScript codebases on Sourcegraph with compiler-accurate precision. Key features of scip-typescript include:
- Performance: scip-typescript is almost as fast as the TypeScript typechecker, indexing 1k-5k lines per second depending on the usage of types in your codebase. If you’re migrating from lsif-node, our older TypeScript indexer, you can expect to see 3-10x speedups after migrating to scip-typescript.
- Cross-repository navigation: scip-typescript is designed from the ground up to support navigating between multiple repositories. You can follow symbols between multiple TypeScript projects, or even between your codebase and package.json dependencies.
- Find implementations: You can navigate from an interface, interface property, abstract class, or abstract method to its concrete implementations.
The name “scip-typescript†is derived from SCIP, a new code indexing format that we are using at Sourcegraph. You can learn about SCIP by reading the announcement here.
Get started with scip-typescript
Use the scip-typescript index
command to index a TypeScript codebase.
bash yarn global add @sourcegraph/scip-typescript @sourcegraph/src cd my-typescript-project yarn install # Or npm install scip-typescript index # Optionally include --yarn-workspaces src lsif upload # Upload the index to Sourcegraph
Use the --infer-tsconfig
flag for pure JavaScript projects. Optionally, to improve the quality of the indexed data, add @types/*
devDependencies
for JavaScript dependencies that have available TypeScript definitions.
bash scip-typescript index --infer-tsconfig
Performance
Indexing a codebase with scip-typescript should have roughly similar performance as type checking the codebase with tsc
. We built scip-typescript with the TypeScript type checker and our benchmarks indicate that indexing performance is largely bottlenecked by type checking performance.
We benchmarked scip-typescript by running it against several open source codebases to measure the indexing performance. The numbers are measured with a 2019 MacBook Pro with a 2.6 GHz 6-Core Intel Core.
Lines of code scip-typescript index (s) loc/s Size (gzip, MB) coder/code-server 6,545 6,4 1,023 2,1 sunflower-land/sunflower-land 20,824 11,6 1,795 0, 4 react-navigation/react-navigation 36,024 14,5 2,484 0,6 vercel/next.js 68,107 14,3 4,763 9,3 typeorm/typeorm 81,087 27,9 2,906 3,4 Microsoft/TypeScript/src/compiler 111,155 22,7 4,897 3,2 sourcegraph/sourcegraph 263,010 154,35 1,704 6,2
The indexing performance varies from codebase to codebase, ranging anywhere between 1k-5k lines of code per second. Given the large variation in indexing performance, the best way to understand real-world scip-typescript performance is to run it against your codebase.
Our experience is that the scip-typescript index
command is not always a bottleneck in a CI pipeline when you take into account all steps such as git clone
to checkout the source code and yarn install
to download external dependencies.
Cross-repository navigation
The actions “Go to definition†and “Find references†work across your codebase and package.json dependencies. Try this out yourself by opening the github.com/vendure-ecommerce/vendure repository and navigating to the definition of the arguments()
method that’s defined by the commander
npm package.
Likewise, trigger “Find references†on the action()
method to get real-world examples of that symbol across multiple repositories and packages.