Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix terraform status bar #857

Merged
merged 3 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { config, getActiveTextEditor } from './vscodeUtils';

const brand = `HashiCorp Terraform`;
const outputChannel = vscode.window.createOutputChannel(brand);
const terraformStatus = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 0);
export const terraformStatus = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 0);

let reporter: TelemetryReporter;
let clientHandler: ClientHandler;
Expand Down Expand Up @@ -158,7 +158,8 @@ export async function deactivate(): Promise<void> {
}

async function updateTerraformStatusBar(documentUri: vscode.Uri): Promise<void> {
const initSupported = clientHandler.clientSupportsCommand('terraform-ls.terraform.init');
const client = clientHandler.getClient();
const initSupported = clientHandler.clientSupportsCommand(`${client.commandPrefix}.terraform-ls.terraform.init`);
if (initSupported) {
const client = clientHandler.getClient();
const moduleUri = Utils.dirname(documentUri);
Expand All @@ -175,6 +176,7 @@ async function updateTerraformStatusBar(documentUri: vscode.Uri): Promise<void>
terraformStatus.show();
} else {
terraformStatus.hide();
terraformStatus.text = '';
}
} catch (err) {
vscode.window.showErrorMessage(err);
Expand Down
32 changes: 32 additions & 0 deletions src/test/integration/statusBar.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as assert from 'assert';
import * as vscode from 'vscode';
import { expect } from 'chai';
import { terraformStatus } from '../../extension';
import { getDocUri, open } from '../helper';
import { sleep } from '../../utils';

suite('statusBar', () => {
teardown(async () => {
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
});

test('should create a status bar item', () => {
assert.notStrictEqual(terraformStatus, undefined);
});

test('should create a status bar with the root module label', async () => {
const documentUri = getDocUri('sample.tf');
await open(documentUri);
await sleep(500);

expect(terraformStatus.text).to.equal('$(refresh) testFixture');
});

test('should create an empty status bar inside a child module', async () => {
const documentUri = getDocUri('modules/sample.tf');
await open(documentUri);
await sleep(500);

expect(terraformStatus.text).to.equal('');
});
});