Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added "KCL: Restart Language Server" command to restart the KCL language server #43

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Peefy marked this conversation as resolved.
Show resolved Hide resolved

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
Loading