Skip to content

Commit

Permalink
feat: add command to graph terraform project (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mukundan314 authored Oct 1, 2021
1 parent 0054a26 commit 5c9a1c5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
],
"activationEvents": [
"onView:terrastate.terrastate",
"onCommand:terrastate.refresh"
"onCommand:terrastate.refresh",
"onCommand:terrastate.init",
"onCommand:terrastate.graph"
],
"main": "./dist/extension.js",
"contributes": {
Expand Down Expand Up @@ -203,10 +205,6 @@
}
],
"commandPalette": [
{
"command": "terrastate.graph",
"when": "false"
},
{
"command": "terrastate.validate",
"when": "false"
Expand Down
39 changes: 26 additions & 13 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,30 @@ export async function activate(
);

context.subscriptions.push(
vscode.commands.registerCommand("terrastate.graph", async (arg: string) => {
const panel = vscode.window.createWebviewPanel(
"Graph",
"Terrastate – Graph",
vscode.ViewColumn.One,
{ enableScripts: true }
);
panel.iconPath = vscode.Uri.joinPath(
context.extensionUri,
"media/terrastate.png"
);
panel.webview.html = `
vscode.commands.registerCommand(
"terrastate.graph",
async (arg?: string) => {
if (arg === undefined) {
arg = (await terrastateProvider.pickTopLevelModule())?.directory;
}

if (arg === undefined) {
return;
}

const panel = vscode.window.createWebviewPanel(
"Graph",
"Terrastate – Graph",
vscode.ViewColumn.One,
{ enableScripts: true }
);

panel.iconPath = vscode.Uri.joinPath(
context.extensionUri,
"media/terrastate.png"
);

panel.webview.html = `
<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -130,6 +142,7 @@ export async function activate(
</body>
</html>
`;
})
}
)
);
}
2 changes: 1 addition & 1 deletion src/terrastateProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export class TerrastateProvider implements vscode.TreeDataProvider<Item> {
}
}

private async pickTopLevelModule(): Promise<Item | undefined> {
async pickTopLevelModule(): Promise<Item | undefined> {
const choice = await vscode.window.showQuickPick(
[...this.topLevelModules.keys()].map((directory) => ({
label: path.dirname(
Expand Down

0 comments on commit 5c9a1c5

Please sign in to comment.