Skip to content

Commit

Permalink
added "KCL: Restart Language Server" command to restart the KCL langu…
Browse files Browse the repository at this point in the history
…age server
  • Loading branch information
Gmin2 committed Apr 11, 2024
1 parent 3a192cc commit 7a7b558
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"activationEvents": [
"onLanguage:KCL",
"onLanguage:YAML",
"onLanguage:MOD"
"onLanguage:MOD",
"onCommand:kcl.restartLanguageServer"
],
"main": "./out/extension.js",
"scripts": {
Expand Down Expand Up @@ -42,6 +43,12 @@
"typescript": "^4.7.2"
},
"contributes": {
"commands": [
{
"command": "kcl.restartLanguageServer",
"title": "KCL: Restart Language Server"
}
],
"type": "object",
"title": "KCL configuration",
"properties": {
Expand Down
16 changes: 16 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
let client: LanguageClient;

export async function activate(context: vscode.ExtensionContext) {
console.log('KCL extension activated');
const autoCompletionProvider = vscode.languages.registerCompletionItemProvider('KCL', {
provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext) {
return autoCompletionItems();
Expand All @@ -28,7 +29,11 @@ export async function activate(context: vscode.ExtensionContext) {
// }
// });

const restartLanguageServerCommand = vscode.commands.registerCommand('kcl.restartLanguageServer', restartLanguageServer, "KCL: Restart Language Server");
console.log('KCL: Restart Language Server command registered');

context.subscriptions.push(autoCompletionProvider);
context.subscriptions.push(restartLanguageServerCommand);

const language_server_path: string | undefined = install.kcl_rust_lsp_location();
// if (!language_server_path) {
Expand Down Expand Up @@ -88,6 +93,17 @@ function startLanguageServerWith(language_server_path: string) {
install.outputMsg(`${install.KCL_LANGUAGE_SERVER} started!`);
}

function restartLanguageServer() {
if (client) {
client.stop().then(() => {
const language_server_path = install.kcl_rust_lsp_location();
if (language_server_path) {
startLanguageServerWith(language_server_path);
}
});
}
}

function autoCompletionItems(): vscode.CompletionItem[] {
const snippetCompletions: {label: string, text: string}[] = [
{label: 'import as', text: 'import ${1:path} as ${2:alias}'},
Expand Down

0 comments on commit 7a7b558

Please sign in to comment.