fix(lsp): support server workspace configuration
This commit is contained in:
@@ -102,9 +102,19 @@ export class LspClient {
|
||||
}
|
||||
},
|
||||
);
|
||||
// Accept Common Server Requests - Return empty/null so servers don't
|
||||
// stall. Good enough for a CLI; a real client would answer properly.
|
||||
this.conn.onRequest("workspace/configuration", () => []);
|
||||
// Accept Common Server Requests - Return one configuration response per
|
||||
// requested item. Server-specific settings live in server.ts so adding
|
||||
// another picky server doesn't grow conditionals in this transport layer.
|
||||
this.conn.onRequest(
|
||||
"workspace/configuration",
|
||||
(params: { items?: { section?: string }[] }) => {
|
||||
const items = params.items ?? [];
|
||||
const config = this.server.workspaceConfiguration;
|
||||
return items.map((item) =>
|
||||
config?.getSection?.(item.section, { rootDir, env }) ?? null,
|
||||
);
|
||||
},
|
||||
);
|
||||
this.conn.onRequest("client/registerCapability", () => null);
|
||||
this.conn.onRequest("client/unregisterCapability", () => null);
|
||||
|
||||
@@ -136,6 +146,16 @@ export class LspClient {
|
||||
},
|
||||
});
|
||||
this.conn.sendNotification("initialized", {});
|
||||
|
||||
// Push Configuration - Some servers do not always request workspace/configuration,
|
||||
// but still consume settings delivered through didChangeConfiguration.
|
||||
const settings = this.server.workspaceConfiguration?.initialSettings?.({
|
||||
rootDir,
|
||||
env,
|
||||
});
|
||||
if (settings !== undefined && settings !== null) {
|
||||
this.conn.sendNotification("workspace/didChangeConfiguration", { settings });
|
||||
}
|
||||
}
|
||||
|
||||
// Wait For Ready - Resolves when there are no outstanding progress
|
||||
|
||||
19
src/types.ts
19
src/types.ts
@@ -17,6 +17,22 @@ export class ServerNotFoundError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
export interface WorkspaceConfigurationContext {
|
||||
rootDir: string;
|
||||
env: NodeJS.ProcessEnv;
|
||||
}
|
||||
|
||||
export interface ServerWorkspaceConfiguration {
|
||||
// Initial Settings - Optional payload pushed via workspace/didChangeConfiguration
|
||||
// after initialize/initialized for servers that don't always request config.
|
||||
initialSettings?: (ctx: WorkspaceConfigurationContext) => unknown;
|
||||
// Section Settings - Optional handler for workspace/configuration requests.
|
||||
getSection?: (
|
||||
section: string | undefined,
|
||||
ctx: WorkspaceConfigurationContext,
|
||||
) => unknown;
|
||||
}
|
||||
|
||||
export interface ServerConfig {
|
||||
// Stable identifier (useful for logs and future daemon cache keys).
|
||||
id: string;
|
||||
@@ -38,6 +54,9 @@ export interface ServerConfig {
|
||||
// hover/definition/references/completion/documentSymbol but included
|
||||
// in lsp_diagnostics and auto-check.
|
||||
diagnosticsOnly?: boolean;
|
||||
// Workspace Configuration - Optional server-specific settings exposed through
|
||||
// workspace/configuration and workspace/didChangeConfiguration.
|
||||
workspaceConfiguration?: ServerWorkspaceConfiguration;
|
||||
}
|
||||
|
||||
// Supported high-level commands exposed via the CLI. Extend this union
|
||||
|
||||
Reference in New Issue
Block a user