fix: align viewsWelcome behavior to VS Code (#2543)

* fix: align `viewsWelcome` behavior to VS Code

Ref: eclipse-theia/theia#14309
Signed-off-by: dankeboy36 <dankeboy36@gmail.com>

* fix: update change proposal from Theia as is

Ref: arduino/arduino-ide#2543
Signed-off-by: dankeboy36 <dankeboy36@gmail.com>

---------

Signed-off-by: dankeboy36 <dankeboy36@gmail.com>
This commit is contained in:
dankeboy36
2024-11-21 08:43:04 +01:00
committed by GitHub
parent 4cf9909a07
commit 3fc8474d71
5 changed files with 351 additions and 2 deletions

View File

@@ -116,12 +116,16 @@ import { MessagingContribution } from './theia/core/messaging-contribution';
import { MessagingService } from '@theia/core/lib/node/messaging/messaging-service';
import { HostedPluginReader } from './theia/plugin-ext/plugin-reader';
import { HostedPluginReader as TheiaHostedPluginReader } from '@theia/plugin-ext/lib/hosted/node/plugin-reader';
import { PluginDeployer } from '@theia/plugin-ext/lib/common/plugin-protocol';
import {
PluginDeployer,
PluginScanner,
} from '@theia/plugin-ext/lib/common/plugin-protocol';
import {
LocalDirectoryPluginDeployerResolverWithFallback,
PluginDeployer_GH_12064,
} from './theia/plugin-ext/plugin-deployer';
import { SettingsReader } from './settings-reader';
import { VsCodePluginScanner } from './theia/plugin-ext-vscode/scanner-vscode';
export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(BackendApplication).toSelf().inSingletonScope();
@@ -410,6 +414,11 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
rebind(PluginDeployer).to(PluginDeployer_GH_12064).inSingletonScope();
bind(SettingsReader).toSelf().inSingletonScope();
// To read the enablement property of the viewsWelcome
// https://github.com/eclipse-theia/theia/issues/14309
bind(VsCodePluginScanner).toSelf().inSingletonScope();
rebind(PluginScanner).toService(VsCodePluginScanner);
});
function bindChildLogger(bind: interfaces.Bind, name: string): void {

View File

@@ -0,0 +1,44 @@
import { injectable, postConstruct } from '@theia/core/shared/inversify';
import { VsCodePluginScanner as TheiaVsCodePluginScanner } from '@theia/plugin-ext-vscode/lib/node/scanner-vscode';
import {
PluginPackageViewWelcome,
ViewWelcome,
} from '@theia/plugin-ext/lib/common/plugin-protocol';
@injectable()
export class VsCodePluginScanner extends TheiaVsCodePluginScanner {
@postConstruct()
protected init(): void {
this['readViewWelcome'] = (
rawViewWelcome: PluginPackageViewWelcome,
pluginViewsIds: string[]
) => {
const result = {
view: rawViewWelcome.view,
content: rawViewWelcome.contents,
when: rawViewWelcome.when,
// if the plugin contributes Welcome view to its own view - it will be ordered first
order:
pluginViewsIds.findIndex((v) => v === rawViewWelcome.view) > -1
? 0
: 1,
};
return maybeSetEnablement(rawViewWelcome, result);
};
}
}
// This is not yet supported by Theia but available in Code (https://github.com/microsoft/vscode/issues/114304)
function maybeSetEnablement(
rawViewWelcome: PluginPackageViewWelcome,
result: ViewWelcome
) {
const enablement =
'enablement' in rawViewWelcome &&
typeof rawViewWelcome['enablement'] === 'string' &&
rawViewWelcome['enablement'];
if (enablement) {
Object.assign(result, { enablement });
}
return result;
}