mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-19 11:40:27 +00:00
This PR adds a new command to the Carbon VSCode extension "carbon: Restart language server" which acts similar to clangd / bazel extensions. While not useful during regular working of the extension this helps when LSP either crashes or the toolchain is updated. In order to support graceful restart, I needed to add a Call handler for "shutdown" which is noop for now. Lsp clients always call shutdown before sending exit. --------- Co-authored-by: jonmeow <jperkins@google.com>
60 lines
1.4 KiB
TypeScript
60 lines
1.4 KiB
TypeScript
/*
|
|
* Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
* Exceptions. See /LICENSE for license information.
|
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
*/
|
|
|
|
/*
|
|
* This is the main launcher for the LSP extension.
|
|
*/
|
|
|
|
import { workspace, ExtensionContext, commands } from 'vscode';
|
|
|
|
import {
|
|
LanguageClient,
|
|
LanguageClientOptions,
|
|
ServerOptions,
|
|
} from 'vscode-languageclient/node';
|
|
|
|
let client: LanguageClient;
|
|
|
|
export function activate(context: ExtensionContext) {
|
|
const settings = workspace.getConfiguration('carbon');
|
|
|
|
const serverOptions: ServerOptions = {
|
|
// The Carbon server can be configured, but we try to use bazel output as a
|
|
// fallback.
|
|
command: settings.get(
|
|
'carbonPath',
|
|
context.asAbsolutePath('./bazel-bin/toolchain/carbon')
|
|
),
|
|
args: ['language-server'],
|
|
};
|
|
|
|
const clientOptions: LanguageClientOptions = {
|
|
documentSelector: [{ language: 'carbon' }],
|
|
};
|
|
|
|
// Create and start the client.
|
|
client = new LanguageClient(
|
|
'carbonLanguageServer',
|
|
'Carbon Language Server',
|
|
serverOptions,
|
|
clientOptions
|
|
);
|
|
client.start();
|
|
|
|
context.subscriptions.push(
|
|
commands.registerCommand('carbon.lsp.restart', () => {
|
|
client.restart();
|
|
})
|
|
);
|
|
}
|
|
|
|
export function deactivate(): Thenable<void> | undefined {
|
|
if (!client) {
|
|
return undefined;
|
|
}
|
|
return client.stop();
|
|
}
|