Skip to content

Commit

Permalink
src/goTest: ensure that cursorOrPrevious always saves
Browse files Browse the repository at this point in the history
In the case of 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.

Followup to golang#1509

Change-Id: Ia5b625b4819727555fb20a1fb022200a2e4abd4e
GitHub-Last-Rev: 1ec414f
GitHub-Pull-Request: golang#1751
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/347789
Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
Trust: Hyang-Ah Hana Kim <[email protected]>
Trust: Suzy Mueller <[email protected]>
Run-TryBot: Hyang-Ah Hana Kim <[email protected]>
TryBot-Result: kokoro <[email protected]>
  • Loading branch information
mislav authored and suzmue committed Sep 22, 2021
1 parent 11afec4 commit 079e752
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 079e752

Please sign in to comment.