Skip to content

Commit 2ba9297

Browse files
suzmuehyangah
authored andcommitted
[release] src/goStatus: show Go status bar when the extension is enabled
We should be showing the Go status bar, even when there are no active text editors. Fixes #831 Change-Id: Ifb228b25f64ad41c7b63bdca27cf351768d8c4ce Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/265126 Trust: Suzy Mueller <suzmue@golang.org> Trust: Hyang-Ah Hana Kim <hyangah@gmail.com> Run-TryBot: Suzy Mueller <suzmue@golang.org> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com> (cherry picked from commit 5eaf73c) Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/266577 Reviewed-by: Suzy Mueller <suzmue@golang.org>
1 parent bb05e96 commit 2ba9297

File tree

3 files changed

+19
-40
lines changed

3 files changed

+19
-40
lines changed

src/goInstallTools.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { addGoRuntimeBaseToPATH, clearGoRuntimeBaseFromPATH } from './goEnvironm
1616
import { getLanguageServerToolPath } from './goLanguageServer';
1717
import { logVerbose } from './goLogging';
1818
import { restartLanguageServer } from './goMain';
19-
import { addGoStatus, initGoEnvStatusBar, outputChannel, removeGoStatus } from './goStatus';
19+
import { addGoStatus, initGoStatusBar, outputChannel, removeGoStatus } from './goStatus';
2020
import {
2121
containsTool,
2222
disableModulesForWildcard,
@@ -414,7 +414,7 @@ export function updateGoVarsFromConfig(): Promise<void> {
414414
// clear pre-existing terminal PATH mutation logic set up by this extension.
415415
clearGoRuntimeBaseFromPATH();
416416
}
417-
initGoEnvStatusBar();
417+
initGoStatusBar();
418418
// TODO: restart language server or synchronize with language server update.
419419

420420
return resolve();

src/goMain.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import { GO111MODULE, isModSupported } from './goModules';
4545
import { playgroundCommand } from './goPlayground';
4646
import { GoReferencesCodeLensProvider } from './goReferencesCodelens';
4747
import { GoRunTestCodeLensProvider } from './goRunTestCodelens';
48-
import { disposeGoStatusBar, expandGoStatusBar, outputChannel, showHideStatus } from './goStatus';
48+
import { disposeGoStatusBar, expandGoStatusBar, outputChannel, updateGoStatusBar } from './goStatus';
4949
import { subTestAtCursor, testAtCursor, testCurrentFile, testCurrentPackage, testPrevious, testWorkspace } from './goTest';
5050
import { getConfiguredTools } from './goTools';
5151
import { vetCode } from './goVet';
@@ -589,7 +589,7 @@ function addOnChangeTextDocumentListeners(ctx: vscode.ExtensionContext) {
589589
}
590590

591591
function addOnChangeActiveTextEditorListeners(ctx: vscode.ExtensionContext) {
592-
[showHideStatus, applyCodeCoverage].forEach((listener) => {
592+
[updateGoStatusBar, applyCodeCoverage].forEach((listener) => {
593593
// Call the listeners on initilization for current active text editor
594594
if (!!vscode.window.activeTextEditor) {
595595
listener(vscode.window.activeTextEditor);

src/goStatus.ts

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,18 @@ let statusBarEntry: vscode.StatusBarItem;
2525
let modulePath: string;
2626
export const languageServerIcon = '$(zap)';
2727

28-
export function showHideStatus(editor: vscode.TextEditor) {
29-
// Update the status bar entry
30-
if (!editor) {
31-
hideGoStatusBar();
32-
} else {
33-
showGoStatusBar();
34-
// Only update the module path if we are in a Go file.
35-
// This allows the user to open output windows without losing
36-
// the go.mod information in the status bar.
37-
if (isGoFile(editor.document)) {
38-
isModSupported(editor.document.uri).then((isMod) => {
39-
if (isMod) {
40-
getModFolderPath(editor.document.uri).then((p) => modulePath = p);
41-
} else {
42-
modulePath = '';
43-
}
44-
});
45-
}
28+
export function updateGoStatusBar(editor: vscode.TextEditor) {
29+
// Only update the module path if we are in a Go file.
30+
// This allows the user to open output windows without losing
31+
// the go.mod information in the status bar.
32+
if (!!editor && isGoFile(editor.document)) {
33+
isModSupported(editor.document.uri).then((isMod) => {
34+
if (isMod) {
35+
getModFolderPath(editor.document.uri).then((p) => modulePath = p);
36+
} else {
37+
modulePath = '';
38+
}
39+
});
4640
}
4741
}
4842

@@ -93,7 +87,7 @@ export async function expandGoStatusBar() {
9387
/**
9488
* Initialize the status bar item with current Go binary
9589
*/
96-
export async function initGoEnvStatusBar() {
90+
export async function initGoStatusBar() {
9791
if (!goEnvStatusbarItem) {
9892
goEnvStatusbarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 50);
9993
}
@@ -110,7 +104,7 @@ export async function initGoEnvStatusBar() {
110104
const cfg = buildLanguageServerConfig();
111105
updateLanguageServerIconGoStatusBar(true, cfg.serverName);
112106

113-
showHideStatus(vscode.window.activeTextEditor);
107+
showGoStatusBar();
114108
}
115109

116110
export async function updateLanguageServerIconGoStatusBar(started: boolean, server: string) {
@@ -150,21 +144,6 @@ export function showGoStatusBar() {
150144
if (!!goEnvStatusbarItem) {
151145
goEnvStatusbarItem.show();
152146
}
153-
if (!!statusBarEntry) {
154-
statusBarEntry.show();
155-
}
156-
}
157-
158-
/**
159-
* Hide the Go statusbar items on the statusbar
160-
*/
161-
export function hideGoStatusBar() {
162-
if (!!goEnvStatusbarItem) {
163-
goEnvStatusbarItem.hide();
164-
}
165-
if (!!statusBarEntry) {
166-
statusBarEntry.hide();
167-
}
168147
}
169148

170149
export function removeGoStatus() {
@@ -178,5 +157,5 @@ export function addGoStatus(message: string, command: string, tooltip?: string)
178157
statusBarEntry.text = `$(alert) ${message}`;
179158
statusBarEntry.command = command;
180159
statusBarEntry.tooltip = tooltip;
181-
showHideStatus(vscode.window.activeTextEditor);
160+
statusBarEntry.show();
182161
}

0 commit comments

Comments
 (0)