Go to Definition
Jump to where a symbol is defined
The SCIP API provides precise code intelligence features like go-to-definition and find-references, powered by language-specific indexers.
SCIP (Source Code Intelligence Protocol) enables precise code navigation by building a semantic index of your code. Unlike text-based search, SCIP understands the structure of your code and can:
Go to Definition
Jump to where a symbol is defined
Find References
Find all usages of a symbol
Multi-language
Supports Go, TypeScript, Java, Rust, Python, PHP
Upload Indexes
Build indexes in CI and upload them
SCIP indexers must be installed on the machine running the API server (or you can build indexes externally and upload them).
go install github.com/sourcegraph/scip-go@latestMake sure $(go env GOPATH)/bin is in your PATH.
npm install -g @sourcegraph/scip-typescriptOr use npx (the indexer will use this automatically):
npx -y @sourcegraph/scip-typescript index# Using Coursiercs install scip-javaUses rust-analyzer. Install via your package manager or:
rustup component add rust-analyzerpip install scip-pythonPHP uses per-project installation via Composer:
composer require --dev davidrjenni/scip-phpGET /api/v1/scip/indexersReturns which indexers are available on the system.
curl "http://localhost:8080/api/v1/scip/indexers"{ "available": { "go": true, "typescript": true, "javascript": true, "java": false, "rust": false, "python": false, "php": false }, "supported": ["go", "typescript", "javascript", "java", "rust", "python", "php"], "instructions": { "go": "go install github.com/sourcegraph/scip-go@latest", "typescript": "npm install -g @sourcegraph/scip-typescript", "java": "cs install scip-java", "rust": "rustup component add rust-analyzer", "python": "pip install scip-python", "php": "composer require --dev davidrjenni/scip-php" }}Check if a repository has a SCIP index.
GET /api/v1/scip/repos/{id}/statuscurl "http://localhost:8080/api/v1/scip/repos/1/status"{ "has_index": true, "available_indexers": { "go": true, "typescript": true }, "stats": { "total_files": 156, "total_symbols": 2340, "total_occurrences": 15678, "indexed_at": "2024-01-15T10:30:00Z" }}Run SCIP indexing on a repository.
POST /api/v1/scip/repos/{id}/index| Parameter | Type | Required | Description |
|---|---|---|---|
language | string | No | Language to index (auto-detected if not specified) |
curl -X POST "http://localhost:8080/api/v1/scip/repos/1/index" \ -H "Content-Type: application/json" \ -d '{"language": "go"}'{ "success": true, "language": "go", "duration": "2.5s", "files": 156, "symbols": 2340, "occurrences": 15678, "output": "Indexing completed successfully"}{ "success": false, "language": "go", "error": "scip-go not found in PATH. Install with: go install github.com/sourcegraph/scip-go@latest", "output": ""}Upload a pre-built SCIP index file. This is useful for:
POST /api/v1/scip/repos/{id}/uploadContent-Type: application/octet-stream# Clone the repositorygit clone https://github.com/myorg/myrepocd myrepo
# Build the SCIP indexscip-go --output index.scip
# Upload to Code Search (replace {id} with your repo ID)curl -X POST "http://localhost:8080/api/v1/scip/repos/{id}/upload" \ --data-binary @index.scip# Clone the repositorygit clone https://github.com/myorg/myrepocd myrepo
# Install dependenciesnpm install
# Build the SCIP indexnpx @sourcegraph/scip-typescript index --output index.scip
# Upload to Code Searchcurl -X POST "http://localhost:8080/api/v1/scip/repos/{id}/upload" \ --data-binary @index.scip# .gitlab-ci.yml examplescip-index: stage: index image: golang:1.21 script: - go install github.com/sourcegraph/scip-go@latest - scip-go --output index.scip - | REPO_ID=$(curl -s "$CODE_SEARCH_URL/api/v1/repos/lookup?name=$CI_PROJECT_PATH" | jq -r '.id') curl -X POST "$CODE_SEARCH_URL/api/v1/scip/repos/$REPO_ID/upload" \ --data-binary @index.scip only: - main{ "success": true, "message": "SCIP index uploaded successfully", "stats": { "total_files": 156, "total_symbols": 2340, "total_occurrences": 15678 }}Find the definition of a symbol at a given position.
POST /api/v1/scip/repos/{id}/definition| Parameter | Type | Required | Description |
|---|---|---|---|
filePath | string | Yes | Path to the file in the repository |
line | integer | Yes | Line number (1-indexed) |
column | integer | Yes | Column number (0-indexed) |
curl -X POST "http://localhost:8080/api/v1/scip/repos/1/definition" \ -H "Content-Type: application/json" \ -d '{ "filePath": "internal/search/search.go", "line": 42, "column": 15 }'{ "found": true, "symbol": "scip-go gomod github.com/myorg/api v1.0.0 internal/search/Search#Query().", "definition": { "symbol": "scip-go gomod github.com/myorg/api v1.0.0 internal/search/Search#Query().", "filePath": "internal/search/search.go", "startLine": 15, "startCol": 0, "endLine": 15, "endCol": 5, "role": 1, "context": "func (s *Search) Query(ctx context.Context, q string) ([]Result, error) {" }, "info": { "symbol": "scip-go gomod github.com/myorg/api v1.0.0 internal/search/Search#Query().", "documentation": "Query executes a search query and returns results.", "kind": 6, "displayName": "Query" }, "external": false}| Field | Type | Description |
|---|---|---|
found | boolean | Whether a definition was found |
symbol | string | The SCIP symbol identifier |
definition | object | Location of the definition |
info | object | Symbol metadata (documentation, kind, etc.) |
external | boolean | True if definition is in an external package |
Find all references to a symbol at a given position.
POST /api/v1/scip/repos/{id}/references| Parameter | Type | Required | Description |
|---|---|---|---|
filePath | string | Yes | Path to the file in the repository |
line | integer | Yes | Line number (1-indexed) |
column | integer | Yes | Column number (0-indexed) |
limit | integer | No | Maximum references to return (default: 100) |
curl -X POST "http://localhost:8080/api/v1/scip/repos/1/references" \ -H "Content-Type: application/json" \ -d '{ "filePath": "internal/search/search.go", "line": 15, "column": 10, "limit": 50 }'{ "found": true, "symbol": "scip-go gomod github.com/myorg/api v1.0.0 internal/search/Search#Query().", "definition": { "filePath": "internal/search/search.go", "startLine": 15, "startCol": 0, "endLine": 15, "endCol": 5, "role": 1, "context": "func (s *Search) Query(ctx context.Context, q string) ([]Result, error) {" }, "references": [ { "filePath": "cmd/api/handlers/search.go", "startLine": 42, "startCol": 15, "endLine": 42, "endCol": 20, "role": 8, "context": " results, err := s.search.Query(ctx, req.Query)" }, { "filePath": "internal/search/search_test.go", "startLine": 28, "startCol": 18, "endLine": 28, "endCol": 23, "role": 8, "context": " results, err := search.Query(ctx, \"test\")" } ], "totalCount": 2}Search for symbols by name in a repository’s SCIP index.
POST /api/v1/scip/repos/{id}/symbols/search| Parameter | Type | Required | Description |
|---|---|---|---|
query | string | Yes | Symbol name pattern to search |
limit | integer | No | Maximum results (default: 100) |
curl -X POST "http://localhost:8080/api/v1/scip/repos/1/symbols/search" \ -H "Content-Type: application/json" \ -d '{"query": "Query", "limit": 10}'{ "results": [ { "symbol": "scip-go gomod github.com/myorg/api v1.0.0 internal/search/Search#Query().", "name": "Query", "kind": "function", "filePath": "internal/search/search.go", "line": 15 } ], "count": 1}List all files in a repository’s SCIP index.
GET /api/v1/scip/repos/{id}/files| Parameter | Type | Required | Description |
|---|---|---|---|
limit | integer | No | Maximum files (default: 100) |
curl "http://localhost:8080/api/v1/scip/repos/1/files?limit=10"{ "files": [ "cmd/api/main.go", "internal/search/search.go", "internal/search/search_test.go" ], "count": 3}Remove the SCIP index for a repository.
DELETE /api/v1/scip/repos/{id}/indexcurl -X DELETE "http://localhost:8080/api/v1/scip/repos/1/index"{ "success": true, "message": "SCIP index cleared"}The default Docker images don’t include SCIP indexers. You have two options:
Build SCIP indexes in your CI pipeline or locally, then upload them:
# Build locallyscip-go --output index.scip
# Upload to the servercurl -X POST "http://code-search:8080/api/v1/scip/repos/{id}/upload" \ --data-binary @index.scipCreate a custom Dockerfile that includes the indexers:
FROM code-search-api:latest
# Install Go and scip-goRUN apk add --no-cache goENV GOPATH=/goENV PATH=$GOPATH/bin:$PATHRUN go install github.com/sourcegraph/scip-go@latest