microsoft/typescript-go · error · Error
Language server is not running.
Error message
Language server is not running.
What it means
Thrown by SessionManager.initializeAPIConnection(pipe?) when this.currentSession is undefined. A Session only exists while the TS7 language server is running (or starting); stop() sets currentSession to undefined. The method forwards to the session's client to create an API session over a named pipe, so it hard-fails when the server is down.
Source
Thrown at _extension/src/session.ts:69
async restart(context: vscode.ExtensionContext): Promise<void> {
if (this.currentSession) {
this.outputChannel.appendLine("Restarting TypeScript language server...");
await this.currentSession.stop();
}
this.currentSession = new Session(context, this.outputChannel, this.initializedEventEmitter, this.telemetryReporter, () => this.stop(), () => this.restart(context));
return this.currentSession.start(context);
}
async stop(): Promise<void> {
if (this.currentSession) {
await this.currentSession.stop();
this.currentSession = undefined;
}
}
async initializeAPIConnection(pipe?: string): Promise<string> {
if (!this.currentSession) {
throw new Error(vscode.l10n.t("Language server is not running."));
}
const result = await this.currentSession.client.initializeAPISession(pipe);
return result.pipe;
}
async dispose(): Promise<void> {
await this.currentSession?.dispose();
await Promise.all(this.disposables.map(d => d.dispose()));
}
}
/**
* Session's lifetime is equal to that of its LanguageClient. The LanguageClient
* can be restarted within the same Session only if the underlying exe path/version
* has not changed. Otherwise, a new Session must be created. Since Session only
* exists while the LSP server is running (or actively starting/restarting/stopping),
* it also owns the commands and UI elements that should only be active while the
* server is running.
View on GitHub (pinned to 1bcfa18d79)
Solutions
- Start or restart the server first (typescript.native-preview.restart), await it, then call initializeAPIConnection
- Re-enable TypeScript 7 (js/ts.experimental.useTsgo = true) if it was disabled
- Check the TypeScript output channel for why the session is not running and fix that
- Catch the error and surface 'Language server is not running' as the extension's .ui variant does
Example fix
// before
const pipe = await vscode.commands.executeCommand('typescript.native-preview.initializeAPIConnection');
// after - ensure a live session first, restart is idempotent
await vscode.commands.executeCommand('typescript.native-preview.restart');
const pipe = await vscode.commands.executeCommand('typescript.native-preview.initializeAPIConnection'); Defensive patterns
Strategy: validation
Validate before calling
// Ensure a live session before asking for an API pipe; restart is idempotent
await vscode.commands.executeCommand('typescript.native-preview.restart');
const pipe: string = await vscode.commands.executeCommand('typescript.native-preview.initializeAPIConnection'); Try / catch
try {
pipe = await sessionManager.initializeAPIConnection();
} catch (e) {
if (e instanceof Error && e.message.includes('not running')) {
await sessionManager.restart(context); // bring the server up, then retry once
pipe = await sessionManager.initializeAPIConnection();
} else throw e;
} Prevention
- Drive API-pipe setup from the same code path that starts the session, not independently
- Re-enable TS7 (js/ts.experimental.useTsgo) before requesting API connections
- Watch the serverRunning context to sequence connection setup after startup
When it happens
Trigger: Executing typescript.native-preview.initializeAPIConnection before the first Session.start() finished, after 'Disable TypeScript 7' (which calls stopSession and clears currentSession), after a session stop, or during the gap while restart() is replacing the session.
Common situations: Tooling that connects to the tsgo API pipe (API.fromLSPConnection) racing extension activation; initializing an API connection in a workspace where TS7 was disabled; retrying after the server crashed.
Related errors
- failed to create API transport: %w
- Language client is not initialized
- Could not find a TypeScript executable in the extension pack
- Cannot run a temporary file update on an inactive snapshot
- Snapshot is disposed
AI-assisted analysis of microsoft/typescript-go@1bcfa18d79 (2026-08-16).
Data as JSON: /api/errors/44a1f89c8502e017.
Report an issue: GitHub.