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' ;
2
3
import { 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' ;
5
8
6
9
@injectable ( )
7
10
export class HostedPluginSupport extends TheiaHostedPluginSupport {
@@ -10,7 +13,7 @@ export class HostedPluginSupport extends TheiaHostedPluginSupport {
10
13
11
14
override onStart ( container : interfaces . Container ) : void {
12
15
super . onStart ( container ) ;
13
- this . hostedPluginServer . onDidCloseConnection ( ( ) =>
16
+ this [ 'server' ] . onDidCloseConnection ( ( ) =>
14
17
this . onDidCloseConnectionEmitter . fire ( )
15
18
) ;
16
19
}
@@ -28,8 +31,38 @@ export class HostedPluginSupport extends TheiaHostedPluginSupport {
28
31
return this . onDidCloseConnectionEmitter . event ;
29
32
}
30
33
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 ) ;
34
40
}
35
41
}
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