Skip to content

Commit d53d8b9

Browse files
committed
fix: let the ino contribution notify the LS
+ event emitter dispatches the new state. Signed-off-by: dankeboy36 <[email protected]>
1 parent bab2e58 commit d53d8b9

File tree

3 files changed

+62
-40
lines changed

3 files changed

+62
-40
lines changed

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

+39
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
ArduinoDaemon,
99
BoardIdentifier,
1010
BoardsService,
11+
CompileSummary,
1112
ExecutableService,
1213
isBoardIdentifierChangeEvent,
1314
sanitizeFqbn,
@@ -23,6 +24,7 @@ import { HostedPluginEvents } from '../hosted/hosted-plugin-events';
2324
import { NotificationCenter } from '../notification-center';
2425
import { CurrentSketch } from '../sketches-service-client-impl';
2526
import { SketchContribution, URI } from './contribution';
27+
import { CompileSummaryProvider } from './verify-sketch';
2628

2729
interface DaemonAddress {
2830
/**
@@ -107,6 +109,8 @@ export class InoLanguage extends SketchContribution {
107109
private readonly notificationCenter: NotificationCenter;
108110
@inject(BoardsDataStore)
109111
private readonly boardDataStore: BoardsDataStore;
112+
@inject(CompileSummaryProvider)
113+
private readonly compileSummaryProvider: CompileSummaryProvider;
110114

111115
private readonly toDispose = new DisposableCollection();
112116
private readonly languageServerStartMutex = new Mutex();
@@ -173,6 +177,13 @@ export class InoLanguage extends SketchContribution {
173177
}
174178
}
175179
}),
180+
this.compileSummaryProvider.onDidChangeCompileSummary(
181+
(compileSummary) => {
182+
if (compileSummary) {
183+
this.fireBuildDidComplete(compileSummary);
184+
}
185+
}
186+
),
176187
]);
177188
Promise.all([
178189
this.boardsServiceProvider.ready,
@@ -317,4 +328,32 @@ export class InoLanguage extends SketchContribution {
317328
params
318329
);
319330
}
331+
332+
// Execute the a command contributed by the Arduino Tools VSIX to send the `ino/buildDidComplete` notification to the language server
333+
private async fireBuildDidComplete(
334+
compileSummary: CompileSummary
335+
): Promise<void> {
336+
const params = {
337+
...compileSummary,
338+
};
339+
console.info(
340+
`Executing 'arduino.languageserver.notifyBuildDidComplete' with ${JSON.stringify(
341+
params.buildOutputUri
342+
)}`
343+
);
344+
345+
try {
346+
await this.commandService.executeCommand(
347+
'arduino.languageserver.notifyBuildDidComplete',
348+
params
349+
);
350+
} catch (err) {
351+
console.error(
352+
`Unexpected error when firing event on build did complete. ${JSON.stringify(
353+
params.buildOutputUri
354+
)}`,
355+
err
356+
);
357+
}
358+
}
320359
}

arduino-ide-extension/src/browser/contributions/update-arduino-state.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@ export class UpdateArduinoState extends SketchContribution {
6262
this.configService.onDidChangeSketchDirUri((userDirUri) =>
6363
this.updateUserDirPath(userDirUri)
6464
),
65-
this.compileSummaryProvider.onDidChangeCompileSummary(() =>
66-
this.maybeUpdateCompileSummary()
65+
this.compileSummaryProvider.onDidChangeCompileSummary(
66+
(compilerSummary) => {
67+
if (compilerSummary) {
68+
this.updateCompileSummary(compilerSummary);
69+
}
70+
}
6771
),
6872
this.boardsDataStore.onDidChange((event) => {
6973
const selectedFqbn =
@@ -85,20 +89,16 @@ export class UpdateArduinoState extends SketchContribution {
8589
this.updateSketchPath(this.sketchServiceClient.tryGetCurrentSketch());
8690
this.updateUserDirPath(this.configService.tryGetSketchDirUri());
8791
this.updateDataDirPath(this.configService.tryGetDataDirUri());
88-
this.maybeUpdateCompileSummary();
89-
}
90-
91-
onStop(): void {
92-
this.toDispose.dispose();
93-
}
94-
95-
private maybeUpdateCompileSummary() {
9692
const { compileSummary } = this.compileSummaryProvider;
9793
if (compileSummary) {
9894
this.updateCompileSummary(compileSummary);
9995
}
10096
}
10197

98+
onStop(): void {
99+
this.toDispose.dispose();
100+
}
101+
102102
private async updateSketchPath(
103103
sketch: CurrentSketch | undefined
104104
): Promise<void> {

arduino-ide-extension/src/browser/contributions/verify-sketch.ts

+13-30
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { CoreErrorHandler } from './core-error-handler';
1818
export const CompileSummaryProvider = Symbol('CompileSummaryProvider');
1919
export interface CompileSummaryProvider {
2020
readonly compileSummary: CompileSummary | undefined;
21-
readonly onDidChangeCompileSummary: Event<void>;
21+
readonly onDidChangeCompileSummary: Event<CompileSummary | undefined>;
2222
}
2323

2424
export type VerifySketchMode =
@@ -61,7 +61,9 @@ export class VerifySketch
6161

6262
private readonly onDidChangeEmitter = new Emitter<void>();
6363
private readonly onDidChange = this.onDidChangeEmitter.event;
64-
private readonly onDidChangeCompileSummaryEmitter = new Emitter<void>();
64+
private readonly onDidChangeCompileSummaryEmitter = new Emitter<
65+
CompileSummary | undefined
66+
>();
6567
private verifyProgress: VerifyProgress = 'idle';
6668
private _compileSummary: CompileSummary | undefined;
6769

@@ -132,7 +134,14 @@ export class VerifySketch
132134
return this._compileSummary;
133135
}
134136

135-
get onDidChangeCompileSummary(): Event<void> {
137+
private updateCompileSummary(
138+
compileSummary: CompileSummary | undefined
139+
): void {
140+
this._compileSummary = compileSummary;
141+
this.onDidChangeCompileSummaryEmitter.fire(this._compileSummary);
142+
}
143+
144+
get onDidChangeCompileSummary(): Event<CompileSummary | undefined> {
136145
return this.onDidChangeCompileSummaryEmitter.event;
137146
}
138147

@@ -180,11 +189,7 @@ export class VerifySketch
180189
{ timeout: 3000 }
181190
);
182191

183-
this._compileSummary = compileSummary;
184-
this.onDidChangeCompileSummaryEmitter.fire();
185-
if (this._compileSummary) {
186-
this.fireBuildDidComplete(this._compileSummary);
187-
}
192+
this.updateCompileSummary(compileSummary);
188193

189194
// Returns with the used options for the compilation
190195
// so that follow-up tasks (such as upload) can reuse the compiled code.
@@ -227,28 +232,6 @@ export class VerifySketch
227232
compilerWarnings,
228233
};
229234
}
230-
231-
// Execute the a command contributed by the Arduino Tools VSIX to send the `ino/buildDidComplete` notification to the language server
232-
private fireBuildDidComplete(compileSummary: CompileSummary): void {
233-
const params = {
234-
...compileSummary,
235-
};
236-
console.info(
237-
`Executing 'arduino.languageserver.notifyBuildDidComplete' with ${JSON.stringify(
238-
params.buildOutputUri
239-
)}`
240-
);
241-
this.commandService
242-
.executeCommand('arduino.languageserver.notifyBuildDidComplete', params)
243-
.catch((err) =>
244-
console.error(
245-
`Unexpected error when firing event on build did complete. ${JSON.stringify(
246-
params.buildOutputUri
247-
)}`,
248-
err
249-
)
250-
);
251-
}
252235
}
253236

254237
export namespace VerifySketch {

0 commit comments

Comments
 (0)