Skip to content

Commit

Permalink
Ensure that cursorOrPrevious always saves
Browse files Browse the repository at this point in the history
In the case of `go.test.cursorOrPrevious` command not finding a Go test
under the cursor, it will call `go.test.previous`. However,
`cursorOrPrevious` automatically saves when there was a test found, but
`previous` does not. This can lead to the user being surprised as to why
doesn't `cursorOrPrevious` always save.
  • Loading branch information
mislav committed Sep 22, 2021
1 parent bf9a5a1 commit 1ec414f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/goTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,20 @@ export function testAtCursor(goConfig: vscode.WorkspaceConfiguration, cmd: TestA
* @param cmd Whether the command is test, benchmark, or debug.
* @param args
*/
export function testAtCursorOrPrevious(goConfig: vscode.WorkspaceConfiguration, cmd: TestAtCursorCmd, args: any) {
_testAtCursor(goConfig, cmd, args).catch((err) => {
export async function testAtCursorOrPrevious(goConfig: vscode.WorkspaceConfiguration, cmd: TestAtCursorCmd, args: any) {
try {
await _testAtCursor(goConfig, cmd, args);
} catch (err) {
if (err instanceof NotFoundError) {
testPrevious();
const editor = vscode.window.activeTextEditor;
if (editor) {
await editor.document.save();
}
await testPrevious();
} else {
console.error(err);
}
});
}
}

/**
Expand Down

0 comments on commit 1ec414f

Please sign in to comment.