|
| 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 * as path from 'path'; |
| 7 | +import { workspace, ExtensionContext } from 'vscode'; |
| 8 | + |
| 9 | +import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient/node'; |
| 10 | + |
| 11 | +let client: LanguageClient; |
| 12 | + |
| 13 | +export function activate(context: ExtensionContext) { |
| 14 | + console.log('init'); |
| 15 | + // The server is implemented in node |
| 16 | + const serverModule = context.asAbsolutePath(path.join('server', 'out', 'index.js')); |
| 17 | + // The debug options for the server |
| 18 | + // --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging |
| 19 | + const debugOptions = { execArgv: ['--nolazy', '--inspect=6009'] }; |
| 20 | + |
| 21 | + // If the extension is launched in debug mode then the debug server options are used |
| 22 | + // Otherwise the run options are used |
| 23 | + const serverOptions: ServerOptions = { |
| 24 | + run: { module: serverModule, transport: TransportKind.ipc }, |
| 25 | + debug: { |
| 26 | + module: serverModule, |
| 27 | + transport: TransportKind.ipc, |
| 28 | + options: debugOptions, |
| 29 | + }, |
| 30 | + }; |
| 31 | + |
| 32 | + // Options to control the language client |
| 33 | + const clientOptions: LanguageClientOptions = { |
| 34 | + // Register the server for plain text documents |
| 35 | + documentSelector: [{ scheme: 'file', language: 'bitloops' }], |
| 36 | + synchronize: { |
| 37 | + // Notify the server about file changes to '.clientrc files contained in the workspace |
| 38 | + fileEvents: workspace.createFileSystemWatcher('**/.clientrc'), |
| 39 | + }, |
| 40 | + }; |
| 41 | + |
| 42 | + // Create the language client and start the client. |
| 43 | + client = new LanguageClient('Bitloops LSP', 'Bitloops LSP', serverOptions, clientOptions); |
| 44 | + // console.log(client); |
| 45 | + |
| 46 | + // Start the client. This will also launch the server |
| 47 | + client.start(); |
| 48 | +} |
| 49 | + |
| 50 | +export function deactivate(): Thenable<void> | undefined { |
| 51 | + if (!client) { |
| 52 | + return undefined; |
| 53 | + } |
| 54 | + return client.stop(); |
| 55 | +} |
0 commit comments