Move lsp server to this repo (#5619)

This commit is contained in:
Jess Frazelle
2025-03-04 22:21:12 -08:00
committed by GitHub
parent e8af61e11f
commit 37715d9fa8
47 changed files with 5929 additions and 28 deletions

View File

@ -0,0 +1,74 @@
/* eslint suggest-no-throw/suggest-no-throw: 0 */
import * as lc from 'vscode-languageclient/node'
import type * as vscode from 'vscode'
export async function createClient(
traceOutputChannel: vscode.OutputChannel,
outputChannel: vscode.OutputChannel,
initializationOptions: vscode.WorkspaceConfiguration,
serverOptions: lc.ServerOptions
): Promise<lc.LanguageClient> {
const clientOptions: lc.LanguageClientOptions = {
documentSelector: [{ scheme: 'file', language: 'kcl' }],
initializationOptions,
traceOutputChannel,
outputChannel,
middleware: {
workspace: {
// HACK: This is a workaround, when the client has been disposed, VSCode
// continues to emit events to the client and the default one for this event
// attempt to restart the client for no reason
async didChangeWatchedFile(event: any, next: any) {
if (client.isRunning()) {
await next(event)
}
},
async configuration(
params: lc.ConfigurationParams,
token: vscode.CancellationToken,
next: lc.ConfigurationRequest.HandlerSignature
) {
const resp = await next(params, token)
return resp
},
},
},
}
const client = new lc.LanguageClient(
'kcl-language-server',
'KittyCAD Language Server',
serverOptions,
clientOptions
)
client.registerFeature(new ExperimentalFeatures())
return client
}
class ExperimentalFeatures implements lc.StaticFeature {
getState(): lc.FeatureState {
return { kind: 'static' }
}
fillClientCapabilities(capabilities: lc.ClientCapabilities): void {
capabilities.experimental = {
snippetTextEdit: true,
codeActionGroup: true,
hoverActions: true,
serverStatusNotification: true,
colorDiagnosticOutput: true,
openServerLogs: true,
commands: {
commands: ['editor.action.triggerParameterHints'],
},
...capabilities.experimental,
}
}
initialize(
_capabilities: lc.ServerCapabilities,
_documentSelector: lc.DocumentSelector | undefined
): void {}
dispose(): void {}
clear(): void {}
}