From cdadda85e5766bac621cd61357f1f81dea035e32 Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Thu, 25 Feb 2021 14:11:20 +0100 Subject: [PATCH] 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 --- .../browser/arduino-frontend-contribution.tsx | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx b/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx index b3bec2b8..0e7b68a2 100644 --- a/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx +++ b/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx @@ -229,11 +229,17 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut protected async startLanguageServer(fqbn: string, name: string | undefined): Promise { const release = await this.languageServerStartMutex.acquire(); try { + await this.hostedPluginSupport.didStart; + const details = await this.boardsService.getBoardDetails({ fqbn }); + if (!details) { + // Core is not installed for the selected board. + console.info(`Could not start language server for ${fqbn}. The core is not installed for the board.`); + return; + } if (fqbn === this.languageServerFqbn) { // NOOP return; } - await this.hostedPluginSupport.didStart; this.logger.info(`Starting language server: ${fqbn}`); const log = this.arduinoPreferences.get('arduino.language.log'); let currentSketchPath: string | undefined = undefined; @@ -249,16 +255,22 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut this.fileSystem.fsPath(new URI(cliUri)), this.fileSystem.fsPath(new URI(lsUri)), ]); - this.languageServerFqbn = await this.commandRegistry.executeCommand('arduino.languageserver.start', { - lsPath, - cliPath, - clangdPath, - log: currentSketchPath ? currentSketchPath : log, - board: { - fqbn, - name: name ? `"${name}"` : undefined - } - }); + this.languageServerFqbn = await Promise.race([ + new Promise((_, reject) => setTimeout(() => reject(new Error(`Timeout after ${20_000} ms.`)), 20_000)), + this.commandRegistry.executeCommand('arduino.languageserver.start', { + lsPath, + cliPath, + clangdPath, + log: currentSketchPath ? currentSketchPath : log, + board: { + fqbn, + name: name ? `"${name}"` : undefined + } + }) + ]); + } catch (e) { + console.log(`Failed to start language server for ${fqbn}`, e); + this.languageServerFqbn = undefined; } finally { release(); }