Preserve structured diagnostics, source attribution, phase outcomes and revision context through compiler, Studio, LSP, MCP and JavaFX. Add project service discovery and resilient VS Code reconnection. Correct all eight reproduced PBS production failures in expression context, sibling executable bindings and nominal owner identity. Consolidate specs, lessons, immutable baseline evidence and the maintained source-to-guest qualification runner. Validation: required Gradle gate recorded 724 tests, with 711 passed and 13 skipped. Full corpus passed 168 compilation observations and 108 guest runs (104 successes and four deliberate faults); supplemental controls passed 42 compilations and 16 guest runs. TypeScript compilation, two Node discovery tests and discussion validation passed.
3.4 KiB
Discover project services through session metadata
Owner: studio. Completed through AGD-0105, DEC-0087 and PLN-0165.
Original problem
The app correctly assigned a loopback LSP port to each open project, but VS Code still assumed 7775. Every refusal produced another attempt and error popup after two seconds. Manually copying a port worked only until the next Studio session.
Consolidated decision and implementation
An ephemeral service needs a discoverable identity as well as an address. Studio
now atomically publishes .studio/lsp.json when the project server starts. The
record contains schema version, canonical project root, process identity, session
identity and actual loopback endpoint. Publication failure rolls back server boot;
shutdown removes only metadata matching the owning session. This non-secret file
is separate from automation credentials and grants.
The extension defaults to discovery for one local project root. It rejects malformed, misbound and non-loopback metadata and ignores dead-process records. Discovery file and workspace/configuration changes trigger serialized reconnection. Missing metadata means waiting for Studio. Backoff progresses through 2, 4, 8, 16 and 30 seconds, resets on success, and is cancelled during shutdown. Status is visible without recurring connection-error dialogs. Explicit manual mode preserves other LSP hosting arrangements; automatic mode never guesses a fixed port.
For example, open zelda-1 in Studio and the same folder in VS Code. Reopening
Studio may change the port; VS Code reads the new discovery record automatically.
Older running binaries must be rebuilt and restarted before they can publish it.
Pitfalls
- A live process ID alone is not a project binding: validate the canonical root and keep the LSP server's initialize-time root validation authoritative.
- A new server session invalidates old SDK consumer identities. Reset those before reconnecting; retain old virtual-document text, and navigate again for fresh URIs. Short socket reconnects to the same session can retain consumer identity.
- languageclient 9 may invoke stop while failed initialization is still Starting. The adapter waits for start settlement before stopping, avoiding an unhandled rejection during a failed handshake.
- A successful socket test does not prove file watching and editor recovery. Use a real isolated Extension Development Host to exercise publication and replacement.
Validation and limits
97 application tests passed, including four new real ephemeral-server discovery lifecycle tests. Two Node tests cover malformed/missing/stale/misbound metadata, canonical symlink roots, replacement and capped backoff. TypeScript compilation passed. The isolated real VS Code gate passed starting without discovery, file creation, server replacement on a new port, continued project queries, manual mode, SDK navigation and ordinary project editing. This gate uses a development-classpath LSP host, not a packaged Studio installation or the user's active Zelda editor. No runtime files were changed and no commits were created.
References
- Project-local state specification
- Extension operation
LspLifecycleAdapter,LspDiscoveryTest,discovery.tsandExternalSourceDevelopmentHostTestcontain the executable contract.