-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathconfigurations.ts
More file actions
312 lines (254 loc) · 11.6 KB
/
configurations.ts
File metadata and controls
312 lines (254 loc) · 11.6 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved.
* See 'LICENSE' in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import * as os from 'os';
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { configPrefix } from '../LanguageServer/extension';
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
export function isDebugLaunchStr(str: string): boolean {
return str.startsWith("(gdb) ") || str.startsWith("(lldb) ") || str.startsWith("(Windows) ");
}
export interface ConfigMenu extends vscode.QuickPickItem {
configuration: CppDebugConfiguration;
}
export enum DebuggerType {
cppvsdbg = "cppvsdbg",
cppdbg = "cppdbg",
all = "all"
}
export enum DebuggerEvent {
debugPanel = "debugPanel", // F5 or "Run and Debug" Panel
playButton = "playButton", // "Run and Debug" play button
addConfigGear = "AddConfigGear"
}
export enum TaskStatus {
recentlyUsed = "Recently Used Task", // A configured task that has been used recently.
configured = "Configured Task", // The tasks that are configured in tasks.json file.
detected = "Detected Task" // The tasks that are available based on detected compilers.
}
export enum ConfigSource {
singleFile = "singleFile", // a debug config defined for a single mode file
workspaceFolder = "workspaceFolder", // a debug config defined in launch.json
workspace = "workspace", // a debug config defined in workspace level
global = "global", // a debug config defined in user level
unknown = "unknown"
}
export enum ConfigMode {
launchConfig = "launchConfig",
noLaunchConfig = "noLaunchConfig",
unknown = "unknown"
}
export enum DebugType {
debug = "debug",
run = "run"
}
export interface CppDebugConfiguration extends vscode.DebugConfiguration {
detail?: string;
taskStatus?: TaskStatus;
isDefault?: boolean; // The debug configuration is considered as default, if the prelaunch task is set as default.
configSource?: ConfigSource;
debuggerEvent?: DebuggerEvent;
debugType?: DebugType;
existing?: boolean;
}
export interface IConfigurationSnippet {
label: string;
description: string;
bodyText: string;
// Internal
isInitialConfiguration?: boolean;
debuggerType: DebuggerType;
}
export function indentJsonString(json: string, numTabs: number = 1): string {
return json.split('\n').map(line => '\t'.repeat(numTabs) + line).join('\n').trim();
}
function formatString(format: string, args: string[]): string {
args.forEach((arg: string, index: number) => {
format = format.replace("{" + index + "}", arg);
});
return format;
}
function createLaunchString(name: string, type: string, executable: string): string {
return `"name": "${name}",
"type": "${type}",
"request": "launch",
"program": "${localize("enter.program.name", "enter program name, for example {0}", "$\{workspaceFolder\}" + "/" + executable).replace(/"/g, '')}",
"args": [],
"stopAtEntry": false,
"cwd": "$\{fileDirname\}",
"environment": [],
${type === "cppdbg" ? `"externalConsole": false` : `"console": "internalConsole"`}
`;
}
function createAttachString(name: string, type: string, executable: string): string {
return formatString(`
"name": "${name}",
"type": "${type}",
"request": "attach",{0}
`, [type === "cppdbg" ? `${os.EOL}"program": "${localize("enter.program.name", "enter program name, for example {0}", "$\{workspaceFolder\}" + "/" + executable).replace(/"/g, '')}",` : ""]);
}
function createRemoteAttachString(name: string, type: string, executable: string): string {
return `
"name": "${name}",
"type": "${type}",
"request": "attach",
"program": "${localize("enter.program.name", "enter program name, for example {0}", "$\{workspaceFolder\}" + "/" + executable).replace(/"/g, '')}",
"processId": "$\{command:pickRemoteProcess\}"
`;
}
function createPipeTransportString(pipeProgram: string, debuggerProgram: string, pipeArgs: string[] = []): string {
return `
"pipeTransport": {
\t"debuggerPath": "/usr/bin/${debuggerProgram}",
\t"pipeProgram": "${pipeProgram}",
\t"pipeArgs": ${JSON.stringify(pipeArgs)},
\t"pipeCwd": ""
}`;
}
export interface IConfiguration {
GetLaunchConfiguration(): IConfigurationSnippet;
GetAttachConfiguration(): IConfigurationSnippet;
}
abstract class Configuration implements IConfiguration {
public executable: string;
public pipeProgram: string;
public MIMode: string;
public additionalProperties: string;
public miDebugger = "cppdbg";
public windowsDebugger = "cppvsdbg";
constructor(MIMode: string, executable: string, pipeProgram: string, additionalProperties: string = "") {
this.MIMode = MIMode;
this.executable = executable;
this.pipeProgram = pipeProgram;
this.additionalProperties = additionalProperties;
}
abstract GetLaunchConfiguration(): IConfigurationSnippet;
abstract GetAttachConfiguration(): IConfigurationSnippet;
}
export class MIConfigurations extends Configuration {
public GetLaunchConfiguration(): IConfigurationSnippet {
const name: string = `(${this.MIMode}) ${localize("launch.string", "Launch").replace(/"/g, '')}`;
const body: string = formatString(`{
\t${indentJsonString(createLaunchString(name, this.miDebugger, this.executable))},
\t"MIMode": "${this.MIMode}"{0}{1}
}`, [this.miDebugger === "cppdbg" && os.platform() === "win32" ? `,${os.EOL}\t"miDebuggerPath": "/path/to/gdb"` : "",
this.additionalProperties ? `,${os.EOL}\t${indentJsonString(this.additionalProperties)}` : ""]);
return {
"label": configPrefix + name,
"description": localize("launch.with", "Launch with {0}.", this.MIMode).replace(/"/g, ''),
"bodyText": body.trim(),
"isInitialConfiguration": true,
"debuggerType": DebuggerType.cppdbg
};
}
public GetAttachConfiguration(): IConfigurationSnippet {
const name: string = `(${this.MIMode}) ${localize("attach.string", "Attach").replace(/"/g, '')}`;
const body: string = formatString(`{
\t${indentJsonString(createAttachString(name, this.miDebugger, this.executable))}
\t"MIMode": "${this.MIMode}"{0}{1}
}`, [this.miDebugger === "cppdbg" && os.platform() === "win32" ? `,${os.EOL}\t"miDebuggerPath": "/path/to/gdb"` : "",
this.additionalProperties ? `,${os.EOL}\t${indentJsonString(this.additionalProperties)}` : ""]);
return {
"label": configPrefix + name,
"description": localize("attach.with", "Attach with {0}.", this.MIMode).replace(/"/g, ''),
"bodyText": body.trim(),
"debuggerType": DebuggerType.cppdbg
};
}
}
export class PipeTransportConfigurations extends Configuration {
public GetLaunchConfiguration(): IConfigurationSnippet {
const name: string = `(${this.MIMode}) ${localize("pipe.launch", "Pipe Launch").replace(/"/g, '')}`;
const body: string = formatString(`
{
\t${indentJsonString(createLaunchString(name, this.miDebugger, this.executable))},
\t${indentJsonString(createPipeTransportString(this.pipeProgram, this.MIMode))},
\t"MIMode": "${this.MIMode}"{0}
}`, [this.additionalProperties ? `,${os.EOL}\t${indentJsonString(this.additionalProperties)}` : ""]);
return {
"label": configPrefix + name,
"description": localize("pipe.launch.with", "Pipe Launch with {0}.", this.MIMode).replace(/"/g, ''),
"bodyText": body.trim(),
"debuggerType": DebuggerType.cppdbg
};
}
public GetAttachConfiguration(): IConfigurationSnippet {
const name: string = `(${this.MIMode}) ${localize("pipe.attach", "Pipe Attach").replace(/"/g, '')}`;
const body: string = formatString(`
{
\t${indentJsonString(createRemoteAttachString(name, this.miDebugger, this.executable))},
\t${indentJsonString(createPipeTransportString(this.pipeProgram, this.MIMode))},
\t"MIMode": "${this.MIMode}"{0}
}`, [this.additionalProperties ? `,${os.EOL}\t${indentJsonString(this.additionalProperties)}` : ""]);
return {
"label": configPrefix + name,
"description": localize("pipe.attach.with", "Pipe Attach with {0}.", this.MIMode).replace(/"/g, ''),
"bodyText": body.trim(),
"debuggerType": DebuggerType.cppdbg
};
}
}
export class WindowsConfigurations extends Configuration {
public GetLaunchConfiguration(): IConfigurationSnippet {
const name: string = `(Windows) ${localize("launch.string", "Launch").replace(/"/g, '')}`;
const body: string = `
{
\t${indentJsonString(createLaunchString(name, this.windowsDebugger, this.executable))}
}`;
return {
"label": configPrefix + name,
"description": localize("launch.with.vs.debugger", "Launch with the Visual Studio C/C++ debugger.").replace(/"/g, ''),
"bodyText": body.trim(),
"isInitialConfiguration": true,
"debuggerType": DebuggerType.cppvsdbg
};
}
public GetAttachConfiguration(): IConfigurationSnippet {
const name: string = `(Windows) ${localize("attach.string", "Attach").replace(/"/g, '')}`;
const body: string = `
{
\t${indentJsonString(createAttachString(name, this.windowsDebugger, this.executable))}
}`;
return {
"label": configPrefix + name,
"description": localize("attach.with.vs.debugger", "Attach to a process with the Visual Studio C/C++ debugger.").replace(/"/g, ''),
"bodyText": body.trim(),
"debuggerType": DebuggerType.cppvsdbg
};
}
}
export class WSLConfigurations extends Configuration {
// Detects if the current VSCode is 32-bit and uses the correct bash.exe
public bashPipeProgram = process.arch === 'ia32' ? "${env:windir}\\\\sysnative\\\\bash.exe" : "${env:windir}\\\\system32\\\\bash.exe";
public GetLaunchConfiguration(): IConfigurationSnippet {
const name: string = `(${this.MIMode}) ${localize("bash.on.windows.launch", "Bash on Windows Launch").replace(/"/g, '')}`;
const body: string = formatString(`
{
\t${indentJsonString(createLaunchString(name, this.miDebugger, this.executable))},
\t${indentJsonString(createPipeTransportString(this.bashPipeProgram, this.MIMode, ["-c"]))}{0}
}`, [this.additionalProperties ? `,${os.EOL}\t${indentJsonString(this.additionalProperties)}` : ""]);
return {
"label": configPrefix + name,
"description": localize("launch.bash.windows", "Launch in Bash on Windows using {0}.", this.MIMode).replace(/"/g, ''),
"bodyText": body.trim(),
"debuggerType": DebuggerType.cppdbg
};
}
public GetAttachConfiguration(): IConfigurationSnippet {
const name: string = `(${this.MIMode}) ${localize("bash.on.windows.attach", "Bash on Windows Attach").replace(/"/g, '')}`;
const body: string = formatString(`
{
\t${indentJsonString(createRemoteAttachString(name, this.miDebugger, this.executable))},
\t${indentJsonString(createPipeTransportString(this.bashPipeProgram, this.MIMode, ["-c"]))}{0}
}`, [this.additionalProperties ? `,${os.EOL}\t${indentJsonString(this.additionalProperties)}` : ""]);
return {
"label": configPrefix + name,
"description": localize("remote.attach.bash.windows", "Attach to a remote process running in Bash on Windows using {0}.", this.MIMode).replace(/"/g, ''),
"bodyText": body.trim(),
"debuggerType": DebuggerType.cppdbg
};
}
}