From dfdfee2f1e483f59080f0a6a6c9170b9337704c5 Mon Sep 17 00:00:00 2001 From: James Pogran Date: Fri, 3 Sep 2021 13:11:12 -0400 Subject: [PATCH] Improve first use experience Add a check to see if the current workspace has been initialized. If not, pop a warning message informing the user why that is important for the performance of the extension and provide a set of actions for the user to choose. They can either ignore the message, see documentation, or choose to execute terraform init. When choosing terraform init, it will open the command pallete and wait for the user to execute. This accomplishes the init task as well as teaching the user how the builtin commands help. --- src/extension.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/extension.ts b/src/extension.ts index 39a0ca58d..d9036a6a6 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,3 +1,5 @@ +import * as fs from 'fs'; +import * as path from 'path'; import * as vscode from 'vscode'; import TelemetryReporter from 'vscode-extension-telemetry'; import { ExecuteCommandParams, ExecuteCommandRequest } from 'vscode-languageclient'; @@ -156,6 +158,26 @@ export async function activate(context: vscode.ExtensionContext): Promise { if (enabled()) { try { await vscode.commands.executeCommand('terraform.enableLanguageServer'); + + try { + // const terraDir = vscode.Uri.parse(path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, '.terraform')); + const terraDir = path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, '.terraform'); + fs.accessSync(terraDir, fs.constants.X_OK); + } catch (err) { + const message = ''; + const response = await vscode.window.showWarningMessage( + 'No .terraform directory found. You should run "Terraform: init" from the Command Pallete first.', + { modal: false }, + { title: "Don't check again" }, + { title: 'Run init' }, + ); + if (response.title == "Don't check again") { + vscode.window.showInformationMessage('Forgettings'); + } + if (response.title == 'Run init') { + await vscode.commands.executeCommand('workbench.action.quickOpen', '> Terraform: init current folder'); + } + } } catch (error) { reporter.sendTelemetryException(error); }