Skip to content

Commit 837852b

Browse files
committed
[release] src/goPath: remove dependency on util that depends on vscode
golang.org/cl/239697 accidentally added the new dependency on util - to find the value of go.goroot, which broke the debug adapter that runs outside vscode. Made getBinPathWithPreferredGopath accept a preferredGoroot param, and renamed the function to reflect this change. We need to remove any dependency from src/debugAdapter to src to avoid a similar bug in the future. We need to have a test, using the built extension. Updates #137. Change-Id: I586438f1f391aaff0c0cdc806de1e9f3fd5deba9 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/240097 Reviewed-by: Rebecca Stambler <[email protected]> (cherry picked from commit b9d1bad) Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/240117
1 parent 865d3d9 commit 837852b

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

src/debugAdapter/goDebug.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { DebugProtocol } from 'vscode-debugprotocol';
3333
import {
3434
envPath,
3535
fixDriveCasingInWindows,
36-
getBinPathWithPreferredGopath,
36+
getBinPathWithPreferredGopathGoroot,
3737
getCurrentGoWorkspaceFromGOPATH,
3838
getInferredGopath,
3939
parseEnvFile
@@ -471,7 +471,7 @@ export class Delve {
471471
runArgs.push(...launchArgs.args);
472472
}
473473

474-
const goExe = getBinPathWithPreferredGopath('go', []);
474+
const goExe = getBinPathWithPreferredGopathGoroot('go', []);
475475
log(`Current working directory: ${dirname}`);
476476
log(`Running: ${goExe} ${runArgs.join(' ')}`);
477477

@@ -1934,7 +1934,7 @@ export class GoDebugSession extends LoggingDebugSession {
19341934
}
19351935
return new Promise((resolve) => {
19361936
execFile(
1937-
getBinPathWithPreferredGopath('go', []),
1937+
getBinPathWithPreferredGopathGoroot('go', []),
19381938
['list', '-f', '{{.Name}} {{.ImportPath}}'],
19391939
{ cwd: dir, env: this.delve.dlvEnv },
19401940
(err, stdout, stderr) => {
@@ -2335,7 +2335,7 @@ function killProcessTree(p: ChildProcess): Promise<void> {
23352335
function queryGOROOT(cwd: any, env: any): Promise<string> {
23362336
return new Promise<string>((resolve) => {
23372337
execFile(
2338-
getBinPathWithPreferredGopath('go', []),
2338+
getBinPathWithPreferredGopathGoroot('go', []),
23392339
['env', 'GOROOT'],
23402340
{ cwd, env },
23412341
(err, stdout, stderr) => {

src/goPath.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import fs = require('fs');
1313
import os = require('os');
1414
import path = require('path');
15-
import { getGoConfig } from './util';
1615

1716
let binPathCache: { [bin: string]: string } = {};
1817

@@ -32,9 +31,10 @@ export function getBinPathFromEnvVar(toolName: string, envVarValue: string, appe
3231
return null;
3332
}
3433

35-
export function getBinPathWithPreferredGopath(
34+
export function getBinPathWithPreferredGopathGoroot(
3635
toolName: string,
3736
preferredGopaths: string[],
37+
preferredGoroot?: string,
3838
alternateTool?: string,
3939
useCache = true,
4040
) {
@@ -67,7 +67,7 @@ export function getBinPathWithPreferredGopath(
6767
}
6868

6969
// Check GOROOT (go, gofmt, godoc would be found here)
70-
const pathFromGoRoot = getBinPathFromEnvVar(binname, getGoConfig().get('goroot') || getCurrentGoRoot(), true);
70+
const pathFromGoRoot = getBinPathFromEnvVar(binname, preferredGoroot || getCurrentGoRoot(), true);
7171
if (pathFromGoRoot) {
7272
binPathCache[toolName] = pathFromGoRoot;
7373
return pathFromGoRoot;

src/util.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { getCurrentPackage } from './goModules';
1919
import {
2020
envPath,
2121
fixDriveCasingInWindows,
22-
getBinPathWithPreferredGopath,
22+
getBinPathWithPreferredGopathGoroot,
2323
getCurrentGoRoot,
2424
getInferredGopath,
2525
resolveHomeDir,
@@ -436,12 +436,14 @@ function resolveToolsGopath(): string {
436436
}
437437

438438
export function getBinPath(tool: string, useCache = true): string {
439-
const alternateTools: { [key: string]: string } = getGoConfig().get('alternateTools');
439+
const cfg = getGoConfig();
440+
const alternateTools: { [key: string]: string } = cfg.get('alternateTools');
440441
const alternateToolPath: string = alternateTools[tool];
441442

442-
return getBinPathWithPreferredGopath(
443+
return getBinPathWithPreferredGopathGoroot(
443444
tool,
444445
tool === 'go' ? [] : [getToolsGopath(), getCurrentGoPath()],
446+
tool === 'go' && cfg.get('goroot') ? cfg.get('goroot') : undefined,
445447
resolvePath(alternateToolPath),
446448
useCache
447449
);

0 commit comments

Comments
 (0)