Files
bf-server/client/src/extension.ts

73 lines
2.5 KiB
TypeScript
Raw Normal View History

2021-04-09 23:15:58 +05:30
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import * as path from 'path';
2024-01-02 22:32:24 +05:30
import { commands } from 'vscode';
import type { ExtensionContext } from 'vscode';
2021-04-09 23:15:58 +05:30
import {
2024-01-02 17:15:19 +05:30
LanguageClient,
LanguageClientOptions,
ServerOptions,
TransportKind,
2021-04-09 23:15:58 +05:30
} from 'vscode-languageclient';
2024-01-02 22:32:24 +05:30
import { CompileBranFlakesCommand } from './command/CompileBranFlakesCommand';
2021-04-09 23:15:58 +05:30
let client: LanguageClient;
export function activate(context: ExtensionContext) {
2024-01-02 17:15:19 +05:30
// The server is implemented in node
let serverModule = context.asAbsolutePath(
path.join('server', 'dist', 'server.js')
);
// 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
let debugOptions = { execArgv: ['--nolazy', '--inspect=6009'] };
2021-04-09 23:15:58 +05:30
2024-01-02 17:15:19 +05:30
// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
let serverOptions: ServerOptions = {
run: { module: serverModule, transport: TransportKind.ipc },
debug: {
module: serverModule,
transport: TransportKind.ipc,
options: debugOptions,
},
};
2021-04-09 23:15:58 +05:30
2024-01-02 17:15:19 +05:30
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: [{ scheme: 'file', language: 'bf' }],
};
2021-04-17 23:03:40 +05:30
2024-01-02 17:15:19 +05:30
const branFlakesCommands = [new CompileBranFlakesCommand()];
for (let branFlakesCommand of branFlakesCommands) {
context.subscriptions.push(
commands.registerCommand(
branFlakesCommand.getCommandName(),
branFlakesCommand.getCommandHandler()
)
);
}
2021-04-09 23:15:58 +05:30
2024-01-02 17:15:19 +05:30
// Create the language client and start the client.
client = new LanguageClient(
'brainfucklanguageserver',
'Brainfuck Language Server',
serverOptions,
clientOptions
);
2021-04-09 23:15:58 +05:30
2024-01-02 17:15:19 +05:30
// Start the client. This will also launch the server
client.start();
2021-04-09 23:15:58 +05:30
}
export function deactivate(): Thenable<void> | undefined {
2024-01-02 17:15:19 +05:30
if (!client) {
return undefined;
}
return client.stop();
2021-04-09 23:15:58 +05:30
}