Skip to content

Commit 1ec414f

Browse files
committed
Ensure that cursorOrPrevious always saves
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.
1 parent bf9a5a1 commit 1ec414f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/goTest.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,20 @@ export function testAtCursor(goConfig: vscode.WorkspaceConfiguration, cmd: TestA
8888
* @param cmd Whether the command is test, benchmark, or debug.
8989
* @param args
9090
*/
91-
export function testAtCursorOrPrevious(goConfig: vscode.WorkspaceConfiguration, cmd: TestAtCursorCmd, args: any) {
92-
_testAtCursor(goConfig, cmd, args).catch((err) => {
91+
export async function testAtCursorOrPrevious(goConfig: vscode.WorkspaceConfiguration, cmd: TestAtCursorCmd, args: any) {
92+
try {
93+
await _testAtCursor(goConfig, cmd, args);
94+
} catch (err) {
9395
if (err instanceof NotFoundError) {
94-
testPrevious();
96+
const editor = vscode.window.activeTextEditor;
97+
if (editor) {
98+
await editor.document.save();
99+
}
100+
await testPrevious();
95101
} else {
96102
console.error(err);
97103
}
98-
});
104+
}
99105
}
100106

101107
/**

0 commit comments

Comments
 (0)