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 1 commit
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
15 changes: 13 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,14 +479,17 @@ export function activate(ctx: vscode.ExtensionContext): void {
vscode.window.showErrorMessage('Cannot apply coverage profile when no Go file is open.');
return;
}
const lastCoverProfilePathKey = '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: getFromWorkspaceState(lastCoverProfilePathKey, ''),
})
.then((coverProfilePath) => {
if (!coverProfilePath) {
return;
}
updateWorkspaceState(lastCoverProfilePathKey, coverProfilePath);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can skip updating the state if the same value was used

if (!fileExists(coverProfilePath)) {
vscode.window.showErrorMessage(`Cannot find the file ${coverProfilePath}`);
return;
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;
}