Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

make file paths clickable in test output when using go modules #1975

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/goBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ export function goBuild(fileUri: vscode.Uri, isMod: boolean, goConfig: vscode.Wo
// Find the right importPath instead of directly using `.`. Fixes https://github.com/Microsoft/vscode-go/issues/846
let currentGoWorkspace = getCurrentGoWorkspaceFromGOPATH(getCurrentGoPath(), cwd);
let importPath = currentGoWorkspace ? cwd.substr(currentGoWorkspace.length + 1) : '.';
if (importPath === '') {
importPath = currentGoWorkspace;
}
running = true;
return runTool(
buildArgs.concat('-o', tmpPath, importPath),
Expand Down
13 changes: 13 additions & 0 deletions src/goPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,22 @@ export function getCurrentGoWorkspaceFromGOPATH(gopath: string, currentFileDirPa
}
}
}
// use current root if the package is using go modules outside of GOPATH
if (isGoModule(currentFileDirPath)) {
currentWorkspace = currentFileDirPath;
}
return currentWorkspace;
}

export function isGoModule(modulePath: string): Boolean {
try {
return fs.statSync(path.join(modulePath, 'go.mod')).isFile();
}
catch (e) {
return false;
}
}

// Workaround for issue in https://github.com/Microsoft/vscode/issues/9448#issuecomment-244804026
export function fixDriveCasingInWindows(pathToFix: string): string {
return (process.platform === 'win32' && pathToFix) ? pathToFix.substr(0, 1).toUpperCase() + pathToFix.substr(1) : pathToFix;
Expand Down
5 changes: 3 additions & 2 deletions src/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import cp = require('child_process');
import path = require('path');
import vscode = require('vscode');
import util = require('util');
import { parseEnvFile, getCurrentGoWorkspaceFromGOPATH } from './goPath';
import { parseEnvFile, getCurrentGoWorkspaceFromGOPATH, isGoModule } from './goPath';
import { getToolsEnvVars, getGoVersion, LineBuffer, SemVersion, resolvePath, getCurrentGoPath, getBinPath } from './util';
import { GoDocumentSymbolProvider } from './goOutline';
import { getNonVendorPackages } from './goPackages';
Expand Down Expand Up @@ -229,7 +229,8 @@ export function goTest(testconfig: TestConfig): Thenable<boolean> {
const result = line.match(packageResultLineRE);
if (result && currentGoWorkspace) {
const packageNameArr = result[2].split('/');
const baseDir = path.join(currentGoWorkspace, ...packageNameArr);

const baseDir = isGoModule(currentGoWorkspace) ? currentGoWorkspace : path.join(currentGoWorkspace, ...packageNameArr);
testResultLines.forEach(line => outputChannel.appendLine(expandFilePathInOutput(line, baseDir)));
testResultLines.splice(0);
}
Expand Down