|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
| 17 | +import path = require('path'); |
17 | 18 | import {
|
18 | 19 | workspace,
|
19 | 20 | ExtensionContext,
|
20 | 21 | ConfigurationScope,
|
21 |
| - WorkspaceConfiguration |
| 22 | + WorkspaceConfiguration, |
| 23 | + commands, |
| 24 | + window, |
| 25 | + Uri, |
22 | 26 | } from 'vscode';
|
23 | 27 |
|
| 28 | + import * as vscode from 'vscode'; |
| 29 | + |
24 | 30 | import {
|
| 31 | + ExecuteCommandParams, |
| 32 | + ExecuteCommandRequest, |
25 | 33 | LanguageClient,
|
26 | 34 | LanguageClientOptions,
|
27 | 35 | } from 'vscode-languageclient/node';
|
@@ -50,10 +58,76 @@ export function activate(ctx: ExtensionContext) {
|
50 | 58 |
|
51 | 59 | console.log("terramate-ls path: "+getServerPath(ctx));
|
52 | 60 |
|
| 61 | + const terramateStatus = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 0); |
| 62 | + |
| 63 | + ctx.subscriptions.push(vscode.commands.registerCommand('terramate.createStack', async (dir:vscode.Uri) => { |
| 64 | + terramateStatus.text = "Creating stack"; |
| 65 | + terramateStatus.show(); |
| 66 | + if (dir === undefined) { |
| 67 | + const selected = await vscode.window.showOpenDialog({ |
| 68 | + title: "Select the directory for the stack creation", |
| 69 | + canSelectFiles: false, |
| 70 | + canSelectFolders: true, |
| 71 | + canSelectMany: false, |
| 72 | + defaultUri: vscode.workspace.workspaceFolders[0].uri, |
| 73 | + openLabel: "Create Stack" |
| 74 | + }); |
| 75 | + if (selected) { |
| 76 | + dir = selected[0]; |
| 77 | + } else { |
| 78 | + vscode.window.showErrorMessage("no file selected"); |
| 79 | + terramateStatus.hide(); |
| 80 | + return; |
| 81 | + } |
| 82 | + } |
| 83 | + const name = await vscode.window.showInputBox({ |
| 84 | + title: "Name of the stack", |
| 85 | + }); |
| 86 | + const desc = await vscode.window.showInputBox({ |
| 87 | + title: "Description of the stack", |
| 88 | + }); |
| 89 | + const val = await vscode.window.showQuickPick(["yes", "no"], { |
| 90 | + title: "Generate the stack.id with an UUID v4?", |
| 91 | + }); |
| 92 | + try { |
| 93 | + const res = await createStackCommand(client, dir, name, desc, val == "yes"); |
| 94 | + console.log(res); |
| 95 | + } catch (err) { |
| 96 | + await vscode.window.showErrorMessage(err.toString()); |
| 97 | + } |
| 98 | + terramateStatus.hide(); |
| 99 | + })); |
| 100 | + |
53 | 101 | // Start the client. This will also launch the server
|
54 | 102 | ctx.subscriptions.push(client.start());
|
55 | 103 | }
|
56 | 104 |
|
| 105 | +async function createStackCommand(client: LanguageClient, moduleUri: vscode.Uri, name: string, desc: string, genid = true): Promise<any> { |
| 106 | + const args = [ |
| 107 | + `uri=${moduleUri.toString()}`, |
| 108 | + ]; |
| 109 | + if (name !== '') { |
| 110 | + args.push(`name=${name}`); |
| 111 | + } else { |
| 112 | + args.push(`name=${path.basename(moduleUri.path)}`); |
| 113 | + } |
| 114 | + if (desc !== '') { |
| 115 | + args.push(`description=${desc}`); |
| 116 | + } |
| 117 | + if (genid) { |
| 118 | + args.push(`genid=true`); |
| 119 | + } |
| 120 | + const requestParams: ExecuteCommandParams = { |
| 121 | + command: `terramate.createStack`, |
| 122 | + arguments: args, |
| 123 | + }; |
| 124 | + return execWorkspaceCommand(client, requestParams); |
| 125 | +} |
| 126 | + |
| 127 | +function execWorkspaceCommand(client: LanguageClient, params: ExecuteCommandParams): Promise<any> { |
| 128 | + return client.sendRequest(ExecuteCommandRequest.type, params); |
| 129 | +} |
| 130 | + |
57 | 131 | export function deactivate(): Thenable<void> | undefined {
|
58 | 132 | if (!client) {
|
59 | 133 | return undefined;
|
|
0 commit comments