-
-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: filtered undesired contributions: RTOS view
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
- Loading branch information
Akos Kitta
committed
Nov 29, 2022
1 parent
c217bed
commit e58d3a7
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
arduino-ide-extension/src/node/theia/plugin-ext/plugin-reader.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
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 readContribution( | ||
plugin: PluginPackage | ||
): PluginContribution | undefined { | ||
const scanner = this.scanner.getScanner(plugin); | ||
const contributions = 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'; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return contribution; | ||
}; | ||
|
||
const pluginFilters = new Map<string, PluginContributionFilter>([ | ||
['cortex-debug', cortexDebugFilter], | ||
]); |