-
-
Notifications
You must be signed in to change notification settings - Fork 431
/
Copy pathplugin-reader.ts
89 lines (85 loc) · 2.76 KB
/
plugin-reader.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
import { injectable } from '@theia/core/shared/inversify';
import type {
PluginContribution,
PluginPackage,
} from '@theia/plugin-ext/lib/common/plugin-protocol';
import { HostedPluginReader as TheiaHostedPluginReader } from '@theia/plugin-ext/lib/hosted/node/plugin-reader';
@injectable()
export class HostedPluginReader extends TheiaHostedPluginReader {
override async readContribution(
plugin: PluginPackage
): Promise<PluginContribution | undefined> {
const scanner = this.scanner.getScanner(plugin);
const contributions = await scanner.getContribution(plugin);
return this.filterContribution(plugin.name, contributions);
}
private filterContribution(
pluginName: string,
contributions: PluginContribution | undefined
): PluginContribution | undefined {
if (!contributions) {
return contributions;
}
const filter = pluginFilters.get(pluginName);
return filter ? filter(contributions) : contributions;
}
}
type PluginContributionFilter = (
contribution: PluginContribution
) => PluginContribution | undefined;
const cortexDebugFilter: PluginContributionFilter = (
contribution: PluginContribution
) => {
if (contribution.viewsContainers) {
for (const location of Object.keys(contribution.viewsContainers)) {
const viewContainers = contribution.viewsContainers[location];
for (let i = 0; i < viewContainers.length; i++) {
const viewContainer = viewContainers[i];
if (
viewContainer.id === 'cortex-debug' &&
viewContainer.title === 'RTOS'
) {
viewContainers.splice(i, 1);
}
}
}
}
if (contribution.views) {
for (const location of Object.keys(contribution.views)) {
if (location === 'cortex-debug') {
const views = contribution.views[location];
for (let i = 0; i < views.length; i++) {
const view = views[i];
if (view.id === 'cortex-debug.rtos') {
views.splice(i, 1);
}
}
}
}
}
if (contribution.menus) {
for (const location of Object.keys(contribution.menus)) {
if (location === 'commandPalette') {
const menus = contribution.menus[location];
for (let i = 0; i < menus.length; i++) {
const menu = menus[i];
if (menu.command === 'cortex-debug.rtos.toggleRTOSPanel') {
menu.when = 'false';
}
}
}
}
}
if (contribution.commands) {
for (const command of contribution.commands) {
if (command.command === 'cortex-debug.resetDevice') {
// TODO: fix loading of original SVG icon in Theia
delete command.iconUrl;
}
}
}
return contribution;
};
const pluginFilters = new Map<string, PluginContributionFilter>([
['cortex-debug', cortexDebugFilter],
]);