microsoft/TypeScript · error · Error

getClassifier is not available using the server interface.

Error message

getClassifier is not available using the server interface.

What it means

Thrown by the server-backed language service adapter (harnessLanguageService.ts:807) when a test invokes getClassifier() on a TestSession/SessionClientHost. The classifier is a compiler-internal API that the tsserver protocol does not expose, so the server adapter deliberately throws rather than pretend to support it.

Solutions

  1. Gate classifier tests to run only against the in-process adapter (skip when the adapter is the server/session variant).
  2. Move classifier assertions into a separate test that does not exercise the server code path.
  3. If you must assert server-side classification, use the EncodedSyntacticClassifications protocol command instead of getClassifier.

Example fix

// before — runs against every adapter, throws on server variant
test.each(adapters)("classifies", adapter => {
  const cls = adapter.getClassifier().getClassificationsForLine(...);
  assert.ok(cls);
});

// after — skip server variants for classifier-only tests
test.each(adapters.filter(a => !isServerAdapter(a)))("classifies", adapter => {
  const cls = adapter.getClassifier().getClassificationsForLine(...);
  assert.ok(cls);
});
Defensive patterns

Strategy: type-guard

Validate before calling

// Detect server-backed adapters and skip classifier tests for them.
function supportsClassifier(adapter: unknown): boolean {
  // Server-backed adapters throw on getClassifier; detect by capability rather than type.
  return typeof (adapter as any).getClassifier === 'function' && !isServerAdapter(adapter);
}

Type guard

function isServerAdapter(adapter: unknown): boolean {
  // SessionClientHost advertises getHost/getLanguageService but lacks a real classifier.
  return typeof (adapter as any)?.getHost === 'function' && !(adapter as any)._classifierAvailable;
}

Prevention

When it happens

Trigger: A language service test is parameterised to run both against the in-process LanguageService and against a server Session, and the test body calls `adapter.getClassifier()`. The in-process variant returns a real Classifier; the server variant throws this message.

Common situations: Writing a classifier/syntax-classification test and running it through the server harness; sharing one test function across both adapter kinds without gating classifier-only calls.

Related errors


AI-assisted analysis of microsoft/TypeScript@b465fdbfe1 (2026-08-12). Data as JSON: /api/errors/4e63ec7176b63cb9. Report an issue: GitHub.

Appendix: source

Thrown at src/harness/harnessLanguageService.ts:807

        if (options) {
            client.setCompilerOptionsForInferredProjects(ts.optionMapToObject(ts.serializeCompilerOptions(options)) as ts.server.protocol.CompilerOptions);
        }

        // Set the properties
        this.client = client;
        this.host = clientHost;
    }
    getLogger(): LoggerWithInMemoryLogs {
        return this.logger;
    }
    getHost(): SessionClientHost {
        return this.host;
    }
    getLanguageService(): ts.LanguageService {
        return this.client;
    }
    getClassifier(): ts.Classifier {
        throw new Error("getClassifier is not available using the server interface.");
    }
    getPreProcessedFileInfo(): ts.PreProcessedFileInfo {
        throw new Error("getPreProcessedFileInfo is not available using the server interface.");
    }
    assertTextConsistent(fileName: string): void {
        const serverText = this.server.getText(fileName);
        const clientText = this.host.readFile(fileName);
        ts.Debug.assert(
            serverText === clientText,
            [
                "Server and client text are inconsistent.",
                "",
                "\x1b[1mServer\x1b[0m\x1b[31m:",
                serverText,
                "",
                "\x1b[1mClient\x1b[0m\x1b[31m:",
                clientText,
                "",

View on GitHub (pinned to b465fdbfe1)