src/goModules.ts: fix test workspace in modules mode
testWorkspace may call isModSupported with the workspace URI,
which is already the root of the workspace or a module.
isModSupported unconditionally assumed the fileuril was a file
path, and worked on the parent of the workspace. That led
incorrect conclusion about modules mode, and broke tests in
various ways when modules should be enabled.
Change-Id: Ia7ba0d863e8d86f67fa27493d23ec3c686dd782e
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/242642
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
diff --git a/src/goModules.ts b/src/goModules.ts
index de41add..9406850 100644
--- a/src/goModules.ts
+++ b/src/goModules.ts
@@ -37,14 +37,14 @@
});
}
-export function isModSupported(fileuri: vscode.Uri): Promise<boolean> {
- return getModFolderPath(fileuri).then((modPath) => !!modPath);
+export function isModSupported(fileuri: vscode.Uri, isDir?: boolean): Promise<boolean> {
+ return getModFolderPath(fileuri, isDir).then((modPath) => !!modPath);
}
export const packagePathToGoModPathMap: { [key: string]: string } = {};
-export async function getModFolderPath(fileuri: vscode.Uri): Promise<string> {
- const pkgPath = path.dirname(fileuri.fsPath);
+export async function getModFolderPath(fileuri: vscode.Uri, isDir?: boolean): Promise<string> {
+ const pkgPath = isDir ? fileuri.fsPath : path.dirname(fileuri.fsPath);
if (packagePathToGoModPathMap[pkgPath]) {
return packagePathToGoModPathMap[pkgPath];
}
diff --git a/src/goTest.ts b/src/goTest.ts
index b25c78a..5b1576d 100644
--- a/src/goTest.ts
+++ b/src/goTest.ts
@@ -241,11 +241,13 @@
vscode.window.showInformationMessage('No workspace is open to run tests.');
return;
}
+ let workspaceUriIsDir = true;
let workspaceUri = vscode.workspace.workspaceFolders[0].uri;
if (
vscode.window.activeTextEditor &&
vscode.workspace.getWorkspaceFolder(vscode.window.activeTextEditor.document.uri)
) {
+ workspaceUriIsDir = false;
workspaceUri = vscode.workspace.getWorkspaceFolder(vscode.window.activeTextEditor.document.uri).uri;
}
@@ -258,7 +260,7 @@
// Remember this config as the last executed test.
lastTestConfig = testConfig;
- isModSupported(workspaceUri).then((isMod) => {
+ isModSupported(workspaceUri, workspaceUriIsDir).then((isMod) => {
testConfig.isMod = isMod;
goTest(testConfig).then(null, (err) => {
console.error(err);