lsp
Skill9 starsChanged 5 days agoMITView on GitHub
Language server patterns: servers owned per view (ipc/lsp.ts, lsp/registry.ts, lsp/manager.ts, lsp/server.ts), document mirror and versions, request deadlines and cancellation, normalization of untrusted server output, WorkspaceEdit application and the renderer LSP editor extensions. Use when creating or reviewing anything in src/main/lsp, ipc/lsp.ts, lspActions.ts, lspNavigationActions.ts, workspaceEditActions.ts or components/editor/lsp*.ts.
4 other projects use a version of this.
Adopted by
Most recently taken up by
- Fahrnetic/engineering-agent-skill-workflowtheir own version, first seen Oct 15, 2026
- wjgoarxiv/litopencodetheir own version, first seen Oct 13, 2026
- LuisaGroup/LuisaComputetheir own version, first seen Oct 8, 2026
- atopile/atopiletheir own version, first seen Oct 8, 2026
Other versions4 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 4
- atopile/atopile★ 4ksame name
- LuisaGroup/LuisaCompute★ 1.1ksame name
- wjgoarxiv/litopencode★ 3same name
- Fahrnetic/engineering-agent-skill-workflow★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository17 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- app-testingSkill
- claude-panelSkill
- commands-settingsSkill
- containersSkill
- debuggerSkill
- files-git-searchSkill
- i18nSkill
- main-ipcSkill
- main-processesSkill
- packaging-releaseSkill
- renderer-componentsSkill
- renderer-editorSkill
- renderer-storeSkill
- renderer-stylesSkill
- renderer-terminalSkill
- workspacesSkill
The file
We split this skill into the rules it gives an agent
2 rules. 0 are common, 0 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 84
Only the last completion list per window is cached (resultId → raw items for completionItem/resolve).
- Very specific: line 152
Every edit from the server goes through ONE applier (applyWorkspaceEdit in workspaceEditActions.ts): plan everything, refuse stale …
“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Language servers (src/main/lsp, editor/lsp*.ts)
One LspManager per view webContents; lsp/server.ts (process + JSON-RPC + backoff) is stable:
change it only with a concrete reason.
Modules
ipc/lsp.ts is wiring only: channels, argument validation and delegation. The manager of a view lives in
lsp/registry.ts (createViewRegistry; lspManagerOf(wc), ensureLspManager(wc), syncLspActivity(),
killAllLsp() for will-quit): import it from there, never from ipc/lsp.ts. lsp/manager.ts keeps only the server
lifecycle and the file → server routing; the rest has its own module:
| Module | Role |
lsp/documentMirror.ts | DocumentMirror: open docs keyed by pathKey, versions, applyChanges, editContext(root) and canon(root) (the renderer's path spelling) |
lsp/applyEditBroker.ts | ApplyEditBroker: the server's workspace/applyEdit round trip (seq, 10 s timeout, resolve, dropAll) |
lsp/requests.ts | requests table of per-document requests (method, capability, params, normalize, empty, optional exclusive key, shortcut, recover), REQUEST_TIMEOUTS_MS, RequestKind |
lsp/exclusive.ts | ExclusiveRequests.withExclusive(key, fn): a new request of the same key cancels the previous one (read token.isCancellationRequested inside fn: disposing the source also cancels the token) |
lsp/logBuffer.ts | LogBuffer: the "Output" panel lines (2000 cap) |
util/batcher.ts | createBatcher(ms, deliver): groups items and delivers them as one array (push, flush, dispose) |
lsp/codeLens.ts | normalizeCodeLens(es)/normalizeLensCommand (show-locations commands become locations) and CodeLensCache (last list per document, by pathKey) |
lsp/hierarchy.ts | call/type hierarchy normalizers (normalizeHierarchyItem(s), normalizeHierarchyEdges), HIERARCHY_METHODS and HierarchyStore (raw items by id, capped) |
A new per-document request = one entry in requests + a one-line method in LspManager (this.run(requests.x, path, …))
- one
request(channel, parsers, call, missing)line inipc/lsp.ts(validation runs before the manager lookup;missingis the answer when nothing is open and reusesrequests.x.empty). Requests that do not fit the table (workspaceSymbolsover many servers,executeCommand,resolveCompletion,resolveCodeLens,hierarchyRelated) stay in the manager. "Go to" requests that answer locations (implementation,typeDefinition,declaration) are onelocationRequest(kind, method, label, cap)line each; a new one advertises the client capability withlinkSupportinclientCapabilities.
Lifecycle
- LSP servers are owned per window (
lsp/registry.ts, oneLspManagerperwebContents): started lazily on the firstlsp.openof a file they serve, killed on folder change, reload, close andwill-quit(global registry, also covers servers still in async shutdown). - Servers spawn through
spawnGroup, sokillAllSpawnedGroupsalready covers them atwill-quit. Theliveset inlsp/server.tsholds RUNS, removed only when the process exits: a server that is slow to die afterstopRunstays there, somarkAllLanguageServersQuittingstill marks itstopping. Atwill-quitLSP only marks (quitNow) and never kills:killAllSpawnedGroupsdoes, in one batchedtaskkillon Windows.stopRunmarks the run notreadyfirst, so requests during a restart answer empty at once. - Events main → renderer are named apart from the invoke channels:
lsp:statusChanged(whole status list) andlsp:logAppended(an ARRAY ofLspLogEntry, batched per 100 ms by the manager'slogBatch;lsp:status/lsp:logare only the invoke channels).LogBuffer(history) is updated at once; only the push to the renderer is batched.shutdown()flushes the batch before and after stopping the servers,dispose()/killAll()drop it and clear the timer.log()flushes the batch before returning the history, so the event reaches the renderer before the invoke reply andmergeLogcan drop the overlap; never remove that flush. Server stderr is split withcreateLineSplitter; new log sources go throughpushLog, neveremitLogdirectly. - Text sent to the server or back to the model (
applyEditfailure reasons…) is English, not translated. - POSIX servers run
detachedand are killed by process group (kill(-pid)) so tsserver children die too; never kill by bare pid after exit (pid reuse).
Documents
- The renderer opens every loaded file tab (main keeps docs without a server too, so enabling one later reaches open
tabs) and reports every document mutation once (
components/editor/lspSync.ts, versions per tab;changesToLspemits changes in descending order).
Servers
- The built-in TS server runs
typescript-language-serverwithprocess.execPath+ELECTRON_RUN_AS_NODE=1and always uses the bundledtsserver-bundled; a workspacenode_modules/typescriptis code from the repo and only runs with the user-onlylsp.servers.typescript.useWorkspaceTypeScript. - The editor uses
baseSetup(editor/setup.ts, a copy ofbasicSetupwithoutlintKeymap, whose Mod-Shift-M would swallow the Problems accelerator on Win/Linux): new CodeMirror extensions go there. - Files rewritten on disk reach servers as
workspace/didChangeWatchedFilesonly if the server registered watchers dynamically (lsp/watchers.ts+lsp/glob.ts), fed by the window watcher's 150 ms batch (onWorkspaceFiles);changeof a mirrored open doc is skipped, andnode_modules/.gitstay ignored by that watcher.
Requests
- Requests (
ipc/lsp.ts→LspManager.completion/hover/…→lsp/requests.ts) route path → mirrored doc → its server and answernull/[]when there is no ready server or capability (ServerCapsfrom theinitializeresult). - Server output is normalized by pure modules in
lsp/(untrusted): aWorkspaceEditwith create/rename/delete or a file outside the window folder throws (translated message) instead of being half-applied. - Requests have deadlines (5 s; 15 s for references/rename/workspace symbols) and reject on timeout; a new
completion/hover/signature cancels the previous one (it resolves
null). - Deadlines use
util/deadline.ts(withDeadline→TIMEOUT); server lifecycle operations (restart/stop) run on autil/serialQueue.tsSerialQueue; server stderr is split withutil/lineSplitter.ts(8 KiB cap). Never inlinesetTimeout+Promise.race, achain = chain.then(…)or asplit('\n')buffer. - Only the last completion list per window is cached (
resultId→ raw items forcompletionItem/resolve). - Results the renderer refers to later keep their raw server items in main, owned by
{ entry, runId }(a restart invalidates them;dropResultson detach/sleep,dropRequestson shutdown): the last code lens list per document (codeLens/resolvemerges the answer into the raw item) and the hierarchy items by id (eachhierarchyRelatedstores the children it returns, so recursion never reuses an id). The renderer only sees ids. - Code lens commands of the "show locations" family (
editor.action.showReferences,peekLocations,goToLocations,rust-analyzer.showReferences, args[uri, position, Location[]]) are normalized intolocationsand shown by the renderer (peek); servers never accept them inworkspace/executeCommand. Other commands go throughexecuteCommand(still checked againstexecuteCommandProvider.commands). - Server → client refresh requests (
workspace/codeLens/refresh) are a table inserver.ts(REFRESH_METHODS) →host.onRefresh(kind)→lsp:refreshRequested→REFRESH[kind]inlspActions.ts. A new refresh kind = one entry in each table plusLspRefreshKind. ServerOptions.settingsis sent asworkspace/didChangeConfigurationright afterinitialized(workspaceSettings(def)inlaunch.ts: the bundled TS server only offers references/implementations code lenses with them on).- Code actions without edit/command are resolved inside
codeActions(the contract has no lazy resolve). - Inlay hints (
lsp/inlayHints.ts), document highlights (lsp/documentHighlights.ts) and semantic tokens (lsp/semanticTokens.ts) are table entries too. Semantic tokens are decoded in main (relative → absolute, legend names checked incapabilities.tsbecause they become CSS classes, capped at 200k tokens; documents over 3 MB never ask). The last result with aresultIdlives on theManagedDoc(semanticTokens, tagged with server id andrunId) and is the base offull/delta; a delta refused by the server falls back tofullinLspManager.semanticTokens, and any malformed delta drops the cache instead of half-applying it. workspace/inlayHint/refreshandworkspace/semanticTokens/refreshare answered inserver.tsand pushed aslsp:refresh {kind, serverId}; new client capabilities go inclientCapabilities()next to their request.documentSymbolsreturns the TREE (LspDocumentSymbol[], children in document order; a flatSymbolInformation[]is nested by range containment inlsp/symbols.ts). The@picker flattens it in the renderer (fetchDocumentSymbols→flattenSymbols); breadcrumbs, Outline and their Lezer fallback use the tree (renderer-editor, "Symbols, breadcrumbs, outline and sticky scroll").
Edits from the server
- The server's
workspace/applyEditis a round trip: main emitslsp:applyEdit {id}, the renderer MUST answerlsp.applyEditResult(10 s timeout =applied:falsepluslsp:applyEditCancelled {id}; shutdown also answersfalse). - Paths from the server are re-spelled like the renderer's (
canonicalPath: open doc path, else the window folder's spelling), aWorkspaceEditis strict (any malformed part throws) and each file carries the mirrorversion.
Renderer
- LSP editor extensions (
editor/lsp*.ts) never import the store; they reach it throughlspHost(injected bylspActions.ts) and know their tab by thelspTabIdfacet; completion is added viaEditorState.languageData(neveroverride, which would drop language completions). - Data the editor asks for on its own (inlay hints, document highlights, semantic tokens) uses
lspFetch(editor/lspFetch.ts): a ViewPlugin that debounces the trigger, skips the request when the feature is off (lspHost().featureEnabled, fromeditor.inlayHints.enabled/editor.semanticHighlighting.enabled) or the server is not ready, and drops a reply whose document orlspDocVersionchanged. The result lives in aStateField(mapped through edits, survives hide/show).emitLspRefresh(lspHost.ts) re-asks: fired bylsp:refresh, by the set of ready servers changing and by the settings; requests errors are silent (opportunistic, like hover). - Semantic marks (
cm-sem-<type>+cm-sem-mod-<modifier>, colors instyles/editor.cssover--syn-*) must stay inlspExtensions, ahead of the theme: higher-precedence decorations are the INNER DOM nodes, so their color beats the Lezer highlight. F7/Shift+F7 (editor.next/previousSymbolHighlight) walk the highlights, or the whole-word occurrences when there are none. - Snippet items (
insertTextFormat: 'snippet') expand throughexpandSnippet(renderer-editorskill: variables, choices), never through CodeMirror'ssnippet()directly. - Navigation that answers locations goes through ONE path (
queryLocations(kind)inlspNavigationActions.ts):goToLocations(kind)(one result jumps, many go to the References view) andpeekLocations(kind)(inline peek). A new "go to" kind = an entry inFETCHand its messages (lspNavigation.locations). - The peek (
editor/lspPeek.ts,openPeek(view, { pos, title, locations })) is a block widget below the line, provided by aStateField; its selection and loaded files live in a model object outside the state. The preview is static highlighted text (highlightRangefromlib/codeHighlight.tswith the target file's language), never anotherEditorView. The widget'signoreEventistrue: its keys (Esc, Enter, ↑/↓) and clicks are its own. - Code lenses (
editor/lspCodeLens.ts) live incodeLensSlot, toggled with the lightbulb byrefreshLspGutters(server ready andeditor.codeLens). Lists are requested 600 ms after edits and dropped if the doc changed while waiting; unresolved lenses are resolved only in the viewport, one attempt each. The mirror copy (nohistoryField) never requests lenses: both copies would fight over main's last list per document. - The Hierarchy view (
hierarchyActions.ts,components/HierarchyPanel.tsx,lib/hierarchyTree.ts) loads children lazily per node and drops answers of an older hierarchy or direction. - Every edit from the server goes through ONE applier (
applyWorkspaceEditinworkspaceEditActions.ts): plan everything, refuse stale versions/snapshots, write unloaded files to disk first (original EOL), then apply loaded tabs all-or-nothing (dirty, one undo per file).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

