Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/css-language-features/client/src/node/cssClientMain.ts
3322 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { ExtensionContext, extensions, l10n } from 'vscode';
7
import { BaseLanguageClient, LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient/node';
8
import { LanguageClientConstructor, startClient } from '../cssClient';
9
import { getNodeFSRequestService } from './nodeFs';
10
import { registerDropOrPasteResourceSupport } from '../dropOrPaste/dropOrPasteResource';
11
12
let client: BaseLanguageClient | undefined;
13
14
// this method is called when vs code is activated
15
export async function activate(context: ExtensionContext) {
16
const clientMain = extensions.getExtension('vscode.css-language-features')?.packageJSON?.main || '';
17
18
const serverMain = `./server/${clientMain.indexOf('/dist/') !== -1 ? 'dist' : 'out'}/node/cssServerMain`;
19
const serverModule = context.asAbsolutePath(serverMain);
20
21
// The debug options for the server
22
const debugOptions = { execArgv: ['--nolazy', '--inspect=' + (7000 + Math.round(Math.random() * 999))] };
23
24
// If the extension is launch in debug mode the debug server options are use
25
// Otherwise the run options are used
26
const serverOptions: ServerOptions = {
27
run: { module: serverModule, transport: TransportKind.ipc },
28
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
29
};
30
31
const newLanguageClient: LanguageClientConstructor = (id: string, name: string, clientOptions: LanguageClientOptions) => {
32
return new LanguageClient(id, name, serverOptions, clientOptions);
33
};
34
35
// pass the location of the localization bundle to the server
36
process.env['VSCODE_L10N_BUNDLE_LOCATION'] = l10n.uri?.toString() ?? '';
37
38
client = await startClient(context, newLanguageClient, { fs: getNodeFSRequestService(), TextDecoder });
39
40
context.subscriptions.push(registerDropOrPasteResourceSupport({ language: 'css', scheme: '*' }));
41
}
42
43
export async function deactivate(): Promise<void> {
44
if (client) {
45
await client.stop();
46
client = undefined;
47
}
48
}
49
50
51