Skip to content

Commit 637e2cc

Browse files
author
Akos Kitta
committed
fix: restart LS on lib/core change, client re-init
Closes #670 Signed-off-by: Akos Kitta <[email protected]>
1 parent 76f9f63 commit 637e2cc

File tree

1 file changed

+40
-20
lines changed

1 file changed

+40
-20
lines changed

Diff for: arduino-ide-extension/src/browser/contributions/ino-language.ts

+40-20
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import { Mutex } from 'async-mutex';
1+
import { DisposableCollection } from '@theia/core/lib/common/disposable';
22
import { inject, injectable } from '@theia/core/shared/inversify';
3+
import { Mutex } from 'async-mutex';
34
import {
45
ArduinoDaemon,
56
BoardsService,
67
ExecutableService,
78
} from '../../common/protocol';
8-
import { HostedPluginEvents } from '../hosted-plugin-events';
9-
import { SketchContribution, URI } from './contribution';
109
import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
1110
import { BoardsConfig } from '../boards/boards-config';
1211
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';
1315

1416
@injectable()
1517
export class InoLanguage extends SketchContribution {
@@ -28,8 +30,12 @@ export class InoLanguage extends SketchContribution {
2830
@inject(BoardsServiceProvider)
2931
private readonly boardsServiceProvider: BoardsServiceProvider;
3032

33+
@inject(NotificationCenter)
34+
private readonly notificationCenter: NotificationCenter;
35+
36+
private readonly toDispose = new DisposableCollection();
37+
private readonly languageServerStartMutex = new Mutex();
3138
private languageServerFqbn?: string;
32-
private languageServerStartMutex = new Mutex();
3339

3440
override onReady(): void {
3541
const start = (
@@ -43,27 +49,41 @@ export class InoLanguage extends SketchContribution {
4349
}
4450
}
4551
};
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+
}
6071
}
6172
}
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+
]);
6480
start(this.boardsServiceProvider.boardsConfig);
6581
}
6682

83+
onStop(): void {
84+
this.toDispose.dispose();
85+
}
86+
6787
private async startLanguageServer(
6888
fqbn: string,
6989
name: string | undefined,

0 commit comments

Comments
 (0)