Skip to content

Commit cdadda8

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
Do not start LS if core for board is missing.
- Added a 20 sec timeout to the LS process start. - Discard running LS FQBN when the LS start has failed. Signed-off-by: Akos Kitta <[email protected]>
1 parent 596d54a commit cdadda8

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

Diff for: arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

+23-11
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,17 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
229229
protected async startLanguageServer(fqbn: string, name: string | undefined): Promise<void> {
230230
const release = await this.languageServerStartMutex.acquire();
231231
try {
232+
await this.hostedPluginSupport.didStart;
233+
const details = await this.boardsService.getBoardDetails({ fqbn });
234+
if (!details) {
235+
// Core is not installed for the selected board.
236+
console.info(`Could not start language server for ${fqbn}. The core is not installed for the board.`);
237+
return;
238+
}
232239
if (fqbn === this.languageServerFqbn) {
233240
// NOOP
234241
return;
235242
}
236-
await this.hostedPluginSupport.didStart;
237243
this.logger.info(`Starting language server: ${fqbn}`);
238244
const log = this.arduinoPreferences.get('arduino.language.log');
239245
let currentSketchPath: string | undefined = undefined;
@@ -249,16 +255,22 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
249255
this.fileSystem.fsPath(new URI(cliUri)),
250256
this.fileSystem.fsPath(new URI(lsUri)),
251257
]);
252-
this.languageServerFqbn = await this.commandRegistry.executeCommand('arduino.languageserver.start', {
253-
lsPath,
254-
cliPath,
255-
clangdPath,
256-
log: currentSketchPath ? currentSketchPath : log,
257-
board: {
258-
fqbn,
259-
name: name ? `"${name}"` : undefined
260-
}
261-
});
258+
this.languageServerFqbn = await Promise.race([
259+
new Promise<undefined>((_, reject) => setTimeout(() => reject(new Error(`Timeout after ${20_000} ms.`)), 20_000)),
260+
this.commandRegistry.executeCommand<string>('arduino.languageserver.start', {
261+
lsPath,
262+
cliPath,
263+
clangdPath,
264+
log: currentSketchPath ? currentSketchPath : log,
265+
board: {
266+
fqbn,
267+
name: name ? `"${name}"` : undefined
268+
}
269+
})
270+
]);
271+
} catch (e) {
272+
console.log(`Failed to start language server for ${fqbn}`, e);
273+
this.languageServerFqbn = undefined;
262274
} finally {
263275
release();
264276
}

0 commit comments

Comments
 (0)