Skip to content

Commit

Permalink
feat: implements the terramate.createStack command.
Browse files Browse the repository at this point in the history
Signed-off-by: Tiago Natel <[email protected]>
Signed-off-by: i4k <[email protected]>
  • Loading branch information
i4ki committed May 14, 2024
1 parent cf0ed98 commit 875e7e9
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 10 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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/[email protected]
uses: coactions/setup-xvfb@v1
env:
DBUS_SESSION_BUS_ADDRESS: unix:path=/run/user/1000/bus
with:
run: make test VERSION=${{ matrix.version }}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ addlicense=go run github.com/google/[email protected] \
-ignore 'node_modules/**' -ignore 'testFixture/**' \
-ignore '.vscode-test/**'

terramate_ls_version=latest
terramate_ls_version=v0.8.4
terramate_ls_url=github.com/terramate-io/terramate/cmd/...@$(terramate_ls_version)

.PHONY: default
Expand Down
26 changes: 21 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"vscode": "^1.52.0"
},
"activationEvents": [
"onLanguage:terramate"
"onLanguage:terramate",
"onCommand:terramate.createStack"
],
"main": "./out/extension",
"contributes": {
Expand Down Expand Up @@ -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",
Expand All @@ -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"
}
}
76 changes: 75 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<any> {
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<any> {
return client.sendRequest(ExecuteCommandRequest.type, params);
}

export function deactivate(): Thenable<void> | undefined {
if (!client) {
return undefined;
Expand Down

0 comments on commit 875e7e9

Please sign in to comment.