-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathtree.ts
496 lines (439 loc) · 14.3 KB
/
tree.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
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
// Tree.ts
import * as configuration from "./configuration";
import * as path from "path";
import * as util from "./util";
import * as vscode from "vscode";
import * as nls from "vscode-nls";
import { extension } from "./extension";
nls.config({
messageFormat: nls.MessageFormat.bundle,
bundleFormat: nls.BundleFormat.standalone,
})();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
interface NamedItem {
name: string;
}
abstract class BaseNode {
constructor(public readonly id: string) {}
abstract getTreeItem(): vscode.TreeItem;
abstract getChildren(): BaseNode[];
}
export class BuildTargetNode extends BaseNode {
constructor(targetName: string) {
super(`buildTarget:${targetName}`);
this._name = targetName;
}
_name: string;
update(targetName: string): void {
this._name = localize(
"tree.build.target",
"Build target: {0}",
`[${targetName}]`
);
}
getChildren(): BaseNode[] {
return [];
}
getTreeItem(): vscode.TreeItem {
try {
const item: vscode.TreeItem = new vscode.TreeItem(this._name);
item.collapsibleState = vscode.TreeItemCollapsibleState.None;
item.tooltip = localize(
"makefile.target.currently.selected.for.build",
"The makefile target currently selected for build."
);
item.contextValue = [`nodeType=buildTarget`].join(",");
return item;
} catch (e) {
return new vscode.TreeItem(
localize(
"issue.rendering.item",
"{0} (there was an issue rendering this item)",
this._name
)
);
}
}
}
export class LaunchTargetNode extends BaseNode {
_name: string;
// Keep the tree node label as short as possible.
// The binary path is the most important component of a launch target.
async getShortLaunchTargetName(
completeLaunchTargetName: string
): Promise<string> {
let launchConfiguration: configuration.LaunchConfiguration | undefined =
await configuration.stringToLaunchConfiguration(completeLaunchTargetName);
let shortName: string;
if (!launchConfiguration) {
shortName = localize("Unset", "Unset");
} else {
if (vscode.workspace.workspaceFolders) {
// In a complete launch target string, the binary path is relative to cwd.
// In here, since we don't show cwd, make it relative to current workspace folder.
shortName = util.makeRelPath(
launchConfiguration.binaryPath,
vscode.workspace.workspaceFolders[0].uri.fsPath
);
} else {
// Just in case, if for some reason we don't have a workspace folder, return full binary path.
shortName = launchConfiguration.binaryPath;
}
}
return localize(
"tree.launch.target",
"Launch target: {0}",
`[${shortName}]`
);
}
constructor(targetName: string) {
super(`launchTarget:${targetName}`);
// Show the short name as label
this._name = targetName;
}
async update(targetName: string): Promise<void> {
// Show short name as label
this._name = await this.getShortLaunchTargetName(targetName);
}
getChildren(): BaseNode[] {
return [];
}
getTreeItem(): vscode.TreeItem {
try {
const item: vscode.TreeItem = new vscode.TreeItem(this._name);
item.collapsibleState = vscode.TreeItemCollapsibleState.None;
item.tooltip = localize(
"launch.target.currently.selected.for.debug.run.in.terminal",
"The launch target currently selected for debug and run in terminal."
);
item.contextValue = [`nodeType=launchTarget`].join(",");
return item;
} catch (e) {
return new vscode.TreeItem(
localize(
"issue.rendering.item",
"{0} (there was an issue rendering this item)",
this._name
)
);
}
}
}
export class ConfigurationNode extends BaseNode {
constructor(configurationName: string) {
super(`configuration:${configurationName}`);
this._name = configurationName;
}
_name: string;
update(configurationName: string): void {
this._name = localize(
"tree.configuration",
"Configuration: {0}",
`[${configurationName}]`
);
}
getChildren(): BaseNode[] {
return [];
}
getTreeItem(): vscode.TreeItem {
try {
const item: vscode.TreeItem = new vscode.TreeItem(this._name);
item.collapsibleState = vscode.TreeItemCollapsibleState.None;
item.tooltip = localize(
"makefile.currently.selected.configuration",
"The makefile configuration currently selected from settings ('makefile.configurations')."
);
item.contextValue = [`nodeType=configuration`].join(",");
return item;
} catch (e) {
return new vscode.TreeItem(
localize(
"issue.rendering.item",
"{0} (there was an issue rendering this item)",
this._name
)
);
}
}
}
export class MakefilePathInfoNode extends BaseNode {
constructor(pathInSettings: string, pathDisplayed: string) {
super(pathDisplayed);
this._title = pathDisplayed;
this._tooltip = pathInSettings;
}
_title: string;
_tooltip: string;
update(pathInSettings: string, pathDisplayed: string): void {
this._title = localize(
"tree.makefile.path.info",
"{0}",
`${pathDisplayed}`
);
this._tooltip = pathInSettings;
}
getChildren(): BaseNode[] {
return [];
}
getTreeItem(): vscode.TreeItem {
try {
const item: vscode.TreeItem = new vscode.TreeItem(this._title);
item.collapsibleState = vscode.TreeItemCollapsibleState.None;
item.tooltip = this._tooltip;
item.contextValue = [`nodeType=makefilePathInfo`].join(",");
return item;
} catch (e) {
return new vscode.TreeItem(
localize(
"issue.rendering.item",
"{0} (there was an issue rendering this item)",
this._title
)
);
}
}
}
export class MakePathInfoNode extends BaseNode {
constructor(pathInSettings: string, pathDisplayed: string) {
super(pathDisplayed);
this._title = pathDisplayed;
this._tooltip = pathInSettings;
}
_title: string;
_tooltip: string;
update(pathInSettings: string, pathDisplayed: string): void {
this._title = localize("tree.make.path.info", "{0}", `${pathDisplayed}`);
this._tooltip = pathInSettings;
}
getChildren(): BaseNode[] {
return [];
}
getTreeItem(): vscode.TreeItem {
try {
const item: vscode.TreeItem = new vscode.TreeItem(this._title);
item.collapsibleState = vscode.TreeItemCollapsibleState.None;
item.tooltip = this._tooltip;
item.contextValue = [`nodeType=makePathInfo`].join(",");
return item;
} catch (e) {
return new vscode.TreeItem(
localize(
"issue.rendering.item",
"{0} (there was an issue rendering this item)",
this._title
)
);
}
}
}
export class BuildLogPathInfoNode extends BaseNode {
constructor(pathInSettings: string, pathDisplayed: string) {
super(pathDisplayed);
this._title = pathDisplayed;
}
_title: string;
update(pathInSettings: string, pathDisplayed: string): void {
this._title = localize(
"tree.build.log.path.info",
"{0}",
`${pathDisplayed}`
);
}
getChildren(): BaseNode[] {
return [];
}
getTreeItem(): vscode.TreeItem {
try {
const item: vscode.TreeItem = new vscode.TreeItem(this._title);
item.collapsibleState = vscode.TreeItemCollapsibleState.None;
item.tooltip = localize(
"build.log.path.info",
"The path to the build log that is read to bypass a dry-run."
);
item.contextValue = [`nodeType=buildLogPathInfo`].join(",");
return item;
} catch (e) {
return new vscode.TreeItem(
localize(
"issue.rendering.item",
"{0} (there was an issue rendering this item)",
this._title
)
);
}
}
}
export class ProjectOutlineProvider
implements vscode.TreeDataProvider<BaseNode>
{
private readonly _changeEvent = new vscode.EventEmitter<BaseNode | null>();
private readonly _unsetString = localize("Unset", "Unset");
constructor() {
this._currentConfigurationItem = new ConfigurationNode(this._unsetString);
this._currentBuildTargetItem = new BuildTargetNode(this._unsetString);
this._currentLaunchTargetItem = new LaunchTargetNode(this._unsetString);
this._currentMakefilePathInfoItem = new MakefilePathInfoNode(
this._unsetString,
""
);
this._currentMakePathInfoItem = new MakePathInfoNode(this._unsetString, "");
this._currentBuildLogPathInfoItem = new BuildLogPathInfoNode(
this._unsetString,
""
);
}
private _currentConfigurationItem: ConfigurationNode;
private _currentBuildTargetItem: BuildTargetNode;
private _currentLaunchTargetItem: LaunchTargetNode;
private _currentMakefilePathInfoItem: MakefilePathInfoNode;
private _currentMakePathInfoItem: MakePathInfoNode;
private _currentBuildLogPathInfoItem: BuildLogPathInfoNode;
get onDidChangeTreeData(): any {
return this._changeEvent.event;
}
async getTreeItem(node: BaseNode): Promise<vscode.TreeItem> {
return node.getTreeItem();
}
getChildren(node?: BaseNode): BaseNode[] {
if (node) {
return node.getChildren();
}
if (
configuration.isOptionalFeatureEnabled("debug") ||
configuration.isOptionalFeatureEnabled("run")
) {
return [
this._currentConfigurationItem,
this._currentBuildTargetItem,
this._currentLaunchTargetItem,
this._currentMakefilePathInfoItem,
this._currentMakePathInfoItem,
this._currentBuildLogPathInfoItem,
];
} else {
return [
this._currentConfigurationItem,
this._currentBuildTargetItem,
this._currentMakefilePathInfoItem,
this._currentMakePathInfoItem,
this._currentBuildLogPathInfoItem,
];
}
}
pathDisplayed(
pathInSettings: string | undefined,
kind: string,
searchInPath: boolean,
makeRelative: boolean
): string {
if (!pathInSettings) {
if (kind === "Build Log") {
extension.updateBuildLogPresent(false);
kind = localize("build.log", "Build Log");
} else if (kind === "Makefile") {
extension.updateMakefileFilePresent(false);
}
const unset = localize("Unset", "Unset");
return `${kind}: [${unset}]`;
}
const pathInSettingsToTest: string | undefined =
process.platform === "win32" &&
!pathInSettings?.endsWith(".exe") &&
kind === "Make"
? pathInSettings?.concat(".exe")
: pathInSettings;
const pathBase: string | undefined =
searchInPath && path.parse(pathInSettingsToTest).dir === ""
? path.parse(pathInSettingsToTest).base
: undefined;
const pathInEnv: string | undefined = pathBase
? path.join(util.toolPathInEnv(pathBase) || "", pathBase)
: undefined;
const finalPath: string = pathInEnv || pathInSettingsToTest;
const checkFileExists = util.checkFileExistsSync(finalPath);
if (kind === "Build Log") {
extension.updateBuildLogPresent(checkFileExists);
kind = localize("build.log", "Build Log");
} else if (kind === "Makefile") {
extension.updateMakefileFilePresent(checkFileExists);
}
const notFound = localize("not.found", "not found");
return (
(!checkFileExists ? `${kind} (${notFound})` : `${kind}`) +
`: [${
makeRelative
? util.makeRelPath(finalPath, util.getWorkspaceRoot())
: finalPath
}]`
);
}
async update(
configuration: string | undefined,
buildTarget: string | undefined,
launchTarget: string | undefined,
makefilePathInfo: string | undefined,
makePathInfo: string | undefined,
buildLogInfo: string | undefined
): Promise<void> {
this._currentConfigurationItem.update(configuration || this._unsetString);
this._currentBuildTargetItem.update(buildTarget || this._unsetString);
await this._currentLaunchTargetItem.update(
launchTarget || this._unsetString
);
this._currentMakefilePathInfoItem.update(
makefilePathInfo || this._unsetString,
this.pathDisplayed(makefilePathInfo, "Makefile", false, false)
);
this._currentMakePathInfoItem.update(
makePathInfo || this._unsetString,
this.pathDisplayed(makePathInfo, "Make", true, false)
);
this._currentBuildLogPathInfoItem.update(
buildLogInfo || this._unsetString,
this.pathDisplayed(buildLogInfo, "Build Log", false, false)
);
this.updateTree();
}
updateConfiguration(configuration: string): void {
this._currentConfigurationItem.update(configuration);
this.updateTree();
}
updateBuildTarget(buildTarget: string): void {
this._currentBuildTargetItem.update(buildTarget);
this.updateTree();
}
async updateLaunchTarget(launchTarget: string): Promise<void> {
await this._currentLaunchTargetItem.update(launchTarget);
this.updateTree();
}
async updateMakefilePathInfo(
makefilePathInfo: string | undefined
): Promise<void> {
this._currentMakefilePathInfoItem.update(
makefilePathInfo || this._unsetString,
this.pathDisplayed(makefilePathInfo, "Makefile", false, true)
);
this.updateTree();
}
async updateMakePathInfo(makePathInfo: string | undefined): Promise<void> {
this._currentMakePathInfoItem.update(
makePathInfo || this._unsetString,
this.pathDisplayed(makePathInfo, "Make", true, false)
);
this.updateTree();
}
async updateBuildLogPathInfo(
buildLogPathInfo: string | undefined
): Promise<void> {
this._currentBuildLogPathInfoItem.update(
buildLogPathInfo || this._unsetString,
this.pathDisplayed(buildLogPathInfo, "Build Log", false, true)
);
this.updateTree();
}
updateTree(): void {
this._changeEvent.fire(null);
}
}