main
ts 69 lines 1.63 KB
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 import * as path from 'path';
9 import * as vscode from 'vscode';
10
11 import {
12 LanguageClient,
13 LanguageClientOptions,
14 ServerOptions,
15 TransportKind,
16 } from 'vscode-languageclient/node';
17
18 let client: LanguageClient;
19
20 export function activate(context: vscode.ExtensionContext) {
21 const serverModule = context.asAbsolutePath(path.join('dist', 'server.js'));
22 const documentSelector = [
23 {scheme: 'file', language: 'javascriptreact'},
24 {scheme: 'file', language: 'typescriptreact'},
25 ];
26
27 // If the extension is launched in debug mode then the debug server options are used
28 // Otherwise the run options are used
29 const serverOptions: ServerOptions = {
30 run: {
31 module: serverModule,
32 transport: TransportKind.ipc,
33 },
34 debug: {
35 module: serverModule,
36 transport: TransportKind.ipc,
37 },
38 };
39
40 const clientOptions: LanguageClientOptions = {
41 documentSelector,
42 progressOnInitialization: true,
43 };
44
45 // Create the language client and start the client.
46 try {
47 client = new LanguageClient(
48 'react-forgive',
49 'React Analyzer',
50 serverOptions,
51 clientOptions,
52 );
53 } catch {
54 vscode.window.showErrorMessage(
55 `React Analyzer couldn't be started. See the output channel for details.`,
56 );
57 return;
58 }
59
60 client.registerProposedFeatures();
61 client.start();
62 }
63
64 export function deactivate(): Thenable<void> | undefined {
65 if (client !== undefined) {
66 return client.stop();
67 }
68 return;
69 }