This page introduces tsserver as the long-running editor server process, describes its overall architecture, and explains how its major components relate to each other. For detailed coverage of the communication protocol, see tsserver Protocol. For project lifecycle management, see Project Management. For automatic type acquisition, see Automatic Type Acquisition. For the underlying language services that tsserver exposes, see Language Service.
tsserver is a long-running Node.js process that exposes the TypeScript Language Service to editors and IDEs over a line-delimited JSON protocol. Instead of re-launching the compiler on every keystroke, the editor spawns a single tsserver process at startup, keeps it alive for the duration of the editing session, and exchanges request/response/event messages through its standard input and output streams.
All rich editing features that editors provide—completions, diagnostics, go-to-definition, rename, code fixes—are ultimately served by tsserver calling into the language service on behalf of the client.
tsserver component hierarchy
Sources: src/server/session.ts1-110 src/server/editorServices.ts1-200 src/server/project.ts1-70
tsserver is launched by editors as a child process. The canonical entry point is src/tsserver/server.ts (or src/tsserver/nodeServer.ts for Node-specific environments). It constructs a Session and starts the communication loop.
The initialization sequence is:
ServerHost implementation (wrapping sys) is provided to Session.Session constructs a ProjectService src/server/editorServices.ts190 which in turn creates a DocumentRegistry and sets up file watchers.open request for a file, ProjectService locates or creates the appropriate Project (see Project Management).LanguageService backed by a fresh or reused Program.Initialization flow
Sources: src/server/editorServices.ts197-210 src/server/project.ts25-30 src/server/session.ts1-50
All messages are JSON objects, one per line, transmitted over stdio. There are three message shapes defined in src/server/protocol.ts:
| Shape | Key field | Direction | Description |
|---|---|---|---|
Request | "type": "request" | Editor → tsserver | A command with a sequence number and optional arguments |
Response | "type": "response" | tsserver → Editor | Result for a specific request sequence number |
Event | "type": "event" | tsserver → Editor | Unsolicited notification (e.g. diagnostics ready) |
The seq field links responses to requests tests/baselines/reference/api/typescript.d.ts134 Responses include a success boolean and a body containing the result.
The full set of commands is defined in the CommandTypes enum in src/server/protocol.ts tests/baselines/reference/api/typescript.d.ts49-126
Session (src/server/session.ts)Session owns the read loop and the command dispatch table. It:
ServerHost.protocol.Request.command string.protocol.Response.ThrottledOperations src/server/editorServices.ts192The handler methods are named after their commands (e.g. getCompletions, getDefinition) and delegate to ProjectService to find the active project and then call through to the project's LanguageService.
ProjectService (src/server/editorServices.ts)ProjectService is the central coordinator. It manages:
ScriptInfo objects src/server/editorServices.ts186).Project instances.tsconfig.json files and source files.Key constants defined here:
maxProgramSizeForNonTsFiles = 20 MB — threshold above which JS files are excluded from a program src/server/editorServices.ts198maxFileSize = 4 MB — per-file size limit src/server/editorServices.ts200Events emitted by ProjectService (as string constants):
| Constant | Value | Meaning |
|---|---|---|
ProjectsUpdatedInBackgroundEvent | "projectsUpdatedInBackground" | Background update finished src/server/editorServices.ts202 |
ProjectLoadingStartEvent | "projectLoadingStart" | Project starting to load src/server/editorServices.ts203 |
ProjectLoadingFinishEvent | "projectLoadingFinish" | Project finished loading src/server/editorServices.ts204 |
ConfigFileDiagEvent | "configFileDiag" | tsconfig.json diagnostics available src/server/editorServices.ts206 |
ScriptInfo (src/server/scriptInfo.ts)Each open or referenced file is represented as a ScriptInfo. It stores:
NormalizedPath).ScriptKind (TS, JS, TSX, etc.).ScriptInfo acts as the shared, version-tracked document store that all projects access through the LanguageServiceHost interface.
Three concrete project types inherit from the abstract Project base src/server/editorServices.ts182:
| Type | Description |
|---|---|
ConfiguredProject | Backed by a tsconfig.json / jsconfig.json file src/server/editorServices.ts153 |
InferredProject | Created for files that have no tsconfig.json src/server/editorServices.ts162 |
ExternalProject | Client-defined project (used by non-VS Code integrations) src/server/editorServices.ts159 |
AutoImportProviderProject | Auxiliary project used to compute auto-import completions src/server/editorServices.ts149 |
Each project owns a LanguageService instance and a DocumentRegistry (shared across projects to avoid parsing the same file twice).
How a completions request travels through tsserver
Sources: src/server/session.ts1-220 src/server/editorServices.ts1-200 src/server/project.ts1-70
tsserver does not duplicate language service or compiler logic. The dependency chain is strictly layered:
src/compiler/ implements all parsing, type-checking, and emit logic.src/services/services.ts wraps the compiler in the LanguageService interface src/services/services.ts212 adding editor-oriented features.src/server/ wraps the language service in a protocol layer, adding project management and file watching.Sources: src/services/services.ts212 src/server/project.ts25-30
Unlike most requests, diagnostics are often delivered as events. The workflow is:
Geterr request tests/baselines/reference/api/typescript.d.ts71semanticDiag, syntacticDiag, and suggestionDiag events.This allows the editor to remain responsive while the type checker works in the background.
Sources: src/server/session.ts1-100 tests/baselines/reference/api/typescript.d.ts49-126
| Page | Topic |
|---|---|
| tsserver Protocol | Full JSON message format, key command reference, Session dispatch details |
| Project Management | ProjectService, ConfiguredProject, InferredProject, ExternalProject lifecycle |
| Automatic Type Acquisition | TypingsInstaller, jsTyping, @types discovery and npm integration |
Refresh this wiki