Language Servers and Code Indexes
The other design notes assume that symbols, references, types and call relations are available. This note is about where they actually come from, what each source can and cannot answer, and what it costs to run. It is the practical side of code representation, and it decides how the ablation ladder in the thesis and evaluation plan gets built (conditions B1 to B3, and the structural tools in A1).
There are three families of sources:
- Parsers read one file at a time and give syntax: tree-sitter, ctags.
- Live language servers answer questions about a running workspace: the Language Server Protocol (LSP).
- Precomputed indexes and analysis databases are built once per snapshot and queried offline: LSIF, SCIP, stack graphs, Kythe, Glean for navigation; CodeQL, Joern for data flow.
Levels of structural fidelity
History and configuration (implicit knowledge) are a separate axis: they need Git and config parsing, not a deeper analysis of code.
Each level up is more precise and more expensive, and less likely to work out of the box on an arbitrary repository. Hypothesis H7 asks where the gain stops being worth the cost.
Level 1: tree-sitter
Tree-sitter is an incremental parsing library with grammars for most languages. It produces a concrete syntax tree for one file, tolerates syntax errors (useful for code being edited), and re-parses quickly after small edits. It needs no build and no dependencies.
Two features matter here:
- Queries. S-expression patterns match tree nodes, for example “every function definition with its name and parameters”. This is how AST chunks, envelopes (the class around a method) and signatures are cut out.
- Tags. Many grammars ship a
tags.scmquery that captures definitions and references by name. GitHub’s search-based code navigation works this way, and so does Aider’s repository map: it extracts definitions and references with tree-sitter tags, builds a graph of files that reference each other’s names, ranks files with PageRank biased towards the files in the conversation, and fits the top entries into a token budget.
The limit is resolution. Tree-sitter knows that a call to connect exists, not which connect it is. Imports can be read syntactically, but following them to the right definition across packages, overloads and inheritance needs level 2. Universal Ctags is an older alternative with the same name-based character.
Level 2: the Language Server Protocol
The Language Server Protocol, introduced by Microsoft in 2016, is a JSON-RPC protocol between an editor and a language-specific server. The server holds a semantic model of the workspace and answers position-based requests. Because every major editor uses it, nearly every language has a mature server.
Requests useful to an assistant
Call and type hierarchy arrived in protocol versions 3.16 and 3.17, so older servers may lack them. Support varies by server: check each capability in the server’s initialize response rather than assuming it.
Running servers headless
Language servers are built for one person editing one workspace, so using them as a back end takes some care.
- Lifecycle.
initializewith the workspace root and client capabilities,initialized, thentextDocument/didOpenfor files before querying them (some servers answer only for open files), andshutdownandexitat the end. - Readiness. There is no standard “indexing finished” signal. Servers report work through
$/progressnotifications; a back end should wait for them, and should report “not ready” rather than return an empty result that looks like “no references”. - Positions. Lines and characters are zero-based, and characters count UTF-16 code units by default; protocol 3.17 lets client and server negotiate another encoding. Off-by-one and encoding mismatches are a common source of wrong citations.
- Environment. Results are only as good as the project setup: the Python interpreter and installed packages for Pyright,
node_modulesfor the TypeScript server, acompile_commands.jsonfor clangd, an imported Maven or Gradle project for the Java server. A server on a misconfigured project returns partial results without failing. - Cost. Startup and initial indexing take from seconds to minutes and can use gigabytes of memory on a large repository. Keep servers warm and reuse them across queries.
- Robustness. Servers crash and hang; supervise them, time out requests, and restart.
Libraries do most of this work. Microsoft’s multilspy, written for the monitor-guided decoding research (a language server constrains what the model generates), starts servers for several languages and exposes the requests as Python calls. Serena exposes symbol search, references, declarations, implementations and symbol-level editing over the Model Context Protocol (MCP), with language servers as its default back end. Coding agents themselves increasingly ship a language-server tool: Claude Code has a read-only one, active once a code-intelligence plugin and the language server are installed.
What language servers do not give
- A snapshot. A server answers about the files on disk now. It has no notion of commit, so reproducible evaluation at a pinned commit means setting up the workspace at that commit (see the evaluation section below).
- Data flow. References say where a symbol is used, not how values move through it.
- Links across languages and services. A server for the client code does not know which server handler an HTTP route or gRPC method reaches.
- History. Nothing about who changed what, or what changes together.
- Completeness in dynamic code. Python and JavaScript references miss calls through
getattr, decorators that rewrite functions, dependency injection and string-built names.
Level 2, offline: precomputed indexes
An index is built once per snapshot, usually in CI, and queried without a running server. This trades freshness for reproducibility, speed at query time and scale.
- LSIF (Language Server Index Format, Microsoft, 2019) is a dump of the answers a language server would give, as a graph of vertices and edges in JSON lines, so navigation works without running the server.
- SCIP (Sourcegraph’s successor to LSIF in its own products) is Protobuf-based and organized by document. Its main contribution is symbol identity: each symbol has a readable, globally unique string built from the package manager, package name and version, and a descriptor path (namespace, type, method). The same string identifies the symbol in every file and, through package versions, across repositories. That is the answer to the open question of how a node keeps its identity in the software knowledge graph. Indexers exist for TypeScript, Java and other JVM languages, Python (built on Pyright), Go, C and C++, and rust-analyzer can emit SCIP.
- Stack graphs (GitHub) resolve names without a build. Each file’s graph is built independently from its tree-sitter tree, using rules written in a small DSL, and the graphs are joined at query time to resolve a reference to its definition. Because files are processed independently, updates are incremental. The approach comes from scope graphs, a theory of name resolution from programming-language research. It was the main way to get precise navigation without a build environment, but GitHub archived the stack-graphs repository in September 2025 and no longer supports it, so it is now a design to learn from rather than a dependency to adopt.
- Kythe (Google) defines a language-neutral graph of nodes and edges for cross-references. Extractors capture each compilation from the build and indexers emit facts, so it is tied to build integration; it is what Google’s code search uses.
- Glean (Meta, open-sourced in 2021) stores facts about code in a database with a declarative query language (Angle), supports incremental updates, and derives new facts from stored ones. It powers code navigation and other tooling at Meta’s scale.
The cost moves to CI: indexing time and storage per commit. Answers are as fresh as the last indexed commit, so uncommitted edits still need a live server or a re-index of the changed files.
Level 3: data flow and code property graphs
- CodeQL (GitHub) extracts code into a relational database, often by watching the build for compiled languages, and queries it in QL, a declarative, object-oriented logic language. Its standard libraries include data-flow and taint tracking, so “where does this request parameter end up?” is a library query. It is the most mature option for the
DataflowFromSourceprimitive in hybrid architecture. Check licensing before using it on closed-source code. - Joern builds a code property graph (AST, control flow and program dependence in one graph) from frontends for several languages and queries it with a Scala-based language. It is the reference implementation of the CPG idea in code representation.
- Language-specific tools give call graphs and points-to information: for example PyCG for Python call graphs, and Soot, WALA or Doop for Java. Static call graphs for dynamic languages are approximations: some report calls that never happen, others miss calls that do. Which way a tool errs matters for impact questions, where a missed caller is worse than an extra one.
Level 3 tools are heavy: building a database for a large repository can take as long as a full build, and the queries are expressive but slow compared with level 2 lookups. They fit precomputed, high-value questions (security, data movement) better than every query.
Choosing a source
For the evaluation plan
The pilot in the thesis and evaluation plan pins each item at the parent of a fix commit, and SWE-bench items are spread over many commits of many repositories. That has practical consequences:
- B1 (syntax) is cheap: tree-sitter runs on any checkout.
- B2 (symbols) needs a working environment per item. SWE-bench provides a container image per task with the environment installed, which is the easiest way to get a language server that actually resolves. Starting a server per item costs time; budget for it, and record coverage (the share of files where references resolved) so that a weak B2 result can be told apart from a broken setup.
- A SCIP index per pinned commit is the more reproducible option for B2 and makes repeated runs cheap, at the cost of an indexing step per commit.
- B3 (flow) is the expensive step. Run it on a subset first, and only if B2 shows a gain worth extending.
As tools for an agent
The structural primitives in hybrid architecture map onto these sources directly:
Design points that matter for agents:
- Compact results. Return symbol, kind,
path:line, signature and one line of context, not whole files. The agent can read the file if it needs more. - Paging and limits. References to a common symbol can number in the thousands; return a count and the first page.
- Honest failure. Distinguish “no references” from “server not ready” or “unresolved because the environment is broken”, so the agent can fall back to grep instead of concluding there are no callers.
- Stable identifiers. Return SCIP-style symbol IDs that the agent can pass back to other tools.
This is condition A1 in the evaluation plan; hypothesis H6 asks whether it beats grep and file reads on cost. Early evidence is mixed: one small study found that agents rarely call language-server tools when they are optional and gain mainly on finding references, where grep returns many false positives; another reports one to two points more on SWE-bench Verified with fewer turns (related work § Comparisons of structure, text and grep).
Open questions
- How should a client call in one service be linked to its handler in another: route strings, OpenAPI or proto definitions, message topics?
- How should generated code be treated: indexed, linked to its generator, or excluded?
- Can one language server cope with a large monorepo, or does the index need to be split by package?
- How should uncommitted edits be combined with an index built for the last commit?
References
- Language Server Protocol specification: https://microsoft.github.io/language-server-protocol/
- LSIF: https://microsoft.github.io/language-server-protocol/overviews/lsif/overview/
- SCIP: https://github.com/sourcegraph/scip
- Stack graphs: https://github.com/github/stack-graphs
- Kythe: https://kythe.io
- Glean: https://glean.software
- CodeQL: https://codeql.github.com
- Joern: https://joern.io
- Tree-sitter: https://tree-sitter.github.io/tree-sitter/
- Aider repository map: https://aider.chat/docs/repomap.html
- multilspy: https://github.com/microsoft/multilspy; Agrawal et al., Guiding Language Models of Code with Global Context using Monitors (NeurIPS 2023)
- Serena: https://github.com/oraios/serena
- Néron et al., A Theory of Name Resolution (ESOP 2015), the scope-graph work behind stack graphs
Library sources
Further reading:
- Winters et al. 2020, Software Engineering at Google: the chapters on code search and static analysis describe how cross-reference indexes and analyzers run at scale