Skip to content

Commit

Permalink
src/goTools.ts: add dlv-dap to the configured tools
Browse files Browse the repository at this point in the history
dlv-dap needs to appear in the list of missing tools in order for
the user get the prompt to install.

Additionally, if they already have dlv-dap installed, we do want
dlv-dap to appear as a tool to update, since we are building from
master.

If the user has declined to install, do not attempt to prompt,
because it will do nothing. Instead, continue with the debugging
session without attempting to install so the error will show up
later.

Updates #794

Change-Id: If5922c950fde621d4c666e06bcc149413674ed9d
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/303235
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
  • Loading branch information
suzmue committed Mar 29, 2021
1 parent 8b97b4b commit 8d0bd24
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
15 changes: 11 additions & 4 deletions src/goDebugConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import path = require('path');
import vscode = require('vscode');
import { getGoConfig } from './config';
import { toolExecutionEnvironment } from './goEnv';
import { promptForMissingTool, promptForUpdatingTool, shouldUpdateTool } from './goInstallTools';
import { declinedToolInstall, promptForMissingTool, promptForUpdatingTool, shouldUpdateTool } from './goInstallTools';
import { packagePathToGoModPathMap } from './goModules';
import { getToolAtVersion } from './goTools';
import { getTool, getToolAtVersion } from './goTools';
import { pickProcess, pickProcessByName } from './pickProcess';
import { getFromGlobalState, updateGlobalState } from './stateUtils';
import { getBinPath, resolvePath } from './util';
Expand Down Expand Up @@ -233,8 +233,15 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
const debugAdapter = debugConfiguration['debugAdapter'] === 'dlv-dap' ? 'dlv-dap' : 'dlv';
const dlvToolPath = getBinPath(debugAdapter);
if (!path.isAbsolute(dlvToolPath)) {
await promptForMissingTool(debugAdapter);
return;
const tool = getTool(debugAdapter);

// If user has not already declined to install this tool,
// prompt for it. Otherwise continue and have the lack of
// dlv binary be caught later.
if (!declinedToolInstall(debugAdapter)) {
await promptForMissingTool(debugAdapter);
return;
}
}
debugConfiguration['dlvToolPath'] = dlvToolPath;

Expand Down
24 changes: 22 additions & 2 deletions src/goInstallTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,18 @@ export async function installTool(
return result;
}

export function declinedToolInstall(toolName: string) {
const tool = getTool(toolName);

// If user has declined to install this tool, don't prompt for it.
return !!containsTool(declinedInstalls, tool)
}

export async function promptForMissingTool(toolName: string) {
const tool = getTool(toolName);

// If user has declined to install this tool, don't prompt for it.
if (containsTool(declinedInstalls, tool)) {
if (declinedToolInstall(toolName)) {
return;
}

Expand Down Expand Up @@ -338,7 +345,9 @@ export async function promptForMissingTool(toolName: string) {
const installOptions = ['Install'];
let missing = await getMissingTools(goVersion);
if (!containsTool(missing, tool)) {
return;
// If this function has been called, we want to display the prompt whether
// it appears in missing or not.
missing.push(tool);
}
missing = missing.filter((x) => x === tool || tool.isImportant);
if (missing.length > 1) {
Expand Down Expand Up @@ -558,6 +567,17 @@ function getMissingTools(goVersion: GoVersion): Promise<Tool[]> {
(tool) =>
new Promise<Tool>((resolve, reject) => {
const toolPath = getBinPath(tool.name);
if (tool.name === 'dlv-dap') {
// Check if user already has dlv-dap binary.
// If so, it's likely the user may be interested in updating the tool,
// so we should mark it as important and return as a missing tool.
if (path.isAbsolute(toolPath)) {
tool.isImportant = true;
resolve(tool);
return;
}
tool.isImportant = false;
}
resolve(path.isAbsolute(toolPath) ? null : tool);
})
)
Expand Down
1 change: 1 addition & 0 deletions src/goTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export function getConfiguredTools(
// families are 64-bit, so just try to install it and hope for the best.
if (process.arch.match(/^(arm64|mips|mipsel|ppc64|s390|s390x|x64)$/)) {
maybeAddTool('dlv');
maybeAddTool('dlv-dap');
}

// gocode-gomod needed in go 1.11 & higher
Expand Down

0 comments on commit 8d0bd24

Please sign in to comment.