Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 16 additions & 2 deletions src/goMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ import { GoRunTestCodeLensProvider } from './goRunTestCodelens';
import { showHideStatus } from './goStatus';
import { testAtCursor, testCurrentFile, testCurrentPackage, testPrevious, testWorkspace } from './goTest';
import { vetCode } from './goVet';
import { getFromGlobalState, setGlobalState, updateGlobalState } from './stateUtils';
import {
getFromGlobalState,
getFromWorkspaceState,
setGlobalState,
setWorkspaceState,
updateGlobalState,
updateWorkspaceState
} from './stateUtils';
import { disposeTelemetryReporter, sendTelemetryEventForConfig } from './telemetry';
import { cancelRunningTests, showTestOutput } from './testUtils';
import {
Expand All @@ -69,6 +76,7 @@ export let vetDiagnosticCollection: vscode.DiagnosticCollection;

export function activate(ctx: vscode.ExtensionContext): void {
setGlobalState(ctx.globalState);
setWorkspaceState(ctx.workspaceState);

updateGoPathGoRootFromConfig().then(async () => {
const updateToolsCmdText = 'Update tools';
Expand Down Expand Up @@ -471,9 +479,12 @@ export function activate(ctx: vscode.ExtensionContext): void {
vscode.window.showErrorMessage('Cannot apply coverage profile when no Go file is open.');
return;
}
const lastCoverProfilePathKey = 'lastCoverProfilePathKey';
const lastCoverProfilePath = getFromWorkspaceState(lastCoverProfilePathKey, '');
vscode.window
.showInputBox({
prompt: 'Enter the path to the coverage profile for current package'
prompt: 'Enter the path to the coverage profile for current package',
value: lastCoverProfilePath,
})
.then((coverProfilePath) => {
if (!coverProfilePath) {
Expand All @@ -483,6 +494,9 @@ export function activate(ctx: vscode.ExtensionContext): void {
vscode.window.showErrorMessage(`Cannot find the file ${coverProfilePath}`);
return;
}
if (coverProfilePath !== lastCoverProfilePath) {
updateWorkspaceState(lastCoverProfilePathKey, coverProfilePath);
}
applyCodeCoverageToAllEditors(
coverProfilePath,
path.dirname(vscode.window.activeTextEditor.document.fileName)
Expand Down
19 changes: 19 additions & 0 deletions src/stateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import vscode = require('vscode');

let globalState: vscode.Memento;
let workspaceState: vscode.Memento;

export function getFromGlobalState(key: string, defaultValue?: any) {
if (!globalState) {
Expand All @@ -24,3 +25,21 @@ export function updateGlobalState(key: string, value: any) {
export function setGlobalState(state: vscode.Memento) {
globalState = state;
}

export function getFromWorkspaceState(key: string, defaultValue?: any) {
if (!workspaceState) {
return defaultValue;
}
return workspaceState.get(key, defaultValue);
}

export function updateWorkspaceState(key: string, value: any) {
if (!workspaceState) {
return;
}
return workspaceState.update(key, value);
}

export function setWorkspaceState(state: vscode.Memento) {
workspaceState = state;
}