diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea51fc3..882e2ce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: - go-version: "1.20" + go-version: "1.22" - uses: actions/setup-node@v2 with: node-version: ^18 @@ -21,6 +21,7 @@ jobs: run: make license/check build: strategy: + fail-fast: false matrix: version: [ '', # uses the minimum supported version defined in package.json @@ -36,11 +37,13 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: - go-version: "1.20" + go-version: "1.22" - uses: actions/setup-node@v2 with: node-version: ^18 - name: Run tests - uses: GabrielBB/xvfb-action@v1.0 + uses: coactions/setup-xvfb@v1 + env: + DBUS_SESSION_BUS_ADDRESS: unix:path=/run/user/1000/bus with: run: make test VERSION=${{ matrix.version }} diff --git a/Makefile b/Makefile index 256f1b5..113c54e 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ addlicense=go run github.com/google/addlicense@v1.0.0 \ -ignore 'node_modules/**' -ignore 'testFixture/**' \ -ignore '.vscode-test/**' -terramate_ls_version=latest +terramate_ls_version=v0.9.0 terramate_ls_url=github.com/terramate-io/terramate/cmd/...@$(terramate_ls_version) .PHONY: default diff --git a/package.json b/package.json index 91db559..08a3b20 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,8 @@ "vscode": "^1.52.0" }, "activationEvents": [ - "onLanguage:terramate" + "onLanguage:terramate", + "onCommand:terramate.createStack" ], "main": "./out/extension", "contributes": { @@ -87,7 +88,22 @@ } } } - ] + ], + "commands": [ + { + "command": "terramate.createStack", + "title": "Create Terramate Stack", + "category": "Terramate" + } + ], + "menus": { + "explorer/context": [ + { + "command": "terramate.createStack", + "group": "terramate" + } + ] + } }, "scripts": { "vscode:prepublish": "npm run compile", @@ -104,12 +120,12 @@ "@types/vscode": "^1.52.0", "@typescript-eslint/eslint-plugin": "^5.18.0", "@typescript-eslint/parser": "^5.18.0", - "@vscode/test-electron": "^2.1.2", + "@vscode/test-electron": "^2.3.8", "eslint": "^8.12.0", "mocha": "^9.2.1", "ovsx": "^0.5.0", + "semver": "^7.3.7", "typescript": "^4.6.2", - "vsce": "^2.9.1", - "semver": "^7.3.7" + "vsce": "^2.15.0" } } diff --git a/src/extension.ts b/src/extension.ts index 9e48ca7..8518f00 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -14,14 +14,22 @@ * limitations under the License. */ +import path = require('path'); import { workspace, ExtensionContext, ConfigurationScope, - WorkspaceConfiguration + WorkspaceConfiguration, + commands, + window, + Uri, } from 'vscode'; + import * as vscode from 'vscode'; + import { + ExecuteCommandParams, + ExecuteCommandRequest, LanguageClient, LanguageClientOptions, } from 'vscode-languageclient/node'; @@ -50,10 +58,76 @@ export function activate(ctx: ExtensionContext) { console.log("terramate-ls path: "+getServerPath(ctx)); + const terramateStatus = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 0); + + ctx.subscriptions.push(vscode.commands.registerCommand('terramate.createStack', async (dir:vscode.Uri) => { + terramateStatus.text = "Creating stack"; + terramateStatus.show(); + if (dir === undefined) { + const selected = await vscode.window.showOpenDialog({ + title: "Select the directory for the stack creation", + canSelectFiles: false, + canSelectFolders: true, + canSelectMany: false, + defaultUri: vscode.workspace.workspaceFolders[0].uri, + openLabel: "Create Stack" + }); + if (selected) { + dir = selected[0]; + } else { + vscode.window.showErrorMessage("no file selected"); + terramateStatus.hide(); + return; + } + } + const name = await vscode.window.showInputBox({ + title: "Name of the stack", + }); + const desc = await vscode.window.showInputBox({ + title: "Description of the stack", + }); + const val = await vscode.window.showQuickPick(["yes", "no"], { + title: "Generate the stack.id with an UUID v4?", + }); + try { + const res = await createStackCommand(client, dir, name, desc, val == "yes"); + console.log(res); + } catch (err) { + await vscode.window.showErrorMessage(err.toString()); + } + terramateStatus.hide(); + })); + // Start the client. This will also launch the server ctx.subscriptions.push(client.start()); } +async function createStackCommand(client: LanguageClient, moduleUri: vscode.Uri, name: string, desc: string, genid = true): Promise { + const args = [ + `uri=${moduleUri.toString()}`, + ]; + if (name !== '') { + args.push(`name=${name}`); + } else { + args.push(`name=${path.basename(moduleUri.path)}`); + } + if (desc !== '') { + args.push(`description=${desc}`); + } + if (genid) { + args.push(`genid=true`); + } + const requestParams: ExecuteCommandParams = { + command: `terramate.createStack`, + arguments: args, + }; + return execWorkspaceCommand(client, requestParams); +} + +function execWorkspaceCommand(client: LanguageClient, params: ExecuteCommandParams): Promise { + return client.sendRequest(ExecuteCommandRequest.type, params); +} + export function deactivate(): Thenable | undefined { if (!client) { return undefined;