Language server architecture

From forcedotcom/apex-language-support · View interactive version

Language server architecture is an AI agent skill from the GitHub repository forcedotcom/apex-language-support. Apex Language Server data architecture — type sources, worker topology, and data ownership. Use when working on type resolution, worker communication, resource loading, hover, definition, diagnostics, or any code in apex-ls/src/server/ or apex-parser-ast/src/symbols/.

How to use this skill

Skill file

Language Server Architecture

Hard Rule: No Raw-Text Semantic Fallbacks

Language features must never scan raw Apex source with regular expressions or

other text heuristics to infer symbols, declarations, types, references,

scopes, members, completion candidates, definitions, or dependency and

missing-artifact names. Semantic results must come from the Apex lexer/parser,

grammar-derived tree walkers, symbol tables, resolved references/xref data, or

a prior stable semantic snapshot.

Raw text may be passed to the parser and used for document transport or

position/range mechanics only. When semantic state is incomplete or stale,

wait, retry, or return an incomplete result; do not invent semantic state from

source text.

Three Sources of Apex Types

The language server works with three distinct sources of Apex type artifacts:

1. Workspace (customer code)

2. Faux SObject classes

3. Standard Apex Library (stdlib)

Worker Topology

Coordinator (main thread)
├── Data owner worker      — owns symbol tables for workspace + faux SObject files
├── Request-pool workers (2+) — handle dispatched LSP requests
└── Resource loader worker — owns standard Apex library (read-only)

Data owner worker

Request-pool workers

When a member is selected in a multi-node chain, preserve the matching

enclosing chain as well as the narrowest leaf reference so the chain head's

owning table can be fetched before missing-artifact resolution. Do not infer

the receiver from raw source text.

Resource loader worker

GlobalTypeRegistry

Defined in apex-parser-ast/src/services/GlobalTypeRegistryService.ts.

GlobalTypeRegistry is an in-process, mutable type index — NOT just a stdlib cache. It tracks types from ALL three sources as they are compiled and registered:

It is a module-level singleton (globalRegistryInstance). Each Node.js process gets its own instance:

When modifying resolution code in apex-parser-ast/src/symbols/ops/:

Separation of Concerns (Data Ownership Boundaries)

Keep data-handling logic siloed within the component whose responsibility it is. Each layer of the topology has one job:

Rule of thumb: if you're adding data transformation logic to the coordinator, it's in the wrong place — push it down to the owning worker. A component should only manipulate data it owns.

LSP Request Routing (DISPATCH_ROUTING)

Defined in apex-ls/src/server/WorkerCoordinator.ts.

| Request | Target | Notes |

|---------|--------|-------|

| documentOpen/Change/Save/Close | dataOwner | Document lifecycle |

| hover, completion, definition, diagnostics | requestPool | Cursor requests may load only parser-owned target dependencies; enrichment writes back when applicable |

| code action, code lens, document symbol, implementation, references, rename, signature help, semantic tokens | requestPool | Request-specific preparation and processing |

Worker Profiling & Debugging

Workers inherit profiling, debug, and heap-size flags from the main process via WorkerExecArgvBuilder. Key behaviors:

Worker Log Reachability

Effect logs (Effect.logInfo/logDebug/etc.) run under the worker's replaced workerLogger layer (worker.platform.ts, worker.platform.web.ts) post a WorkerLogMessage over the assistance port; the coordinator forwards them to the output channel. Reachability of plain getLogger() calls or Effects run under an ad-hoc Effect.runPromise (default logger) is unverified.

Key Paths

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.