Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/extension-editing/src/extensionLinter.ts
5256 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as path from 'path';
7
import * as fs from 'fs';
8
import { URL } from 'url';
9
10
import { parseTree, findNodeAtLocation, Node as JsonNode, getNodeValue } from 'jsonc-parser';
11
import * as MarkdownItType from 'markdown-it';
12
13
import { commands, languages, workspace, Disposable, TextDocument, Uri, Diagnostic, Range, DiagnosticSeverity, Position, env, l10n } from 'vscode';
14
import { INormalizedVersion, normalizeVersion, parseVersion } from './extensionEngineValidation';
15
import { JsonStringScanner } from './jsonReconstruct';
16
import { implicitActivationEvent, redundantImplicitActivationEvent } from './constants';
17
18
const product = JSON.parse(fs.readFileSync(path.join(env.appRoot, 'product.json'), { encoding: 'utf-8' }));
19
const allowedBadgeProviders: string[] = (product.extensionAllowedBadgeProviders || []).map((s: string) => s.toLowerCase());
20
const allowedBadgeProvidersRegex: RegExp[] = (product.extensionAllowedBadgeProvidersRegex || []).map((r: string) => new RegExp(r));
21
const extensionEnabledApiProposals: Record<string, string[]> = product.extensionEnabledApiProposals ?? {};
22
const reservedImplicitActivationEventPrefixes = ['onNotebookSerializer:'];
23
const redundantImplicitActivationEventPrefixes = ['onLanguage:', 'onView:', 'onAuthenticationRequest:', 'onCommand:', 'onCustomEditor:', 'onTerminalProfile:', 'onRenderer:', 'onTerminalQuickFixRequest:', 'onWalkthrough:'];
24
25
function isTrustedSVGSource(uri: Uri): boolean {
26
return allowedBadgeProviders.includes(uri.authority.toLowerCase()) || allowedBadgeProvidersRegex.some(r => r.test(uri.toString()));
27
}
28
29
const httpsRequired = l10n.t("Images must use the HTTPS protocol.");
30
const svgsNotValid = l10n.t("SVGs are not a valid image source.");
31
const embeddedSvgsNotValid = l10n.t("Embedded SVGs are not a valid image source.");
32
const dataUrlsNotValid = l10n.t("Data URLs are not a valid image source.");
33
const relativeUrlRequiresHttpsRepository = l10n.t("Relative image URLs require a repository with HTTPS protocol to be specified in the package.json.");
34
const relativeBadgeUrlRequiresHttpsRepository = l10n.t("Relative badge URLs require a repository with HTTPS protocol to be specified in this package.json.");
35
const apiProposalNotListed = l10n.t("This proposal cannot be used because for this extension the product defines a fixed set of API proposals. You can test your extension but before publishing you MUST reach out to the VS Code team.");
36
37
const starActivation = l10n.t("Using '*' activation is usually a bad idea as it impacts performance.");
38
const parsingErrorHeader = l10n.t("Error parsing the when-clause:");
39
40
enum Context {
41
ICON,
42
BADGE,
43
MARKDOWN
44
}
45
46
interface TokenAndPosition {
47
token: MarkdownItType.Token;
48
begin: number;
49
end: number;
50
}
51
52
interface PackageJsonInfo {
53
isExtension: boolean;
54
hasHttpsRepository: boolean;
55
repository: Uri;
56
implicitActivationEvents: Set<string> | undefined;
57
engineVersion: INormalizedVersion | null;
58
}
59
60
export class ExtensionLinter {
61
62
private diagnosticsCollection = languages.createDiagnosticCollection('extension-editing');
63
private fileWatcher = workspace.createFileSystemWatcher('**/package.json');
64
private disposables: Disposable[] = [this.diagnosticsCollection, this.fileWatcher];
65
66
private folderToPackageJsonInfo: Record<string, PackageJsonInfo> = {};
67
private packageJsonQ = new Set<TextDocument>();
68
private readmeQ = new Set<TextDocument>();
69
private timer: NodeJS.Timeout | undefined;
70
private markdownIt: MarkdownItType.MarkdownIt | undefined;
71
private parse5: typeof import('parse5') | undefined;
72
73
constructor() {
74
this.disposables.push(
75
workspace.onDidOpenTextDocument(document => this.queue(document)),
76
workspace.onDidChangeTextDocument(event => this.queue(event.document)),
77
workspace.onDidCloseTextDocument(document => this.clear(document)),
78
this.fileWatcher.onDidChange(uri => this.packageJsonChanged(this.getUriFolder(uri))),
79
this.fileWatcher.onDidCreate(uri => this.packageJsonChanged(this.getUriFolder(uri))),
80
this.fileWatcher.onDidDelete(uri => this.packageJsonChanged(this.getUriFolder(uri))),
81
);
82
workspace.textDocuments.forEach(document => this.queue(document));
83
}
84
85
private queue(document: TextDocument) {
86
const p = document.uri.path;
87
if (document.languageId === 'json' && p.endsWith('/package.json')) {
88
this.packageJsonQ.add(document);
89
this.startTimer();
90
}
91
this.queueReadme(document);
92
}
93
94
private queueReadme(document: TextDocument) {
95
const p = document.uri.path;
96
if (document.languageId === 'markdown' && (p.toLowerCase().endsWith('/readme.md') || p.toLowerCase().endsWith('/changelog.md'))) {
97
this.readmeQ.add(document);
98
this.startTimer();
99
}
100
}
101
102
private startTimer() {
103
if (this.timer) {
104
clearTimeout(this.timer);
105
}
106
this.timer = setTimeout(() => {
107
this.lint()
108
.catch(console.error);
109
}, 300);
110
}
111
112
private async lint() {
113
await Promise.all([
114
this.lintPackageJson(),
115
this.lintReadme()
116
]);
117
}
118
119
private async lintPackageJson() {
120
for (const document of Array.from(this.packageJsonQ)) {
121
this.packageJsonQ.delete(document);
122
if (document.isClosed) {
123
continue;
124
}
125
126
const diagnostics: Diagnostic[] = [];
127
128
const tree = parseTree(document.getText());
129
const info = this.readPackageJsonInfo(this.getUriFolder(document.uri), tree);
130
if (tree && info.isExtension) {
131
132
const icon = findNodeAtLocation(tree, ['icon']);
133
if (icon && icon.type === 'string') {
134
this.addDiagnostics(diagnostics, document, icon.offset + 1, icon.offset + icon.length - 1, icon.value, Context.ICON, info);
135
}
136
137
const badges = findNodeAtLocation(tree, ['badges']);
138
if (badges && badges.type === 'array' && badges.children) {
139
badges.children.map(child => findNodeAtLocation(child, ['url']))
140
.filter(url => url && url.type === 'string')
141
.map(url => this.addDiagnostics(diagnostics, document, url!.offset + 1, url!.offset + url!.length - 1, url!.value, Context.BADGE, info));
142
}
143
144
const publisher = findNodeAtLocation(tree, ['publisher']);
145
const name = findNodeAtLocation(tree, ['name']);
146
const enabledApiProposals = findNodeAtLocation(tree, ['enabledApiProposals']);
147
if (publisher?.type === 'string' && name?.type === 'string' && enabledApiProposals?.type === 'array') {
148
const extensionId = `${getNodeValue(publisher)}.${getNodeValue(name)}`;
149
const effectiveProposalNames = extensionEnabledApiProposals[extensionId];
150
if (Array.isArray(effectiveProposalNames) && enabledApiProposals.children) {
151
for (const child of enabledApiProposals.children) {
152
const proposalName = child.type === 'string' ? getNodeValue(child) : undefined;
153
if (typeof proposalName === 'string' && !effectiveProposalNames.includes(proposalName.split('@')[0])) {
154
const start = document.positionAt(child.offset);
155
const end = document.positionAt(child.offset + child.length);
156
diagnostics.push(new Diagnostic(new Range(start, end), apiProposalNotListed, DiagnosticSeverity.Error));
157
}
158
}
159
}
160
}
161
const activationEventsNode = findNodeAtLocation(tree, ['activationEvents']);
162
if (activationEventsNode?.type === 'array' && activationEventsNode.children) {
163
for (const activationEventNode of activationEventsNode.children) {
164
const activationEvent = getNodeValue(activationEventNode);
165
const isImplicitActivationSupported = info.engineVersion && (info.engineVersion.majorBase > 1 || (info.engineVersion.majorBase === 1 && info.engineVersion.minorBase >= 75));
166
// Redundant Implicit Activation
167
if (isImplicitActivationSupported && info.implicitActivationEvents?.has(activationEvent) && redundantImplicitActivationEventPrefixes.some((prefix) => activationEvent.startsWith(prefix))) {
168
const start = document.positionAt(activationEventNode.offset);
169
const end = document.positionAt(activationEventNode.offset + activationEventNode.length);
170
diagnostics.push(new Diagnostic(new Range(start, end), redundantImplicitActivationEvent, DiagnosticSeverity.Warning));
171
}
172
173
// Reserved Implicit Activation
174
for (const implicitActivationEventPrefix of reservedImplicitActivationEventPrefixes) {
175
if (isImplicitActivationSupported && activationEvent.startsWith(implicitActivationEventPrefix)) {
176
const start = document.positionAt(activationEventNode.offset);
177
const end = document.positionAt(activationEventNode.offset + activationEventNode.length);
178
diagnostics.push(new Diagnostic(new Range(start, end), implicitActivationEvent, DiagnosticSeverity.Error));
179
}
180
}
181
182
// Star activation
183
if (activationEvent === '*') {
184
const start = document.positionAt(activationEventNode.offset);
185
const end = document.positionAt(activationEventNode.offset + activationEventNode.length);
186
const diagnostic = new Diagnostic(new Range(start, end), starActivation, DiagnosticSeverity.Information);
187
diagnostic.code = {
188
value: 'star-activation',
189
target: Uri.parse('https://code.visualstudio.com/api/references/activation-events#Start-up'),
190
};
191
diagnostics.push(diagnostic);
192
}
193
}
194
}
195
196
const whenClauseLinting = await this.lintWhenClauses(findNodeAtLocation(tree, ['contributes']), document);
197
diagnostics.push(...whenClauseLinting);
198
}
199
this.diagnosticsCollection.set(document.uri, diagnostics);
200
}
201
}
202
203
/** lints `when` and `enablement` clauses */
204
private async lintWhenClauses(contributesNode: JsonNode | undefined, document: TextDocument): Promise<Diagnostic[]> {
205
if (!contributesNode) {
206
return [];
207
}
208
209
const whenClauses: JsonNode[] = [];
210
211
function findWhens(node: JsonNode | undefined, clauseName: string) {
212
if (node) {
213
switch (node.type) {
214
case 'property':
215
if (node.children && node.children.length === 2) {
216
const key = node.children[0];
217
const value = node.children[1];
218
switch (value.type) {
219
case 'string':
220
if (key.value === clauseName && typeof value.value === 'string' /* careful: `.value` MUST be a string 1) because a when/enablement clause is string; so also, type cast to string below is safe */) {
221
whenClauses.push(value);
222
}
223
case 'object':
224
case 'array':
225
findWhens(value, clauseName);
226
}
227
}
228
break;
229
case 'object':
230
case 'array':
231
if (node.children) {
232
node.children.forEach(n => findWhens(n, clauseName));
233
}
234
}
235
}
236
}
237
238
[
239
findNodeAtLocation(contributesNode, ['menus']),
240
findNodeAtLocation(contributesNode, ['views']),
241
findNodeAtLocation(contributesNode, ['viewsWelcome']),
242
findNodeAtLocation(contributesNode, ['keybindings']),
243
].forEach(n => findWhens(n, 'when'));
244
245
findWhens(findNodeAtLocation(contributesNode, ['commands']), 'enablement');
246
247
const parseResults = await commands.executeCommand<{ errorMessage: string; offset: number; length: number }[][]>('_validateWhenClauses', whenClauses.map(w => w.value as string /* we make sure to capture only if `w.value` is string above */));
248
249
const diagnostics: Diagnostic[] = [];
250
for (let i = 0; i < parseResults.length; ++i) {
251
const whenClauseJSONNode = whenClauses[i];
252
253
const jsonStringScanner = new JsonStringScanner(document.getText(), whenClauseJSONNode.offset + 1);
254
255
for (const error of parseResults[i]) {
256
const realOffset = jsonStringScanner.getOffsetInEncoded(error.offset);
257
const realOffsetEnd = jsonStringScanner.getOffsetInEncoded(error.offset + error.length);
258
const start = document.positionAt(realOffset /* +1 to account for the quote (I think) */);
259
const end = document.positionAt(realOffsetEnd);
260
const errMsg = `${parsingErrorHeader}\n\n${error.errorMessage}`;
261
const diagnostic = new Diagnostic(new Range(start, end), errMsg, DiagnosticSeverity.Error);
262
diagnostic.code = {
263
value: 'See docs',
264
target: Uri.parse('https://code.visualstudio.com/api/references/when-clause-contexts'),
265
};
266
diagnostics.push(diagnostic);
267
}
268
}
269
return diagnostics;
270
}
271
272
private async lintReadme() {
273
for (const document of this.readmeQ) {
274
this.readmeQ.delete(document);
275
if (document.isClosed) {
276
continue;
277
}
278
279
const folder = this.getUriFolder(document.uri);
280
let info = this.folderToPackageJsonInfo[folder.toString()];
281
if (!info) {
282
const tree = await this.loadPackageJson(folder);
283
info = this.readPackageJsonInfo(folder, tree);
284
}
285
if (!info.isExtension) {
286
this.diagnosticsCollection.set(document.uri, []);
287
return;
288
}
289
290
const text = document.getText();
291
if (!this.markdownIt) {
292
this.markdownIt = new ((await import('markdown-it')).default);
293
}
294
const tokens = this.markdownIt.parse(text, {});
295
const tokensAndPositions: TokenAndPosition[] = (function toTokensAndPositions(this: ExtensionLinter, tokens: MarkdownItType.Token[], begin = 0, end = text.length): TokenAndPosition[] {
296
const tokensAndPositions = tokens.map<TokenAndPosition>(token => {
297
if (token.map) {
298
const tokenBegin = document.offsetAt(new Position(token.map[0], 0));
299
const tokenEnd = begin = document.offsetAt(new Position(token.map[1], 0));
300
return {
301
token,
302
begin: tokenBegin,
303
end: tokenEnd
304
};
305
}
306
const image = token.type === 'image' && this.locateToken(text, begin, end, token, token.attrGet('src'));
307
const other = image || this.locateToken(text, begin, end, token, token.content);
308
return other || {
309
token,
310
begin,
311
end: begin
312
};
313
});
314
return tokensAndPositions.concat(
315
...tokensAndPositions.filter(tnp => tnp.token.children && tnp.token.children.length)
316
.map(tnp => toTokensAndPositions.call(this, tnp.token.children, tnp.begin, tnp.end))
317
);
318
}).call(this, tokens);
319
320
const diagnostics: Diagnostic[] = [];
321
322
tokensAndPositions.filter(tnp => tnp.token.type === 'image' && tnp.token.attrGet('src'))
323
.map(inp => {
324
const src = inp.token.attrGet('src')!;
325
const begin = text.indexOf(src, inp.begin);
326
if (begin !== -1 && begin < inp.end) {
327
this.addDiagnostics(diagnostics, document, begin, begin + src.length, src, Context.MARKDOWN, info);
328
} else {
329
const content = inp.token.content;
330
const begin = text.indexOf(content, inp.begin);
331
if (begin !== -1 && begin < inp.end) {
332
this.addDiagnostics(diagnostics, document, begin, begin + content.length, src, Context.MARKDOWN, info);
333
}
334
}
335
});
336
337
let svgStart: Diagnostic;
338
for (const tnp of tokensAndPositions) {
339
if (tnp.token.type === 'text' && tnp.token.content) {
340
if (!this.parse5) {
341
this.parse5 = await import('parse5');
342
}
343
const parser = new this.parse5.SAXParser({ locationInfo: true });
344
parser.on('startTag', (name, attrs, _selfClosing, location) => {
345
if (name === 'img') {
346
const src = attrs.find(a => a.name === 'src');
347
if (src && src.value && location) {
348
const begin = text.indexOf(src.value, tnp.begin + location.startOffset);
349
if (begin !== -1 && begin < tnp.end) {
350
this.addDiagnostics(diagnostics, document, begin, begin + src.value.length, src.value, Context.MARKDOWN, info);
351
}
352
}
353
} else if (name === 'svg' && location) {
354
const begin = tnp.begin + location.startOffset;
355
const end = tnp.begin + location.endOffset;
356
const range = new Range(document.positionAt(begin), document.positionAt(end));
357
svgStart = new Diagnostic(range, embeddedSvgsNotValid, DiagnosticSeverity.Warning);
358
diagnostics.push(svgStart);
359
}
360
});
361
parser.on('endTag', (name, location) => {
362
if (name === 'svg' && svgStart && location) {
363
const end = tnp.begin + location.endOffset;
364
svgStart.range = new Range(svgStart.range.start, document.positionAt(end));
365
}
366
});
367
parser.write(tnp.token.content);
368
parser.end();
369
}
370
}
371
372
this.diagnosticsCollection.set(document.uri, diagnostics);
373
}
374
}
375
376
private locateToken(text: string, begin: number, end: number, token: MarkdownItType.Token, content: string | null) {
377
if (content) {
378
const tokenBegin = text.indexOf(content, begin);
379
if (tokenBegin !== -1) {
380
const tokenEnd = tokenBegin + content.length;
381
if (tokenEnd <= end) {
382
begin = tokenEnd;
383
return {
384
token,
385
begin: tokenBegin,
386
end: tokenEnd
387
};
388
}
389
}
390
}
391
return undefined;
392
}
393
394
private readPackageJsonInfo(folder: Uri, tree: JsonNode | undefined) {
395
const engine = tree && findNodeAtLocation(tree, ['engines', 'vscode']);
396
const parsedEngineVersion = engine?.type === 'string' ? normalizeVersion(parseVersion(engine.value)) : null;
397
const repo = tree && findNodeAtLocation(tree, ['repository', 'url']);
398
const uri = repo && parseUri(repo.value);
399
const activationEvents = tree && parseImplicitActivationEvents(tree);
400
401
const info: PackageJsonInfo = {
402
isExtension: !!(engine && engine.type === 'string'),
403
hasHttpsRepository: !!(repo && repo.type === 'string' && repo.value && uri && uri.scheme.toLowerCase() === 'https'),
404
repository: uri!,
405
implicitActivationEvents: activationEvents,
406
engineVersion: parsedEngineVersion
407
};
408
const str = folder.toString();
409
const oldInfo = this.folderToPackageJsonInfo[str];
410
if (oldInfo && (oldInfo.isExtension !== info.isExtension || oldInfo.hasHttpsRepository !== info.hasHttpsRepository)) {
411
this.packageJsonChanged(folder); // clears this.folderToPackageJsonInfo[str]
412
}
413
this.folderToPackageJsonInfo[str] = info;
414
return info;
415
}
416
417
private async loadPackageJson(folder: Uri) {
418
if (folder.scheme === 'git') { // #36236
419
return undefined;
420
}
421
const file = folder.with({ path: path.posix.join(folder.path, 'package.json') });
422
try {
423
const fileContents = await workspace.fs.readFile(file); // #174888
424
return parseTree(Buffer.from(fileContents).toString('utf-8'));
425
} catch (err) {
426
return undefined;
427
}
428
}
429
430
private packageJsonChanged(folder: Uri) {
431
delete this.folderToPackageJsonInfo[folder.toString()];
432
const str = folder.toString().toLowerCase();
433
workspace.textDocuments.filter(document => this.getUriFolder(document.uri).toString().toLowerCase() === str)
434
.forEach(document => this.queueReadme(document));
435
}
436
437
private getUriFolder(uri: Uri) {
438
return uri.with({ path: path.posix.dirname(uri.path) });
439
}
440
441
private addDiagnostics(diagnostics: Diagnostic[], document: TextDocument, begin: number, end: number, src: string, context: Context, info: PackageJsonInfo) {
442
const hasScheme = /^\w[\w\d+.-]*:/.test(src);
443
const uri = parseUri(src, info.repository ? info.repository.toString() : document.uri.toString());
444
if (!uri) {
445
return;
446
}
447
const scheme = uri.scheme.toLowerCase();
448
449
if (hasScheme && scheme !== 'https' && scheme !== 'data') {
450
const range = new Range(document.positionAt(begin), document.positionAt(end));
451
diagnostics.push(new Diagnostic(range, httpsRequired, DiagnosticSeverity.Warning));
452
}
453
454
if (hasScheme && scheme === 'data') {
455
const range = new Range(document.positionAt(begin), document.positionAt(end));
456
diagnostics.push(new Diagnostic(range, dataUrlsNotValid, DiagnosticSeverity.Warning));
457
}
458
459
if (!hasScheme && !info.hasHttpsRepository && context !== Context.ICON) {
460
const range = new Range(document.positionAt(begin), document.positionAt(end));
461
const message = (() => {
462
switch (context) {
463
case Context.BADGE: return relativeBadgeUrlRequiresHttpsRepository;
464
default: return relativeUrlRequiresHttpsRepository;
465
}
466
})();
467
diagnostics.push(new Diagnostic(range, message, DiagnosticSeverity.Warning));
468
}
469
470
if (uri.path.toLowerCase().endsWith('.svg') && !isTrustedSVGSource(uri)) {
471
const range = new Range(document.positionAt(begin), document.positionAt(end));
472
diagnostics.push(new Diagnostic(range, svgsNotValid, DiagnosticSeverity.Warning));
473
}
474
}
475
476
private clear(document: TextDocument) {
477
this.diagnosticsCollection.delete(document.uri);
478
this.packageJsonQ.delete(document);
479
}
480
481
public dispose() {
482
this.disposables.forEach(d => d.dispose());
483
this.disposables = [];
484
}
485
}
486
487
function parseUri(src: string, base?: string, retry: boolean = true): Uri | null {
488
try {
489
const url = new URL(src, base);
490
return Uri.parse(url.toString());
491
} catch (err) {
492
if (retry) {
493
return parseUri(encodeURI(src), base, false);
494
} else {
495
return null;
496
}
497
}
498
}
499
500
function parseImplicitActivationEvents(tree: JsonNode): Set<string> {
501
const activationEvents = new Set<string>();
502
503
// commands
504
const commands = findNodeAtLocation(tree, ['contributes', 'commands']);
505
commands?.children?.forEach(child => {
506
const command = findNodeAtLocation(child, ['command']);
507
if (command && command.type === 'string') {
508
activationEvents.add(`onCommand:${command.value}`);
509
}
510
});
511
512
// authenticationProviders
513
const authenticationProviders = findNodeAtLocation(tree, ['contributes', 'authentication']);
514
authenticationProviders?.children?.forEach(child => {
515
const id = findNodeAtLocation(child, ['id']);
516
if (id && id.type === 'string') {
517
activationEvents.add(`onAuthenticationRequest:${id.value}`);
518
}
519
});
520
521
// languages
522
const languageContributions = findNodeAtLocation(tree, ['contributes', 'languages']);
523
languageContributions?.children?.forEach(child => {
524
const id = findNodeAtLocation(child, ['id']);
525
const configuration = findNodeAtLocation(child, ['configuration']);
526
if (id && id.type === 'string' && configuration && configuration.type === 'string') {
527
activationEvents.add(`onLanguage:${id.value}`);
528
}
529
});
530
531
// customEditors
532
const customEditors = findNodeAtLocation(tree, ['contributes', 'customEditors']);
533
customEditors?.children?.forEach(child => {
534
const viewType = findNodeAtLocation(child, ['viewType']);
535
if (viewType && viewType.type === 'string') {
536
activationEvents.add(`onCustomEditor:${viewType.value}`);
537
}
538
});
539
540
// views
541
const viewContributions = findNodeAtLocation(tree, ['contributes', 'views']);
542
viewContributions?.children?.forEach(viewContribution => {
543
const views = viewContribution.children?.find((node) => node.type === 'array');
544
views?.children?.forEach(view => {
545
const id = findNodeAtLocation(view, ['id']);
546
if (id && id.type === 'string') {
547
activationEvents.add(`onView:${id.value}`);
548
}
549
});
550
});
551
552
// walkthroughs
553
const walkthroughs = findNodeAtLocation(tree, ['contributes', 'walkthroughs']);
554
walkthroughs?.children?.forEach(child => {
555
const id = findNodeAtLocation(child, ['id']);
556
if (id && id.type === 'string') {
557
activationEvents.add(`onWalkthrough:${id.value}`);
558
}
559
});
560
561
// notebookRenderers
562
const notebookRenderers = findNodeAtLocation(tree, ['contributes', 'notebookRenderer']);
563
notebookRenderers?.children?.forEach(child => {
564
const id = findNodeAtLocation(child, ['id']);
565
if (id && id.type === 'string') {
566
activationEvents.add(`onRenderer:${id.value}`);
567
}
568
});
569
570
// terminalProfiles
571
const terminalProfiles = findNodeAtLocation(tree, ['contributes', 'terminal', 'profiles']);
572
terminalProfiles?.children?.forEach(child => {
573
const id = findNodeAtLocation(child, ['id']);
574
if (id && id.type === 'string') {
575
activationEvents.add(`onTerminalProfile:${id.value}`);
576
}
577
});
578
579
// terminalQuickFixes
580
const terminalQuickFixes = findNodeAtLocation(tree, ['contributes', 'terminal', 'quickFixes']);
581
terminalQuickFixes?.children?.forEach(child => {
582
const id = findNodeAtLocation(child, ['id']);
583
if (id && id.type === 'string') {
584
activationEvents.add(`onTerminalQuickFixRequest:${id.value}`);
585
}
586
});
587
588
// tasks
589
const tasks = findNodeAtLocation(tree, ['contributes', 'taskDefinitions']);
590
tasks?.children?.forEach(child => {
591
const id = findNodeAtLocation(child, ['type']);
592
if (id && id.type === 'string') {
593
activationEvents.add(`onTaskType:${id.value}`);
594
}
595
});
596
597
return activationEvents;
598
}
599
600