From 079e752253d3644733d4485bced84b823dfefd88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 22 Sep 2021 16:23:35 +0000 Subject: [PATCH] src/goTest: ensure that cursorOrPrevious always saves 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 https://github.com/golang/vscode-go/pull/1509 Change-Id: Ia5b625b4819727555fb20a1fb022200a2e4abd4e GitHub-Last-Rev: 1ec414f3cbe85c4f8dee28845303c04dd8f6423a GitHub-Pull-Request: golang/vscode-go#1751 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/347789 Reviewed-by: Hyang-Ah Hana Kim Trust: Hyang-Ah Hana Kim Trust: Suzy Mueller Run-TryBot: Hyang-Ah Hana Kim TryBot-Result: kokoro --- src/goTest.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/goTest.ts b/src/goTest.ts index 325c08c25b..748ff8c4da 100644 --- a/src/goTest.ts +++ b/src/goTest.ts @@ -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); } - }); + } } /**