Skip to content

Commit c132833

Browse files
committed
src/goDebugConfiguration: use 'dlv' instead of 'dlv-dap' binary
The stable version of dlv includes all the features Delve DAP mode debug setup requires. We do not need to depend on Delve built from the master or newer than the stable version. Use 'dlv' instead of 'dlv-dap', and remove 'dlv-dap' binary installation/update logic. The extension presents a warning to the users who configured `go.alternateTools.dlv-dap` and offers an option to open the corresponding settings.json. Fixes #1977 Change-Id: I5ed398c4d85594a6ad26bea4874324a75f96badb Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/374594 Trust: Hyang-Ah Hana Kim <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> Reviewed-by: Polina Sokolova <[email protected]>
1 parent 094f345 commit c132833

12 files changed

+96
-139
lines changed

docs/debugging.md

+33-32
Large diffs are not rendered by default.

src/goDebugConfiguration.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -263,34 +263,34 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
263263
}
264264
}
265265

266-
const dlvToolPath = getBinPath(debugAdapter);
266+
const dlvToolPath = getBinPath('dlv');
267267
if (!path.isAbsolute(dlvToolPath)) {
268268
// If user has not already declined to install this tool,
269269
// prompt for it. Otherwise continue and have the lack of
270270
// dlv binary be caught later.
271-
if (!declinedToolInstall(debugAdapter)) {
272-
await promptForMissingTool(debugAdapter);
271+
if (!declinedToolInstall('dlv')) {
272+
await promptForMissingTool('dlv');
273273
return;
274274
}
275275
}
276276
debugConfiguration['dlvToolPath'] = dlvToolPath;
277277

278+
// For dlv-dap mode, check if the dlv is recent enough to support DAP.
278279
if (debugAdapter === 'dlv-dap' && !dlvDAPVersionChecked) {
279-
const tool = getToolAtVersion('dlv-dap');
280+
const tool = getToolAtVersion('dlv');
280281
if (await shouldUpdateTool(tool, dlvToolPath)) {
281282
// If the user has opted in to automatic tool updates, we can update
282283
// without prompting.
283284
const toolsManagementConfig = getGoConfig()['toolsManagement'];
284285
if (toolsManagementConfig && toolsManagementConfig['autoUpdate'] === true) {
285286
const goVersion = await getGoVersion();
286-
const toolVersion = { ...tool, version: tool.latestVersion }; // ToolWithVersion
287-
await installTools([toolVersion], goVersion, true);
287+
await installTools([tool], goVersion, true);
288288
} else {
289289
await promptForUpdatingTool(tool.name);
290290
}
291-
// installTools could've failed (e.g. no network access) or the user decliend to install dlv-dap
292-
// in promptForUpdatingTool. If dlv-dap doesn't exist or dlv-dap is too old to have MVP features,
293-
// the failure will be visible to users when launching the dlv-dap process (crash or error message).
291+
// installTools could've failed (e.g. no network access) or the user decliend to install dlv
292+
// in promptForUpdatingTool. If dlv doesn't exist or dlv is too old to have MVP features,
293+
// the failure will be visible to users when launching the dlv process (crash or error message).
294294
}
295295
dlvDAPVersionChecked = true;
296296
}

src/goDebugFactory.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import getPort = require('get-port');
1212
import path = require('path');
1313
import * as fs from 'fs';
1414
import * as net from 'net';
15-
import { getTool } from './goTools';
1615
import { Logger, logVerbose, TimestampedLogger } from './goLogging';
1716
import { DebugProtocol } from 'vscode-debugprotocol';
1817
import { getWorkspaceFolderPath } from './util';
@@ -578,12 +577,12 @@ function getSpawnConfig(launchAttachArgs: vscode.DebugConfiguration, logErr: (ms
578577
// launchArgsEnv is user-requested env vars (envFiles + env).
579578
const env = Object.assign(goToolsEnvVars, launchArgsEnv);
580579

581-
const dlvPath = launchAttachArgs.dlvToolPath ?? getTool('dlv-dap');
580+
const dlvPath = launchAttachArgs.dlvToolPath ?? 'dlv';
582581

583582
if (!fs.existsSync(dlvPath)) {
584583
const envPath = process.env['PATH'] || (process.platform === 'win32' ? process.env['Path'] : null);
585584
logErr(
586-
`Couldn't find dlv-dap at the Go tools path, ${process.env['GOPATH']}${
585+
`Couldn't find ${dlvPath} at the Go tools path, ${process.env['GOPATH']}${
587586
env['GOPATH'] ? ', ' + env['GOPATH'] : ''
588587
} or ${envPath}\n` +
589588
'Follow the setup instruction in https://github.com/golang/vscode-go/blob/master/docs/debugging.md#getting-started.\n'

src/goInstallTools.ts

+13-14
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export async function installTool(
235235
}
236236

237237
try {
238-
if (!modulesOn || goVersion.lt('1.16') || hasModSuffix(tool) || tool.name === 'dlv-dap') {
238+
if (!modulesOn || goVersion.lt('1.16') || hasModSuffix(tool)) {
239239
await installToolWithGoGet(tool, goVersion, env, modulesOn, importPath);
240240
} else {
241241
await installToolWithGoInstall(goVersion, env, importPath);
@@ -284,9 +284,9 @@ async function installToolWithGoGet(
284284
if (!modulesOn) {
285285
args.push('-u');
286286
}
287-
// dlv-dap or tools with a "mod" suffix can't be installed with
287+
// tools with a "mod" suffix can't be installed with
288288
// simple `go install` or `go get`. We need to get, build, and rename them.
289-
if (hasModSuffix(tool) || tool.name === 'dlv-dap') {
289+
if (hasModSuffix(tool)) {
290290
args.push('-d'); // get the version, but don't build.
291291
}
292292
args.push(importPath);
@@ -307,8 +307,8 @@ async function installToolWithGoGet(
307307
logVerbose(`$ ${goBinary} ${args.join(' ')} (cwd: ${opts.cwd})`);
308308
await execFile(goBinary, args, opts);
309309

310-
if (hasModSuffix(tool) || tool.name === 'dlv-dap') {
311-
// Actual installation of the -gomod tool and dlv-dap is done by running go build.
310+
if (hasModSuffix(tool)) {
311+
// Actual installation of the -gomod tool is done by running go build.
312312
let destDir = env['GOBIN'];
313313
if (!destDir) {
314314
const gopath0 = env['GOPATH']?.split(path.delimiter)[0];
@@ -383,14 +383,13 @@ export async function promptForMissingTool(toolName: string) {
383383
// Offer the option to install all tools.
384384
installOptions.push('Install All');
385385
}
386-
let msg = `The "${tool.name}" command is not available.
387-
Run "go get -v ${getImportPath(tool, goVersion)}" to install.`;
388-
if (tool.name === 'dlv-dap') {
389-
msg = `The ["${tool.name}"](https://github.com/golang/vscode-go/blob/master/docs/debugging.md) command is not available.
390-
Please select "Install", or follow the installation instructions [here](https://github.com/golang/vscode-go/blob/master/docs/debugging.md#updating-dlv-dap).`;
391-
}
392-
393-
const selected = await vscode.window.showErrorMessage(msg, ...installOptions);
386+
const cmd = goVersion.lt('1.16')
387+
? `go get -v ${getImportPath(tool, goVersion)}`
388+
: `go install -v ${getImportPathWithVersion(tool, tool.defaultVersion, goVersion)}`;
389+
const selected = await vscode.window.showErrorMessage(
390+
`The "${tool.name}" command is not available. Run "${cmd}" to install.`,
391+
...installOptions
392+
);
394393
switch (selected) {
395394
case 'Install':
396395
await installTools([tool], goVersion);
@@ -436,7 +435,7 @@ export async function promptForUpdatingTool(
436435
if (toolName === 'gopls') {
437436
choices = ['Always Update', 'Update Once', 'Release Notes'];
438437
}
439-
if (toolName === 'dlv-dap') {
438+
if (toolName === 'dlv') {
440439
choices = ['Always Update', 'Update Once'];
441440
}
442441

src/goMain.ts

+24
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ If you would like additional configuration for diagnostics from gopls, please se
188188
}
189189
}
190190
}
191+
192+
// Present a warning about the deprecation of a 'dlv-dap' binary setting.
193+
checkAlternateTools(cfg);
194+
191195
updateGoVarsFromConfig().then(async () => {
192196
suggestUpdates(ctx);
193197
offerToInstallLatestGoVersion();
@@ -1030,3 +1034,23 @@ export async function setGOROOTEnvVar(configGOROOT: string) {
10301034
delete process.env.GOROOT;
10311035
}
10321036
}
1037+
1038+
async function checkAlternateTools(goConfig: vscode.WorkspaceConfiguration) {
1039+
const alternateTools = goConfig ? goConfig['alternateTools'] : {};
1040+
// TODO(hyangah): delete this check after 2022-03-01.
1041+
if (alternateTools['dlv-dap']) {
1042+
const msg = `The extension no longer requires a separate 'dlv-dap' binary but uses the 'dlv' binary.
1043+
The "dlv-dap" property of the "go.alternateTools" setting will be ignored.
1044+
Please use the "dlv" property if you need to override the default Go debugger.`;
1045+
1046+
const selected = await vscode.window.showWarningMessage(msg, 'Open settings.json');
1047+
if (selected === 'Open settings.json') {
1048+
const { workspaceValue } = goConfig.inspect('alternateTools.dlv-dap');
1049+
if (workspaceValue !== undefined) {
1050+
vscode.commands.executeCommand('workbench.action.openWorkspaceSettingsFile');
1051+
} else {
1052+
vscode.commands.executeCommand('workbench.action.openSettingsJson');
1053+
}
1054+
}
1055+
}
1056+
}

src/goTools.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,8 @@ export function getConfiguredTools(
157157
// Check if the system supports dlv, i.e. is 64-bit.
158158
// There doesn't seem to be a good way to check if the mips and s390
159159
// families are 64-bit, so just try to install it and hope for the best.
160-
if (process.arch.match(/^(arm64|mips|mipsel|ppc64|s390|s390x|x64)$/)) {
160+
if (process.arch.match(/^(mips|mipsel|ppc64|s390|s390x|x64)$/)) {
161161
maybeAddTool('dlv');
162-
maybeAddTool('dlv-dap');
163162
}
164163

165164
// gocode-gomod needed in go 1.11 & higher

src/goToolsInformation.ts

+6-16
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,10 @@ export const allToolsInformation: { [key: string]: Tool } = {
203203
description: 'Language Server from Google',
204204
usePrereleaseInPreviewMode: true,
205205
minimumGoVersion: semver.coerce('1.12'),
206-
latestVersion: semver.parse('v0.7.1'),
207-
latestVersionTimestamp: moment('2021-08-02', 'YYYY-MM-DD'),
208-
latestPrereleaseVersion: semver.parse('v0.7.1'),
209-
latestPrereleaseVersionTimestamp: moment('2021-08-02', 'YYYY-MM-DD')
206+
latestVersion: semver.parse('v0.7.4'),
207+
latestVersionTimestamp: moment('2021-12-09', 'YYYY-MM-DD'),
208+
latestPrereleaseVersion: semver.parse('v0.7.4'),
209+
latestPrereleaseVersionTimestamp: moment('2021-12-09', 'YYYY-MM-DD')
210210
},
211211
'dlv': {
212212
name: 'dlv',
@@ -215,20 +215,10 @@ export const allToolsInformation: { [key: string]: Tool } = {
215215
replacedByGopls: false,
216216
isImportant: true,
217217
description: 'Go debugger (Delve)',
218+
latestVersion: semver.parse('v1.6.1'), // minimum version that supports DAP
219+
latestVersionTimestamp: moment('2021-05-19', 'YYYY-MM-DD'),
218220
minimumGoVersion: semver.coerce('1.12') // dlv requires 1.12+ for build
219221
},
220-
'dlv-dap': {
221-
name: 'dlv-dap',
222-
importPath: 'github.com/go-delve/delve/cmd/dlv',
223-
modulePath: 'github.com/go-delve/delve',
224-
replacedByGopls: false,
225-
isImportant: true,
226-
description: 'Go debugger & debug adapter (Delve DAP)',
227-
defaultVersion: '2f13672765fe', // pinned version
228-
minimumGoVersion: semver.coerce('1.12'), // dlv requires 1.12+ for build
229-
latestVersion: semver.parse('v1.7.3-0.20211026171155-b48ceec161d5'),
230-
latestVersionTimestamp: moment('2021-10-26', 'YYYY-MM-DD')
231-
},
232222
'fillstruct': {
233223
name: 'fillstruct',
234224
importPath: 'github.com/davidrjenni/reftools/cmd/fillstruct',

test/gopls/update.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ suite('gopls update tests', () => {
188188
});
189189

190190
suite('version comparison', () => {
191-
const tool = getTool('dlv-dap');
191+
const tool = getTool('dlv');
192192
const latestVersion = tool.latestVersion;
193193

194194
teardown(() => {
@@ -197,7 +197,7 @@ suite('version comparison', () => {
197197

198198
async function testShouldUpdateTool(expected: boolean, moduleVersion?: string) {
199199
sinon.stub(goInstallTools, 'inspectGoToolVersion').returns(Promise.resolve({ moduleVersion }));
200-
const got = await goInstallTools.shouldUpdateTool(tool, '/bin/path/to/dlv-dap');
200+
const got = await goInstallTools.shouldUpdateTool(tool, '/bin/path/to/dlv');
201201
assert.strictEqual(
202202
expected,
203203
got,

test/integration/install.test.ts

+3-13
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,7 @@ suite('Installation Tests', function () {
157157
await runTest(
158158
[
159159
{ name: 'gopls', versions: ['v0.1.0', 'v1.0.0-pre.1', 'v1.0.0'], wantVersion: 'v1.0.0' },
160-
{ name: 'guru', versions: ['v1.0.0'], wantVersion: 'v1.0.0' },
161-
{
162-
name: 'dlv-dap',
163-
versions: ['v1.0.0', getTool('dlv-dap').defaultVersion!],
164-
wantVersion: 'v' + getTool('dlv-dap').latestVersion!.toString()
165-
}
160+
{ name: 'dlv', versions: ['v1.0.0', 'v1.8.0'], wantVersion: 'v1.8.0' }
166161
],
167162
true
168163
);
@@ -172,12 +167,7 @@ suite('Installation Tests', function () {
172167
await runTest(
173168
[
174169
{ name: 'gopls', versions: ['v0.1.0', 'v1.0.0-pre.1', 'v1.0.0'], wantVersion: 'v1.0.0' },
175-
{ name: 'guru', versions: ['v1.0.0'], wantVersion: 'v1.0.0' },
176-
{
177-
name: 'dlv-dap',
178-
versions: ['v1.0.0', getTool('dlv-dap').defaultVersion!],
179-
wantVersion: 'v' + getTool('dlv-dap').latestVersion!.toString()
180-
}
170+
{ name: 'dlv', versions: ['v1.0.0', 'v1.8.0'], wantVersion: 'v1.8.0' }
181171
],
182172
true, // LOCAL PROXY
183173
true // GOBIN
@@ -214,7 +204,7 @@ function buildFakeProxy(testCases: installationTestCase[]) {
214204

215205
versions.map((version) => {
216206
if (!version.match(/^v\d+\.\d+\.\d+/)) {
217-
// for dlv-dap that retrieves the version from a revision (commit hash)
207+
// for tools that retrieve the versions from a revision (commit hash)
218208
const resolvedVersion = tool.latestVersion?.toString() || '1.0.0';
219209
const infoPath = path.join(dir, `${version}.info`);
220210
version = `v${resolvedVersion}`;

tools/allTools.ts.in

+2-12
Original file line numberDiff line numberDiff line change
@@ -213,20 +213,10 @@ export const allToolsInformation: { [key: string]: Tool } = {
213213
replacedByGopls: false,
214214
isImportant: true,
215215
description: 'Go debugger (Delve)',
216+
latestVersion: semver.parse('v1.6.1'), // minimum version that supports DAP
217+
latestVersionTimestamp: moment('2021-05-19', 'YYYY-MM-DD'),
216218
minimumGoVersion: semver.coerce('1.12') // dlv requires 1.12+ for build
217219
},
218-
'dlv-dap': {
219-
name: 'dlv-dap',
220-
importPath: 'github.com/go-delve/delve/cmd/dlv',
221-
modulePath: 'github.com/go-delve/delve',
222-
replacedByGopls: false,
223-
isImportant: true,
224-
description: 'Go debugger & debug adapter (Delve DAP)',
225-
defaultVersion: '%s', // pinned version
226-
minimumGoVersion: semver.coerce('1.12'), // dlv requires 1.12+ for build
227-
latestVersion: semver.parse('%s'),
228-
latestVersionTimestamp: moment('%s', 'YYYY-MM-DD')
229-
},
230220
'fillstruct': {
231221
name: 'fillstruct',
232222
importPath: 'github.com/davidrjenni/reftools/cmd/fillstruct',

tools/generate.go

+1-31
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ package main
1515
import (
1616
"bytes"
1717
"encoding/json"
18-
"errors"
1918
"flag"
2019
"fmt"
2120
"io"
@@ -24,7 +23,6 @@ import (
2423
"os"
2524
"os/exec"
2625
"path/filepath"
27-
"regexp"
2826
"sort"
2927
"strings"
3028

@@ -232,18 +230,6 @@ func main() {
232230
// Clear so that we can rewrite src/goToolsInformation.ts.
233231
b.Reset()
234232

235-
// Check for latest dlv-dap version.
236-
dlvVersion, err := listModuleVersion("github.com/go-delve/delve@master")
237-
if err != nil {
238-
log.Fatal(err)
239-
}
240-
// Due to https://github.com/golang/vscode-go/issues/1682, we cannot use
241-
// pseudo-version as the pinned version reliably.
242-
dlvRevOrStable := dlvVersion.Version
243-
if rev, err := pseudoVersionRev(dlvVersion.Version); err == nil { // pseudo-version
244-
dlvRevOrStable = rev
245-
}
246-
247233
// Check for the latest gopls version.
248234
versions, err := listAllModuleVersions("golang.org/x/tools/gopls")
249235
if err != nil {
@@ -277,7 +263,7 @@ func main() {
277263
}
278264

279265
// TODO(suzmue): change input to json and avoid magic string printing.
280-
toolsString := fmt.Sprintf(string(data), goplsVersion.Version, goplsVersion.Time[:len("YYYY-MM-DD")], goplsVersionPre.Version, goplsVersionPre.Time[:len("YYYY-MM-DD")], dlvRevOrStable, dlvVersion.Version, dlvVersion.Time[:len("YYYY-MM-DD")])
266+
toolsString := fmt.Sprintf(string(data), goplsVersion.Version, goplsVersion.Time[:len("YYYY-MM-DD")], goplsVersionPre.Version, goplsVersionPre.Time[:len("YYYY-MM-DD")])
281267

282268
// Write tools section.
283269
b.WriteString(toolsString)
@@ -693,19 +679,3 @@ func describeDebugProperty(p *Property) string {
693679
}
694680
return b.String()
695681
}
696-
697-
// pseudoVersionRev extracts the revision info if the given version is pseudo version.
698-
// We wanted to use golang.org/x/mod/module.PseudoVersionRev, but couldn't due to
699-
// an error in the CI. This is a workaround.
700-
//
701-
// It assumes the version string came from the proxy, so a valid, canonical version
702-
// string. Thus, the check for pseudoversion is not as robust as golang.org/x/mod/module
703-
// offers.
704-
func pseudoVersionRev(ver string) (rev string, _ error) {
705-
var pseudoVersionRE = regexp.MustCompile(`^v[0-9]+\.(0\.0-|\d+\.\d+-([^+]*\.)?0\.)\d{14}-[A-Za-z0-9]+(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$`)
706-
if strings.Count(ver, "-") < 2 || !pseudoVersionRE.MatchString(ver) {
707-
return "", errors.New("not a pseudo version")
708-
}
709-
j := strings.LastIndex(ver, "-")
710-
return ver[j+1:], nil
711-
}

tools/installtools/main.go

-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ var tools = []struct {
3131
{"github.com/zmb3/gogetdoc", "", ""},
3232
{"honnef.co/go/tools/cmd/staticcheck", "", ""},
3333
{"golang.org/x/tools/cmd/gorename", "", ""},
34-
{"github.com/go-delve/delve/cmd/dlv", "master", "dlv-dap"},
3534
{"github.com/go-delve/delve/cmd/dlv", "", ""},
3635
}
3736

@@ -140,7 +139,3 @@ func binName(toolPath string) string {
140139
}
141140
return b
142141
}
143-
144-
func runWithGoInstall() error {
145-
return nil
146-
}

0 commit comments

Comments
 (0)