Skip to content
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
6 changes: 5 additions & 1 deletion vscode-extension/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
"request": "launch",
"name": "Launch Client",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
"args": [
"${workspaceFolder}/test-workspace",
"--extensionDevelopmentPath=${workspaceFolder}",
"--disableExtensions"
],
"outFiles": [
"${workspaceRoot}/client/out/**/*.js",
],
Expand Down
24 changes: 24 additions & 0 deletions vscode-extension/client/src/components/activityBar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as vscode from 'vscode';
import * as providers from '../providers';
import * as models from '../models';

export class ActivityBar {
private _provider: providers.CommandsProvider;

constructor() {
this._provider = new providers.CommandsProvider();
vscode.window.createTreeView('lets-ls.commands', {
treeDataProvider: this._provider,
showCollapseAll: true
});
}

public setTreeNesting(enabled: boolean) {
this._provider.setTreeNesting(enabled);
this._provider.refresh();
}

public refresh(commands?: models.Command[]) {
this._provider.refresh(commands);
}
}
2 changes: 2 additions & 0 deletions vscode-extension/client/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { ActivityBar } from './activityBar';
export { TreeItem, CommandTreeItem, WorkspaceTreeItem } from './treeItem';
36 changes: 36 additions & 0 deletions vscode-extension/client/src/components/treeItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as vscode from 'vscode';
import * as models from '../models';

export type TreeItem = WorkspaceTreeItem | CommandTreeItem;

export class WorkspaceTreeItem extends vscode.TreeItem {
constructor(
readonly label: string,
readonly workspace: string,
readonly letsCommands: models.Command[],
readonly collapsibleState: vscode.TreeItemCollapsibleState,
readonly command?: vscode.Command
) {
super(label, collapsibleState);
this.description = this.workspace;
this.iconPath = new vscode.ThemeIcon('folder', new vscode.ThemeColor('letsls.workspaceIcon'));
this.contextValue = `workspaceTreeItem`;
}
}

export class CommandTreeItem extends vscode.TreeItem {
constructor(
readonly label: string,
readonly letsCommand: models.Command,
readonly collapsibleState: vscode.TreeItemCollapsibleState,
readonly command?: vscode.Command
) {
super(label, collapsibleState);
this.description = this.letsCommand?.description || "";
if (this.description.startsWith("No description")) {
this.description = false;
};
this.iconPath = new vscode.ThemeIcon('debug-breakpoint-log-unverified', new vscode.ThemeColor('letsls.upToDateIcon'));
this.contextValue = `commandTreeItem`;
}
}
146 changes: 8 additions & 138 deletions vscode-extension/client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,154 +2,24 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */

import { execSync } from "child_process";
import { ExtensionContext } from "vscode";
import * as vscode from "vscode";
import {
OutputChannel,
} from "vscode";
import {
LanguageClient,
LanguageClientOptions,
ServerOptions,
RevealOutputChannelOn,
} from "vscode-languageclient/node";
import { LetsExtension } from "./lets";

const SKIP_VERSION_STATE_KEY = "skipUpdate";
const REPO = "https://github.com/kindermax/lets_ls"
let client: LanguageClient;
let extension: LetsExtension;

export function activate(context: ExtensionContext) {
if (client?.isRunning()) {
if (extension?.isRunning()) {
return;
}

const outputChannel: OutputChannel = vscode.window.createOutputChannel("Lets LS");

const config = vscode.workspace.getConfiguration("letsLs");

const serverOptions: ServerOptions = {
run: { command: config.get("executablePath") },
debug: {
command: config.get("executablePath"),
},
};

// Options to control the language client
const clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: [
{ scheme: "file", language: "yaml", pattern: "**/lets.yaml" },
{ scheme: "file", language: "yaml", pattern: "**/lets.*.yaml" },
],
initializationOptions: {
log_path: config.get("logPath"),
},
outputChannel,
outputChannelName: 'Lets Language Server',
revealOutputChannelOn: RevealOutputChannelOn.Never,
initializationFailedHandler(err) {
outputChannel.appendLine('Initialization failed');
outputChannel.appendLine(err.message);
if (err.stack) {
outputChannel.appendLine(err.stack);
}
return false;
},
};

// Create the language client and start the client.
client = new LanguageClient(
"letsLs",
serverOptions,
clientOptions,
);

// Start the client. This will also launch the server
client.start();

context.subscriptions.push(
vscode.commands.registerCommand('lets-ls.restart', async () => {
try {
outputChannel.appendLine('Stopping Lets Language server');
await client.stop();

outputChannel.appendLine('Restarting Lets Language server');
await client.start();
outputChannel.appendLine('Lets Language server restarted');
} catch (e) {
outputChannel.appendLine(`Failed to restart Lets Language server: ${e}`);
}
})
);

checkUpdates(context, config.get("executablePath"));
}

async function checkUpdates(
context: ExtensionContext,
executable: string,
): Promise<void> {
const res = await fetch(
`${REPO}/releases/latest`,
);

// js is perfect
const { tag_name } = (await res.json()) as any;

//check if skipped
const val = context.globalState.get(SKIP_VERSION_STATE_KEY);
if (val && val === tag_name) {
return;
}

const version = execSync(`${executable} --version`).toString();

// older version which doesn't support --version
if (!version) {
return;
}

// format of: lets_ls X.X.X
const versionSplit = version.split(" ");

// shouldn't occur
if (versionSplit.length != 2) {
return;
}

const versionTag = versionSplit[1].trim();

if (tag_name != versionTag) {
vscode.window
.showInformationMessage(
"There is a newer version of Lets language server.",
"Show installation guide",
"Show changes",
"Skip this version",
)
.then((answer) => {
let url = "";
if (answer === "Show changes") {
url = `${REPO}/compare/${versionTag}...${tag_name}`;
} else if (answer === "Show installation guide") {
url =
`${REPO}?tab=readme-ov-file#installation`;
} else if (answer === "Skip this version") {
context.globalState.update(SKIP_VERSION_STATE_KEY, tag_name);
}

if (url != "") {
vscode.env.openExternal(vscode.Uri.parse(url));
}
});
}
extension = new LetsExtension();
extension.activate(context);
extension.refresh();
}

export function deactivate(): Thenable<void> | undefined {
if (!client) {
if (!extension) {
return undefined;
}
return client.stop();
return extension.deactivate();
}
Loading