fix(daemon): launch LSP servers with caller env

This commit is contained in:
2026-05-02 15:28:25 -04:00
parent 306771f92a
commit 04fd520438
5 changed files with 80 additions and 20 deletions

View File

@@ -14,6 +14,7 @@ import {
tryConnect,
type DaemonRequest,
type DaemonResponse,
type LaunchContext,
} from "./daemonProtocol.ts";
// Default Idle TTL - 5 minutes. Per-server overrides via ServerConfig.idleTtlMs.
@@ -52,7 +53,10 @@ function log(...args: unknown[]) {
// Get Or Create Entry - Looks up the cached client for a file, spawning a
// fresh LspClient if needed. The returned entry is guaranteed to have its
// `ready` promise resolved before the caller uses it.
async function getOrCreateEntry(filePath: string): Promise<ClientEntry> {
async function getOrCreateEntry(
filePath: string,
launch: LaunchContext,
): Promise<ClientEntry> {
const server = pickServer(filePath);
const rootDir = findRoot(filePath, server.rootMarkers);
const key = `${server.id}::${rootDir}`;
@@ -72,7 +76,7 @@ async function getOrCreateEntry(filePath: string): Promise<ClientEntry> {
client,
ready: (async () => {
log(`spawn`, server.id, rootDir);
await client.start(rootDir);
await client.start(rootDir, launch.env);
await client.waitForReady();
log(`ready`, server.id);
})(),
@@ -157,7 +161,7 @@ async function handle(req: DaemonRequest): Promise<DaemonResponse> {
switch (req.op) {
case "request": {
const filePath = path.resolve(req.file);
const entry = await getOrCreateEntry(filePath);
const entry = await getOrCreateEntry(filePath, req.launch);
const { uri } = await syncFile(entry, filePath);
bumpIdle(entry);
const result = await entry.client.sendRequest(
@@ -168,7 +172,7 @@ async function handle(req: DaemonRequest): Promise<DaemonResponse> {
}
case "diagnostics": {
const filePath = path.resolve(req.file);
const entry = await getOrCreateEntry(filePath);
const entry = await getOrCreateEntry(filePath, req.launch);
const { uri, changed } = await syncFile(entry, filePath);
bumpIdle(entry);
if (changed) entry.client.clearDiagnostics(uri);