This repository has been archived by the owner on Jul 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 645
/
goDebugConfiguration.ts
146 lines (130 loc) · 4.86 KB
/
goDebugConfiguration.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------*/
'use strict';
import path = require('path');
import vscode = require('vscode');
import { promptForMissingTool } from './goInstallTools';
import { packagePathToGoModPathMap } from './goModules';
import { getFromGlobalState, updateGlobalState } from './stateUtils';
import { sendTelemetryEventForDebugConfiguration } from './telemetry';
import { getBinPath, getCurrentGoPath, getGoConfig, getToolsEnvVars } from './util';
export class GoDebugConfigurationProvider implements vscode.DebugConfigurationProvider {
public provideDebugConfigurations(
folder: vscode.WorkspaceFolder | undefined,
token?: vscode.CancellationToken
): vscode.DebugConfiguration[] {
return [
{
name: 'Launch',
type: 'go',
request: 'launch',
mode: 'auto',
program: '${fileDirname}',
env: {},
args: []
}
];
}
public resolveDebugConfiguration?(
folder: vscode.WorkspaceFolder | undefined,
debugConfiguration: vscode.DebugConfiguration,
token?: vscode.CancellationToken
): vscode.DebugConfiguration {
if (debugConfiguration) {
sendTelemetryEventForDebugConfiguration(debugConfiguration);
}
const activeEditor = vscode.window.activeTextEditor;
if (!debugConfiguration || !debugConfiguration.request) {
// if 'request' is missing interpret this as a missing launch.json
if (!activeEditor || activeEditor.document.languageId !== 'go') {
return;
}
debugConfiguration = Object.assign(debugConfiguration || {}, {
name: 'Launch',
type: 'go',
request: 'launch',
mode: 'auto',
program: path.dirname(activeEditor.document.fileName) // matches ${fileDirname}
});
}
debugConfiguration['packagePathToGoModPathMap'] = packagePathToGoModPathMap;
const gopath = getCurrentGoPath(folder ? folder.uri : undefined);
if (!debugConfiguration['env']) {
debugConfiguration['env'] = { GOPATH: gopath };
} else if (!debugConfiguration['env']['GOPATH']) {
debugConfiguration['env']['GOPATH'] = gopath;
}
const goConfig = getGoConfig(folder && folder.uri);
const goToolsEnvVars = getToolsEnvVars();
Object.keys(goToolsEnvVars).forEach((key) => {
if (!debugConfiguration['env'].hasOwnProperty(key)) {
debugConfiguration['env'][key] = goToolsEnvVars[key];
}
});
const dlvConfig = goConfig.get<any>('delveConfig');
let useApiV1 = false;
if (debugConfiguration.hasOwnProperty('useApiV1')) {
useApiV1 = debugConfiguration['useApiV1'] === true;
} else if (dlvConfig.hasOwnProperty('useApiV1')) {
useApiV1 = dlvConfig['useApiV1'] === true;
}
if (useApiV1) {
debugConfiguration['apiVersion'] = 1;
}
if (!debugConfiguration.hasOwnProperty('apiVersion') && dlvConfig.hasOwnProperty('apiVersion')) {
debugConfiguration['apiVersion'] = dlvConfig['apiVersion'];
}
if (!debugConfiguration.hasOwnProperty('dlvLoadConfig') && dlvConfig.hasOwnProperty('dlvLoadConfig')) {
debugConfiguration['dlvLoadConfig'] = dlvConfig['dlvLoadConfig'];
}
if (
!debugConfiguration.hasOwnProperty('showGlobalVariables') &&
dlvConfig.hasOwnProperty('showGlobalVariables')
) {
debugConfiguration['showGlobalVariables'] = dlvConfig['showGlobalVariables'];
}
if (debugConfiguration.request === 'attach' && !debugConfiguration['cwd']) {
debugConfiguration['cwd'] = '${workspaceFolder}';
}
debugConfiguration['dlvToolPath'] = getBinPath('dlv');
if (!path.isAbsolute(debugConfiguration['dlvToolPath'])) {
promptForMissingTool('dlv');
return;
}
if (debugConfiguration['mode'] === 'auto') {
debugConfiguration['mode'] =
activeEditor && activeEditor.document.fileName.endsWith('_test.go') ? 'test' : 'debug';
}
if (debugConfiguration.request === 'launch' && debugConfiguration['mode'] === 'remote') {
this.showWarning(
'ignoreDebugLaunchRemoteWarning',
`Request type of 'launch' with mode 'remote' is deprecated, please use request type 'attach' with mode 'remote' instead.`
);
}
if (
debugConfiguration.request === 'attach' &&
debugConfiguration['mode'] === 'remote' &&
debugConfiguration['program']
) {
this.showWarning(
'ignoreUsingRemotePathAndProgramWarning',
`Request type of 'attach' with mode 'remote' does not work with 'program' attribute, please use 'cwd' attribute instead.`
);
}
return debugConfiguration;
}
private showWarning(ignoreWarningKey: string, warningMessage: string) {
const ignoreWarning = getFromGlobalState(ignoreWarningKey);
if (ignoreWarning) {
return;
}
const neverAgain = { title: `Don't Show Again` };
vscode.window.showWarningMessage(warningMessage, neverAgain).then((result) => {
if (result === neverAgain) {
updateGlobalState(ignoreWarningKey, true);
}
});
}
}