Skip to content

Commit

Permalink
Improve first use experience
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jpogran committed Sep 3, 2021
1 parent 22a1883 commit dfdfee2
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -156,6 +158,26 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
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);
}
Expand Down

0 comments on commit dfdfee2

Please sign in to comment.