|
10 | 10 | import { lstatSync } from 'fs';
|
11 | 11 | import path = require('path');
|
12 | 12 | import vscode = require('vscode');
|
| 13 | +import semver = require('semver'); |
13 | 14 | import { extensionId } from './const';
|
14 | 15 | import { getGoConfig } from './config';
|
15 | 16 | import { toolExecutionEnvironment } from './goEnv';
|
16 | 17 | import {
|
17 | 18 | declinedToolInstall,
|
| 19 | + inspectGoToolVersion, |
18 | 20 | installTools,
|
19 | 21 | promptForMissingTool,
|
20 | 22 | promptForUpdatingTool,
|
@@ -47,8 +49,8 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
|
47 | 49 | constructor(private defaultDebugAdapterType: string = 'go') {}
|
48 | 50 |
|
49 | 51 | public async provideDebugConfigurations(
|
50 |
| - folder: vscode.WorkspaceFolder | undefined, |
51 |
| - token?: vscode.CancellationToken |
| 52 | + _folder: vscode.WorkspaceFolder | undefined, |
| 53 | + _token?: vscode.CancellationToken |
52 | 54 | ): Promise<vscode.DebugConfiguration[] | undefined> {
|
53 | 55 | return await this.pickConfiguration();
|
54 | 56 | }
|
@@ -132,7 +134,7 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
|
132 | 134 | public async resolveDebugConfiguration(
|
133 | 135 | folder: vscode.WorkspaceFolder | undefined,
|
134 | 136 | debugConfiguration: vscode.DebugConfiguration,
|
135 |
| - token?: vscode.CancellationToken |
| 137 | + _token?: vscode.CancellationToken |
136 | 138 | ): Promise<vscode.DebugConfiguration | undefined> {
|
137 | 139 | const activeEditor = vscode.window.activeTextEditor;
|
138 | 140 | if (!debugConfiguration || !debugConfiguration.request) {
|
@@ -261,40 +263,45 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
|
261 | 263 | debugConfiguration['cwd'] = resolveHomeDir(debugConfiguration['cwd']);
|
262 | 264 | }
|
263 | 265 |
|
| 266 | + const dlvToolPath = getBinPath('dlv'); |
| 267 | + if (!path.isAbsolute(dlvToolPath)) { |
| 268 | + // If user has not already declined to install this tool, |
| 269 | + // prompt for it. Otherwise continue and have the lack of |
| 270 | + // dlv binary be caught later. |
| 271 | + if (!declinedToolInstall('dlv')) { |
| 272 | + await promptForMissingTool('dlv'); |
| 273 | + return; |
| 274 | + } |
| 275 | + } |
| 276 | + debugConfiguration['dlvToolPath'] = dlvToolPath; |
| 277 | + |
264 | 278 | // Remove any '--gcflags' entries and show a warning
|
265 | 279 | if (debugConfiguration['buildFlags']) {
|
266 |
| - const resp = this.removeGcflags(debugConfiguration['buildFlags']); |
267 |
| - if (resp.removed) { |
268 |
| - debugConfiguration['buildFlags'] = resp.args; |
269 |
| - this.showWarning( |
270 |
| - 'ignoreDebugGCFlagsWarning', |
271 |
| - "User specified build flag '--gcflags' in 'buildFlags' is being ignored (see [debugging with build flags](https://github.com/golang/vscode-go/blob/master/docs/debugging.md#specifying-other-build-flags) documentation)" |
272 |
| - ); |
| 280 | + let flags = await maybeJoinFlags(dlvToolPath, debugConfiguration['buildFlags']); |
| 281 | + if (typeof flags === 'string') { |
| 282 | + const resp = this.removeGcflags(flags); |
| 283 | + if (resp.removed) { |
| 284 | + flags = resp.args; |
| 285 | + this.showWarning( |
| 286 | + 'ignoreDebugGCFlagsWarning', |
| 287 | + "User specified build flag '-gcflags' in 'buildFlags' is being ignored (see [debugging with build flags](https://github.com/golang/vscode-go/blob/master/docs/debugging.md#specifying-other-build-flags) documentation)" |
| 288 | + ); |
| 289 | + } |
273 | 290 | }
|
| 291 | + |
| 292 | + debugConfiguration['buildFlags'] = flags; |
274 | 293 | }
|
275 | 294 | if (debugConfiguration['env'] && debugConfiguration['env']['GOFLAGS']) {
|
276 | 295 | const resp = this.removeGcflags(debugConfiguration['env']['GOFLAGS']);
|
277 | 296 | if (resp.removed) {
|
278 | 297 | debugConfiguration['env']['GOFLAGS'] = resp.args;
|
279 | 298 | this.showWarning(
|
280 | 299 | 'ignoreDebugGCFlagsWarning',
|
281 |
| - "User specified build flag '--gcflags' in 'GOFLAGS' is being ignored (see [debugging with build flags](https://github.com/golang/vscode-go/blob/master/docs/debugging.md#specifying-other-build-flags) documentation)" |
| 300 | + "User specified build flag '-gcflags' in 'GOFLAGS' is being ignored (see [debugging with build flags](https://github.com/golang/vscode-go/blob/master/docs/debugging.md#specifying-other-build-flags) documentation)" |
282 | 301 | );
|
283 | 302 | }
|
284 | 303 | }
|
285 | 304 |
|
286 |
| - const dlvToolPath = getBinPath('dlv'); |
287 |
| - if (!path.isAbsolute(dlvToolPath)) { |
288 |
| - // If user has not already declined to install this tool, |
289 |
| - // prompt for it. Otherwise continue and have the lack of |
290 |
| - // dlv binary be caught later. |
291 |
| - if (!declinedToolInstall('dlv')) { |
292 |
| - await promptForMissingTool('dlv'); |
293 |
| - return; |
294 |
| - } |
295 |
| - } |
296 |
| - debugConfiguration['dlvToolPath'] = dlvToolPath; |
297 |
| - |
298 | 305 | // For dlv-dap mode, check if the dlv is recent enough to support DAP.
|
299 | 306 | if (debugAdapter === 'dlv-dap' && !dlvDAPVersionChecked) {
|
300 | 307 | const tool = getToolAtVersion('dlv');
|
@@ -405,7 +412,7 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
|
405 | 412 | public resolveDebugConfigurationWithSubstitutedVariables(
|
406 | 413 | folder: vscode.WorkspaceFolder | undefined,
|
407 | 414 | debugConfiguration: vscode.DebugConfiguration,
|
408 |
| - token?: vscode.CancellationToken |
| 415 | + _token?: vscode.CancellationToken |
409 | 416 | ): vscode.DebugConfiguration | null {
|
410 | 417 | const debugAdapter = debugConfiguration['debugAdapter'];
|
411 | 418 | if (debugAdapter === '') {
|
@@ -517,6 +524,16 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
|
517 | 524 | }
|
518 | 525 | }
|
519 | 526 |
|
| 527 | +// exported for testing. |
| 528 | +export async function maybeJoinFlags(dlvToolPath: string, flags: string | string[]) { |
| 529 | + const { moduleVersion } = await inspectGoToolVersion(dlvToolPath); |
| 530 | + const localVersion = semver.parse(moduleVersion, { includePrerelease: true }); |
| 531 | + if (typeof flags !== 'string' && (!localVersion || semver.lt(localVersion, '1.22.2'))) { |
| 532 | + flags = flags.join(' '); |
| 533 | + } |
| 534 | + return flags; |
| 535 | +} |
| 536 | + |
520 | 537 | // parseDebugProgramArgSync parses program arg of debug/auto/test launch requests.
|
521 | 538 | export function parseDebugProgramArgSync(
|
522 | 539 | program: string
|
|
0 commit comments