### Install scip-typescript CLI Tool Source: https://github.com/sourcegraph/scip-typescript/blob/main/README.md Installs the scip-typescript command-line interface globally using npm. This command requires Node.js and npm to be installed. Supported Node.js versions are v18 and v20. ```shell npm install -g @sourcegraph/scip-typescript ``` -------------------------------- ### Index a TypeScript Project Source: https://github.com/sourcegraph/scip-typescript/blob/main/README.md Indexes a TypeScript project by running 'npm install' (or 'yarn install') followed by the 'scip-typescript index' command. This assumes a 'tsconfig.json' file exists in the project root. The output is a SCIP index file. ```shell npm install # or yarn install scip-typescript index ``` -------------------------------- ### Index TypeScript Project with pnpm Workspaces Source: https://github.com/sourcegraph/scip-typescript/blob/main/README.md Indexes a TypeScript project managed with pnpm workspaces. It requires running 'pnpm install' followed by 'scip-typescript index --pnpm-workspaces'. This command is tailored for projects utilizing pnpm's workspace capabilities. ```shell pnpm install scip-typescript index --pnpm-workspaces ``` -------------------------------- ### CI Integration for Indexing and Uploading Source: https://github.com/sourcegraph/scip-typescript/blob/main/README.md Sets up a CI pipeline to install scip-typescript and src, index the project, and upload the SCIP index to Sourcegraph. It uses GitHub secrets for authentication. The 'src lsif upload' command requires the '@sourcegraph/src' package. ```shell npm install -g @sourcegraph/scip-typescript @sourcegraph/src npm install # or yarn install scip-typescript index # Upload index with any necessary tokens (shown here using GitHub workflow syntax) src lsif upload -github-token='${{ secrets.GITHUB_TOKEN }}' -no-progress ``` -------------------------------- ### Index a JavaScript Project Source: https://github.com/sourcegraph/scip-typescript/blob/main/README.md Indexes a JavaScript project by running 'npm install' (or 'yarn install') followed by 'scip-typescript index --infer-tsconfig'. This command infers the tsconfig and is recommended for JavaScript projects. Consider adding '@types/*' packages as devDependencies for better results. ```shell npm install # or yarn install scip-typescript index --infer-tsconfig ``` -------------------------------- ### Index TypeScript Project with Yarn Workspaces Source: https://github.com/sourcegraph/scip-typescript/blob/main/README.md Indexes a TypeScript project managed with Yarn workspaces. This involves running 'yarn install' followed by 'scip-typescript index --yarn-workspaces'. This command is specific to projects using Yarn's workspace feature. ```shell yarn install scip-typescript index --yarn-workspaces ``` -------------------------------- ### Infer tsconfig.json for JavaScript Projects Source: https://context7.com/sourcegraph/scip-typescript/llms.txt Shows how to generate a default tsconfig.json file for JavaScript projects that do not have one. This function enables the indexing of pure JavaScript codebases by providing necessary compiler options. The example includes writing the inferred configuration to a file and using it with the scip-typescript index command. ```typescript import { inferTsconfig } from './inferTsconfig' import * as fs from 'fs' // Example: Generate tsconfig.json for a JavaScript project const projectPath = '/path/to/js-project' const tsconfigContent = inferTsconfig(projectPath) // Write inferred configuration to file fs.writeFileSync(`${projectPath}/tsconfig.json`, tsconfigContent) // Generated tsconfig.json content: // { // "compilerOptions": { // "allowJs": true, // "checkJs": false, // "noEmit": true, // "skipLibCheck": true, // "target": "ES2020", // "module": "commonjs", // "moduleResolution": "node" // }, // "include": ["**/*.js", "**/*.jsx"], // "exclude": ["node_modules", "dist", "build"] // } // Use with index command // scip-typescript index --infer-tsconfig ``` -------------------------------- ### Snapshot Project with tsx and lsif-typed Source: https://github.com/sourcegraph/scip-typescript/blob/main/Development.md Commands to snapshot an arbitrary project using tsx and lsif-typed. This involves navigating to the project directory, running the scip-typescript main script, and then processing the output with lsif-typed. ```sh cd /path/to/dir DIR=/path/to/scip-typescript "$DIR/node_modules/.bin/tsx" "$DIR/src/main.ts" index # add --yarn-workspaces if applicable lsif-typed index.scip > dump.lsif # from github.com/sourcegraph/sourcegraph/lib/codeintel/tools/lsif-typed lsif-java snapshot-lsif # from github.com/sourcegraph/lsif-java ``` -------------------------------- ### Migrate from lsif-node to scip-typescript Source: https://github.com/sourcegraph/scip-typescript/blob/main/README.md Provides instructions for migrating from the older 'lsif-node' indexer to 'scip-typescript'. This involves replacing 'lsif-tsc -p ARGUMENTS' with 'scip-typescript index ARGUMENTS' and upgrading the 'src' CLI tool. ```shell # Replace usages of the `lsif-tsc -p ARGUMENTS` command with `scip-typescript index ARGUMENTS`. # Upgrade to the latest version of the `src` command-line interface yarn global add @sourcegraph/src ``` -------------------------------- ### Index a TypeScript File with FileIndexer Source: https://context7.com/sourcegraph/scip-typescript/llms.txt Demonstrates the process of indexing a single TypeScript file using the FileIndexer class. It covers setting up the TypeScript program, creating necessary input objects, and initiating the indexing process. The output includes generated SCIP occurrences and symbol information. ```typescript import * as ts from 'typescript' import { FileIndexer } from './FileIndexer' import { ProjectOptions } from './CommandLineOptions' import { Input } from './Input' import { Packages } from './Packages' import { ScipSymbol } from './ScipSymbol' import * as scip from './scip' // Example: Index a single TypeScript file const program = ts.createProgram(['./example.ts'], {}) const checker = program.getTypeChecker() const sourceFile = program.getSourceFile('./example.ts') const document = new scip.scip.Document({ relative_path: 'example.ts', occurrences: [], symbols: [] }) const input = new Input('./example.ts', sourceFile.getText()) const packages = new Packages('/project/root') const globalSymbolTable = new Map() const globalConstructorTable = new Map() const options: ProjectOptions = { cwd: '/project/root', projectRoot: './src', projectDisplayName: './src', output: 'index.scip', inferTsconfig: false, progressBar: false, yarnWorkspaces: false, yarnBerryWorkspaces: false, pnpmWorkspaces: false, globalCaches: true, maxFileByteSizeNumber: 1024 * 1024, indexedProjects: new Set(), writeIndex: (index: scip.scip.Index) => {} } const fileIndexer = new FileIndexer( checker, options, input, document, globalSymbolTable, globalConstructorTable, packages, sourceFile ) fileIndexer.index() // Result: document.occurrences contains all symbol occurrences // Result: document.symbols contains symbol information with documentation // Example occurrence: {symbol: 'scip-typescript npm @sourcegraph/scip-typescript 0.4.0 src/`example.ts`/MyClass#', range: [0, 6, 6, 13], symbol_roles: 1} ``` -------------------------------- ### Programmatic Indexing of Multiple Projects Source: https://context7.com/sourcegraph/scip-typescript/llms.txt The `indexCommand` function orchestrates the indexing of multiple projects programmatically. It takes an array of project paths and an options object to configure the indexing process, generating a SCIP index file. ```typescript import { indexCommand } from './main' import { MultiProjectOptions } from './CommandLineOptions' // Example: Programmatic indexing of multiple projects const options: MultiProjectOptions = { cwd: '/path/to/workspace', output: 'index.scip', inferTsconfig: false, progressBar: true, yarnWorkspaces: false, yarnBerryWorkspaces: false, pnpmWorkspaces: false, globalCaches: true, maxFileByteSize: '1mb', maxFileByteSizeNumber: 1024 * 1024, indexedProjects: new Set() } const projects = ['./packages/core', './packages/utils'] // Generate SCIP index for specified projects indexCommand(projects, options) // Output: Creates index.scip file with serialized SCIP data // Console: "+ /path/to/workspace (2s 456ms)" ``` -------------------------------- ### Run and Update Snapshot Tests Source: https://github.com/sourcegraph/scip-typescript/blob/main/Development.md Commands to execute snapshot tests and update their output. These are crucial for verifying the correctness of code navigation functionality against expected results. ```sh # Run snapshot tests npm run test # Update snapshot test outputs npm run update-snapshots ``` -------------------------------- ### CLI: Index TypeScript/JavaScript Projects Source: https://context7.com/sourcegraph/scip-typescript/llms.txt The `index` command is used to generate SCIP indexes from TypeScript/JavaScript projects. It supports various options for project discovery, configuration, and output customization, including inferring tsconfig, handling workspaces, and setting file size limits. ```bash # Index a TypeScript project with tsconfig.json npm install -g @sourcegraph/scip-typescript cd /path/to/project npm install scip-typescript index # Index a JavaScript project without tsconfig.json scip-typescript index --infer-tsconfig # Index all Yarn workspace packages scip-typescript index --yarn-workspaces # Index all pnpm workspace packages scip-typescript index --pnpm-workspaces # Specify custom output file and working directory scip-typescript index --cwd ./src --output code-index.scip # Enable progress bar for large projects scip-typescript index --progress-bar # Disable global caches to reduce memory usage scip-typescript index --no-global-caches # Set maximum file size to index (skip large files) scip-typescript index --max-file-byte-size 2mb ``` -------------------------------- ### Index Single TypeScript Project with ProjectIndexer Source: https://context7.com/sourcegraph/scip-typescript/llms.txt The `ProjectIndexer` class handles indexing for a single TypeScript project. It initializes the TypeScript program and type checker, then coordinates file-level indexing, supporting progress tracking and caching. The `writeIndex` callback is used to process generated SCIP data. ```typescript import * as ts from 'typescript' import { ProjectIndexer } from './ProjectIndexer' import { ProjectOptions, GlobalCache } from './CommandLineOptions' import * as scip from './scip' // Example: Index a single TypeScript project const config: ts.ParsedCommandLine = ts.parseCommandLine( ['-p', './tsconfig.json'], (relativePath: string) => path.resolve('./tsconfig.json', relativePath) ) const cache: GlobalCache = { sources: new Map(), parsedCommandLines: new Map() } let documentCount = 0 const options: ProjectOptions = { cwd: '/path/to/project', projectRoot: './src', projectDisplayName: './src', output: 'index.scip', inferTsconfig: false, progressBar: false, yarnWorkspaces: false, yarnBerryWorkspaces: false, pnpmWorkspaces: false, globalCaches: true, indexedProjects: new Set(), writeIndex: (index: scip.scip.Index) => { documentCount += index.documents.length console.log(`Indexed ${index.documents.length} documents`) } } const indexer = new ProjectIndexer(config, options, cache) indexer.index() // Output: "+ ./src (1s 234ms)" // Calls writeIndex callback for each batch of indexed files ``` -------------------------------- ### Bump Version and Publish Release Source: https://github.com/sourcegraph/scip-typescript/blob/main/Development.md Shell command to bump the version of the scip-typescript project and push a git tag. This script automates the versioning process and triggers a CI job for release. ```sh ./dev/bump-version VERSION_TO_RELEASE # example: ./dev/bump-version 2.3.1 ``` -------------------------------- ### Discover Yarn and pnpm Workspace Packages in TypeScript Source: https://context7.com/sourcegraph/scip-typescript/llms.txt These functions discover workspace packages in monorepos using Yarn or pnpm. They execute shell commands and parse the output to return an array of package paths. Requires Node.js `child_process` module. ```typescript import { execSync } from 'child_process' // Example: Discover Yarn workspace packages function listYarnWorkspaces(directory: string, yarnVersion: 'tryYarn1' | 'yarn2Plus'): string[] { // For Yarn 2+ (example assumes Yarn 2+ for simplicity) const output = execSync('yarn --json workspaces list', { cwd: directory, encoding: 'utf-8' }) // Output parsing logic would go here to extract paths return [] // Placeholder for actual parsed output } // Example: Discover pnpm workspace packages function listPnpmWorkspaces(directory: string): string[] { const output = execSync('pnpm ls -r --depth -1 --long --parseable', { cwd: directory, encoding: 'utf-8' }) // Output parsing logic would go here to extract paths return [] // Placeholder for actual parsed output } // Usage in indexing import { indexCommand } from './main' const options = { cwd: '/monorepo/root', output: 'index.scip', pnpmWorkspaces: true, // ... other options } // indexCommand([], options) // This would trigger workspace discovery if configured ``` -------------------------------- ### Global Cache Implementation for TypeScript Indexing Source: https://context7.com/sourcegraph/scip-typescript/llms.txt Demonstrates the creation and usage of the GlobalCache object for optimizing multi-project TypeScript indexing. It caches parsed source files and command lines to improve performance and reduce memory consumption. Caching can be disabled via a command-line flag. ```typescript import { GlobalCache } from './CommandLineOptions' import * as ts from 'typescript' // Example: Create and use global cache for multi-project indexing const cache: GlobalCache = { sources: new Map(), parsedCommandLines: new Map() } // First project indexes node_modules/@types/react/index.d.ts // Cache stores: sources.set('node_modules/@types/react/index.d.ts', [sourceFile, languageVersion]) // Second project also uses @types/react // Cache hit: Reuses parsed source file instead of re-parsing // Performance: 30-50% faster indexing for monorepos with shared dependencies // Disable caching to reduce memory usage: // scip-typescript index --no-global-caches // Trade-off: Slower indexing but lower memory footprint (useful for large codebases) ``` -------------------------------- ### Troubleshoot Indexing Progress with Progress Bar Source: https://github.com/sourcegraph/scip-typescript/blob/main/README.md Enables a progress bar for the 'scip-typescript index' command to help diagnose stalled indexing. This is done by adding the '--progress-bar' flag. The progress bar is disabled by default to reduce noise in CI logs. ```shell scip-typescript index --progress-bar ``` -------------------------------- ### Parse Human Byte Size into Number in TypeScript Source: https://context7.com/sourcegraph/scip-typescript/llms.txt Converts human-readable byte size strings (e.g., '1kb', '2mb') into their numeric byte equivalents. Handles various units and plain numbers, returning NaN for invalid input. Useful for configuration thresholds. ```typescript import { parseHumanByteSizeIntoNumber } from './parseHumanByteSizeIntoNumber' // Example: Parse various byte size formats const size1 = parseHumanByteSizeIntoNumber('1kb') // Result: 1024 const size2 = parseHumanByteSizeIntoNumber('2mb') // Result: 2097152 const size3 = parseHumanByteSizeIntoNumber('1gb') // Result: 1073741824 const size4 = parseHumanByteSizeIntoNumber('500') // Result: 500 (plain number, assumed bytes) const size5 = parseHumanByteSizeIntoNumber('invalid') // Result: NaN // Usage with index command // scip-typescript index --max-file-byte-size 5mb // Skips files larger than 5 megabytes during indexing ``` -------------------------------- ### Generate SCIP Symbol Relationships for Inheritance in TypeScript Source: https://context7.com/sourcegraph/scip-typescript/llms.txt Demonstrates the generation of SCIP relationship data, specifically for inheritance and implementation. This data helps code navigation tools understand class hierarchies and interface implementations. Requires the `scip` library. ```typescript // Example TypeScript code being indexed: // interface Animal { // speak(): void // } // // class Dog implements Animal { // speak(): void { // console.log('woof') // } // } // Generated SCIP relationships for Dog class: const dogClassRelationships = [ new scip.scip.Relationship({ symbol: 'scip-typescript npm package 1.0.0 src/`animal.ts`/Animal#', is_implementation: true, is_reference: false }) ] // Generated SCIP relationships for Dog.speak method: const dogSpeakRelationships = [ new scip.scip.Relationship({ symbol: 'scip-typescript npm package 1.0.0 src/`animal.ts`/Animal#speak().', is_implementation: true, is_reference: true }) ] // Result: Code navigation tools can: // - Show "Go to interface" from Dog class // - Show "Find implementations" from Animal interface // - Display method override indicators ``` -------------------------------- ### Address Out of Memory Errors (Increase Node.js Heap Size) Source: https://github.com/sourcegraph/scip-typescript/blob/main/README.md Addresses Out-of-Memory (OOM) errors by increasing the maximum old space size for the Node.js process running scip-typescript. The command 'node --max-old-space-size=16000 "$(which scip-typescript)" index REST_OF_COMMAND' allocates 16GB of memory. Adjust the size based on available RAM. ```shell node --max-old-space-size=16000 "$(which scip-typescript)" index REST_OF_COMMAND ``` -------------------------------- ### Print Type Information in TypeScript Source: https://github.com/sourcegraph/scip-typescript/blob/main/Development.md A simple TypeScript snippet to print the string representation of a type. This is useful for print debugging during development to understand type information. ```typescript checker.typeToString(type) ``` -------------------------------- ### Generate SCIP Symbols for TypeScript Constructs Source: https://context7.com/sourcegraph/scip-typescript/llms.txt Illustrates how to convert TypeScript Abstract Syntax Tree (AST) nodes into SCIP symbol identifiers. This includes handling different types of symbols like classes, methods, variables, and local symbols, ensuring correct descriptor encoding for each. ```typescript import * as ts from 'typescript' import { ScipSymbol } from './ScipSymbol' import { typeDescriptor, methodDescriptor, termDescriptor, packageDescriptor } from './Descriptor' // Example: Generate SCIP symbols for different TypeScript constructs // Class declaration const classNode: ts.ClassDeclaration = /* parsed from: class MyClass {} */ const classSymbol = ScipSymbol.global( packageSymbol, typeDescriptor('MyClass') ) // Result: "scip-typescript npm @sourcegraph/scip-typescript 0.4.0 src/`file.ts`/MyClass#" // Method declaration const methodNode: ts.MethodDeclaration = /* parsed from: myMethod() {} */ const methodSymbol = ScipSymbol.global( classSymbol, methodDescriptor('myMethod') ) // Result: "scip-typescript npm @sourcegraph/scip-typescript 0.4.0 src/`file.ts`/MyClass#myMethod()." // Variable declaration const varNode: ts.VariableDeclaration = /* parsed from: const myVar = 42 */ const varSymbol = ScipSymbol.global( packageSymbol, termDescriptor('myVar') ) // Result: "scip-typescript npm @sourcegraph/scip-typescript 0.4.0 src/`file.ts`/myVar." // Local symbol (within function scope) const localSymbol = ScipSymbol.local(5) // Result: "local 5" ``` -------------------------------- ### Address Out of Memory Errors (Disable Global Caches) Source: https://github.com/sourcegraph/scip-typescript/blob/main/README.md Mitigates Out-of-Memory (OOM) errors during indexing by disabling the global cache with the '--no-global-caches' flag. This reduces memory footprint at the cost of slower indexing. This is a workaround for large codebases. ```shell scip-typescript index --no-global-caches REST_OF_THE_COMMAND ``` -------------------------------- ### Generate SCIP Deprecation Diagnostics from JSDoc in TypeScript Source: https://context7.com/sourcegraph/scip-typescript/llms.txt Automatically detects `@deprecated` JSDoc tags in TypeScript code and generates SCIP diagnostic information. This enables code editors to display deprecation warnings, such as strikethrough text and hover messages. Requires the `scip` library. ```typescript // Example TypeScript code with deprecation: /** * @deprecated Use newFunction() instead. This will be removed in v2.0 */ function oldFunction() { return 42 } const result = oldFunction() // Reference to deprecated symbol // Generated SCIP diagnostic for the reference: const diagnostic = new scip.scip.Diagnostic({ severity: scip.scip.Severity.Information, code: 'DEPRECATED', message: 'Use newFunction() instead. This will be removed in v2.0', tags: [scip.scip.DiagnosticTag.Deprecated] }) // Result: Code editors display strikethrough text and deprecation warning // when hovering over or using oldFunction() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.