Path: blob/main/extensions/css-language-features/client/src/node/cssClientMain.ts
3322 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { ExtensionContext, extensions, l10n } from 'vscode';6import { BaseLanguageClient, LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient/node';7import { LanguageClientConstructor, startClient } from '../cssClient';8import { getNodeFSRequestService } from './nodeFs';9import { registerDropOrPasteResourceSupport } from '../dropOrPaste/dropOrPasteResource';1011let client: BaseLanguageClient | undefined;1213// this method is called when vs code is activated14export async function activate(context: ExtensionContext) {15const clientMain = extensions.getExtension('vscode.css-language-features')?.packageJSON?.main || '';1617const serverMain = `./server/${clientMain.indexOf('/dist/') !== -1 ? 'dist' : 'out'}/node/cssServerMain`;18const serverModule = context.asAbsolutePath(serverMain);1920// The debug options for the server21const debugOptions = { execArgv: ['--nolazy', '--inspect=' + (7000 + Math.round(Math.random() * 999))] };2223// If the extension is launch in debug mode the debug server options are use24// Otherwise the run options are used25const serverOptions: ServerOptions = {26run: { module: serverModule, transport: TransportKind.ipc },27debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }28};2930const newLanguageClient: LanguageClientConstructor = (id: string, name: string, clientOptions: LanguageClientOptions) => {31return new LanguageClient(id, name, serverOptions, clientOptions);32};3334// pass the location of the localization bundle to the server35process.env['VSCODE_L10N_BUNDLE_LOCATION'] = l10n.uri?.toString() ?? '';3637client = await startClient(context, newLanguageClient, { fs: getNodeFSRequestService(), TextDecoder });3839context.subscriptions.push(registerDropOrPasteResourceSupport({ language: 'css', scheme: '*' }));40}4142export async function deactivate(): Promise<void> {43if (client) {44await client.stop();45client = undefined;46}47}48495051