/****************************************************************************** * Copyright 2021 TypeFox GmbH * This program and the accompanying materials are made available under the * terms of the MIT License, which is available in the project root. ******************************************************************************/ import type { LanguageClientOptions, ServerOptions } from 'vscode-languageclient/node'; import type * as vscode from 'vscode'; import * as path from 'node:path'; import { LanguageClient, TransportKind } from 'vscode-languageclient/node'; let client: LanguageClient; // This function is called when the extension is activated. export async function activate(context: vscode.ExtensionContext): Promise { client = await startLanguageClient(context); } // This function is called when the extension is deactivated. export function deactivate(): Thenable | undefined { if (client) { return client.stop(); } return undefined; } async function startLanguageClient(context: vscode.ExtensionContext): Promise { const serverModule = context.asAbsolutePath(path.join('out', 'language-server', 'main.cjs')); // The debug options for the server // --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging const debugOptions = { execArgv: ['--nolazy', '--inspect=6009'] }; // If the extension is launched in debug mode then the debug server options are used // Otherwise the run options are used const serverOptions: ServerOptions = { run: { module: serverModule, transport: TransportKind.ipc }, debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions } }; // Options to control the language client const clientOptions: LanguageClientOptions = { documentSelector: [{ scheme: 'file', language: 'domain-model' }] }; // Create the language client and start the client. const client = new LanguageClient( 'domain-model', 'DomainModel', serverOptions, clientOptions ); // Start the client. This will also launch the server await client.start(); return client; }