1- import { Emitter , Event , JsonRpcProxy } from '@theia/core' ;
1+ import { DisposableCollection } from '@theia/core/lib/common/disposable' ;
2+ import { Emitter , Event } from '@theia/core/lib/common/event' ;
23import { injectable , interfaces } from '@theia/core/shared/inversify' ;
3- import { HostedPluginServer } from '@theia/plugin-ext/lib/common/plugin-protocol' ;
4- import { HostedPluginSupport as TheiaHostedPluginSupport } from '@theia/plugin-ext/lib/hosted/browser/hosted-plugin' ;
4+ import {
5+ PluginContributions ,
6+ HostedPluginSupport as TheiaHostedPluginSupport ,
7+ } from '@theia/plugin-ext/lib/hosted/browser/hosted-plugin' ;
58
69@injectable ( )
710export class HostedPluginSupport extends TheiaHostedPluginSupport {
@@ -10,7 +13,7 @@ export class HostedPluginSupport extends TheiaHostedPluginSupport {
1013
1114 override onStart ( container : interfaces . Container ) : void {
1215 super . onStart ( container ) ;
13- this . hostedPluginServer . onDidCloseConnection ( ( ) =>
16+ this [ 'server' ] . onDidCloseConnection ( ( ) =>
1417 this . onDidCloseConnectionEmitter . fire ( )
1518 ) ;
1619 }
@@ -28,8 +31,38 @@ export class HostedPluginSupport extends TheiaHostedPluginSupport {
2831 return this . onDidCloseConnectionEmitter . event ;
2932 }
3033
31- private get hostedPluginServer ( ) : JsonRpcProxy < HostedPluginServer > {
32- // eslint-disable-next-line @typescript-eslint/no-explicit-any
33- return ( this as any ) . server ;
34+ protected override startPlugins (
35+ contributionsByHost : Map < string , PluginContributions [ ] > ,
36+ toDisconnect : DisposableCollection
37+ ) : Promise < void > {
38+ reorderPlugins ( contributionsByHost ) ;
39+ return super . startPlugins ( contributionsByHost , toDisconnect ) ;
3440 }
3541}
42+
43+ /**
44+ * Force the `vscode-arduino-ide` API to activate before any Arduino IDE tool VSIX.
45+ *
46+ * Arduino IDE tool VISXs are not forced to declare the `vscode-arduino-api` as a `extensionDependencies`,
47+ * but the API must activate before any tools. This in place sorting helps to bypass Theia's plugin resolution
48+ * without forcing tools developers to add `vscode-arduino-api` to the `extensionDependencies`.
49+ */
50+ function reorderPlugins (
51+ contributionsByHost : Map < string , PluginContributions [ ] >
52+ ) : void {
53+ for ( const [ , contributions ] of contributionsByHost ) {
54+ const apiPluginIndex = contributions . findIndex ( isArduinoAPI ) ;
55+ if ( apiPluginIndex >= 0 ) {
56+ const apiPlugin = contributions [ apiPluginIndex ] ;
57+ contributions . splice ( apiPluginIndex , 1 ) ;
58+ contributions . unshift ( apiPlugin ) ;
59+ }
60+ }
61+ }
62+
63+ function isArduinoAPI ( pluginContribution : PluginContributions ) : boolean {
64+ return (
65+ pluginContribution . plugin . metadata . model . id ===
66+ 'dankeboy36.vscode-arduino-api'
67+ ) ;
68+ }
0 commit comments