1
- import { Mutex } from 'async-mutex ' ;
1
+ import { DisposableCollection } from '@theia/core/lib/common/disposable ' ;
2
2
import { inject , injectable } from '@theia/core/shared/inversify' ;
3
+ import { Mutex } from 'async-mutex' ;
3
4
import {
4
5
ArduinoDaemon ,
5
6
BoardsService ,
6
7
ExecutableService ,
7
8
} from '../../common/protocol' ;
8
- import { HostedPluginEvents } from '../hosted-plugin-events' ;
9
- import { SketchContribution , URI } from './contribution' ;
10
9
import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl' ;
11
10
import { BoardsConfig } from '../boards/boards-config' ;
12
11
import { BoardsServiceProvider } from '../boards/boards-service-provider' ;
12
+ import { HostedPluginEvents } from '../hosted-plugin-events' ;
13
+ import { NotificationCenter } from '../notification-center' ;
14
+ import { SketchContribution , URI } from './contribution' ;
13
15
14
16
@injectable ( )
15
17
export class InoLanguage extends SketchContribution {
@@ -28,8 +30,12 @@ export class InoLanguage extends SketchContribution {
28
30
@inject ( BoardsServiceProvider )
29
31
private readonly boardsServiceProvider : BoardsServiceProvider ;
30
32
33
+ @inject ( NotificationCenter )
34
+ private readonly notificationCenter : NotificationCenter ;
35
+
36
+ private readonly toDispose = new DisposableCollection ( ) ;
37
+ private readonly languageServerStartMutex = new Mutex ( ) ;
31
38
private languageServerFqbn ?: string ;
32
- private languageServerStartMutex = new Mutex ( ) ;
33
39
34
40
override onReady ( ) : void {
35
41
const start = (
@@ -43,27 +49,41 @@ export class InoLanguage extends SketchContribution {
43
49
}
44
50
}
45
51
} ;
46
- this . boardsServiceProvider . onBoardsConfigChanged ( start ) ;
47
- this . hostedPluginEvents . onPluginsDidStart ( ( ) =>
48
- start ( this . boardsServiceProvider . boardsConfig )
49
- ) ;
50
- this . hostedPluginEvents . onPluginsWillUnload (
51
- ( ) => ( this . languageServerFqbn = undefined )
52
- ) ;
53
- this . preferences . onPreferenceChanged (
54
- ( { preferenceName, oldValue, newValue } ) => {
55
- if ( oldValue !== newValue ) {
56
- switch ( preferenceName ) {
57
- case 'arduino.language.log' :
58
- case 'arduino.language.realTimeDiagnostics' :
59
- start ( this . boardsServiceProvider . boardsConfig , true ) ;
52
+ const forceRestart = ( ) => {
53
+ start ( this . boardsServiceProvider . boardsConfig , true ) ;
54
+ } ;
55
+ this . toDispose . pushAll ( [
56
+ this . boardsServiceProvider . onBoardsConfigChanged ( start ) ,
57
+ this . hostedPluginEvents . onPluginsDidStart ( ( ) =>
58
+ start ( this . boardsServiceProvider . boardsConfig )
59
+ ) ,
60
+ this . hostedPluginEvents . onPluginsWillUnload (
61
+ ( ) => ( this . languageServerFqbn = undefined )
62
+ ) ,
63
+ this . preferences . onPreferenceChanged (
64
+ ( { preferenceName, oldValue, newValue } ) => {
65
+ if ( oldValue !== newValue ) {
66
+ switch ( preferenceName ) {
67
+ case 'arduino.language.log' :
68
+ case 'arduino.language.realTimeDiagnostics' :
69
+ forceRestart ( ) ;
70
+ }
60
71
}
61
72
}
62
- }
63
- ) ;
73
+ ) ,
74
+ this . notificationCenter . onLibraryDidInstall ( ( ) => forceRestart ( ) ) ,
75
+ this . notificationCenter . onLibraryDidUninstall ( ( ) => forceRestart ( ) ) ,
76
+ this . notificationCenter . onPlatformDidInstall ( ( ) => forceRestart ( ) ) ,
77
+ this . notificationCenter . onPlatformDidUninstall ( ( ) => forceRestart ( ) ) ,
78
+ this . notificationCenter . onDidReinitialize ( ( ) => forceRestart ( ) ) ,
79
+ ] ) ;
64
80
start ( this . boardsServiceProvider . boardsConfig ) ;
65
81
}
66
82
83
+ onStop ( ) : void {
84
+ this . toDispose . dispose ( ) ;
85
+ }
86
+
67
87
private async startLanguageServer (
68
88
fqbn : string ,
69
89
name : string | undefined ,
0 commit comments