From 3e4ad5086c84c9e3dc22ae6da4e05682ec535b71 Mon Sep 17 00:00:00 2001 From: Enguerrand de Ribaucourt Date: Thu, 2 Nov 2023 16:37:29 +0100 Subject: [PATCH] Feat: Have broader bitbake settings sanity checks When the user opens a new workspace he'll probably need to configure the extension. Sanity checks are here to check that the settings are remotely accurate. They don't check that bitbake is fully functionnal but quickly allow detecting settings errors. Previously, the only check and notification regarded the bitbake folder. Now, the environment script is also checked. The build path doesn't need to be checked because it is dynamically created. The notification message has been changed to be more generic. The "Open Settings" button now opens the workspace settings with a more accurate filter. --- client/src/ui/ClientNotificationManager.ts | 14 +++++++------- server/src/ServerNotificationManager.ts | 6 +++--- server/src/server.ts | 15 ++++++++++++--- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/client/src/ui/ClientNotificationManager.ts b/client/src/ui/ClientNotificationManager.ts index eefccf18..b135ab73 100644 --- a/client/src/ui/ClientNotificationManager.ts +++ b/client/src/ui/ClientNotificationManager.ts @@ -17,29 +17,29 @@ export class ClientNotificationManager { buildHandlers (): Disposable[] { const handlers = [ - this.buildBitBakeNotFoundHandler() + this.bitBakeSettingsErrorHandler() ] return handlers } - private buildBitBakeNotFoundHandler (): Disposable { - const isNeverShowAgain = this.checkIsNeverShowAgain('custom/bitBakeNotFound') + private bitBakeSettingsErrorHandler (): Disposable { + const isNeverShowAgain = this.checkIsNeverShowAgain('custom/bitbakeSettingsError') if (isNeverShowAgain) { return { dispose: () => {} } } - return this._client.onNotification('custom/bitBakeNotFound', () => { + return this._client.onNotification('custom/bitbakeSettingsError', (message?: string) => { void window.showErrorMessage( - 'BitBake folder could not be found. Please set its path in the settings. Optionally, also set an environment script.', + 'BitBake could not be configured and started. To enable advanced Bitbake features, please configure the Bitbake extension.\n\n' + message, 'Open Settings', 'Close', 'Never Show Again' ) .then((item) => { if (item === 'Open Settings') { - void commands.executeCommand('workbench.action.openSettings', 'bitbake') + void commands.executeCommand('workbench.action.openWorkspaceSettings', '@ext:savoirfairelinux.bitbake') } else if (item === 'Never Show Again') { - void this.neverShowAgain('custom/bitBakeNotFound') + void this.neverShowAgain('custom/bitbakeSettingsError') } }) }) diff --git a/server/src/ServerNotificationManager.ts b/server/src/ServerNotificationManager.ts index 74bab7fc..0e981485 100644 --- a/server/src/ServerNotificationManager.ts +++ b/server/src/ServerNotificationManager.ts @@ -15,7 +15,7 @@ export function setNotificationManagerConnection (connection: Connection): void } export type NotificationType = - 'custom/bitBakeNotFound' + 'custom/bitbakeSettingsError' class ServerNotificationManager { send (type: NotificationType, message?: string): void { @@ -27,8 +27,8 @@ class ServerNotificationManager { void _connection.sendNotification(type, message) } - sendBitBakeNotFound (): void { - this.send('custom/bitBakeNotFound') + sendBitBakeSettingsError (message?: string): void { + this.send('custom/bitbakeSettingsError', message) } } diff --git a/server/src/server.ts b/server/src/server.ts index 993de33e..a587bd10 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -67,21 +67,30 @@ function setSymbolScanner (newSymbolScanner: SymbolScanner | null): void { contextHandler.symbolScanner = newSymbolScanner } -function checkBitbakePresence (): void { +function checkBitbakeSettingsSanity (): boolean { const bitbakeFolder = bitBakeProjectScanner.bitbakeDriver.bitbakeSettings.pathToBitbakeFolder const bitbakeBinPath = bitbakeFolder + '/bin/bitbake' if (!fs.existsSync(bitbakeBinPath)) { - serverNotificationManager.sendBitBakeNotFound() + serverNotificationManager.sendBitBakeSettingsError("Bitbake binary doesn't exist: " + bitbakeBinPath) + return false } + + const pathToEnvScript = bitBakeProjectScanner.bitbakeDriver.bitbakeSettings.pathToEnvScript + if (!fs.existsSync(pathToEnvScript)) { + serverNotificationManager.sendBitBakeSettingsError("Bitbake environment script doesn't exist: " + pathToEnvScript) + return false + } + + return true } connection.onDidChangeConfiguration((change) => { logger.level = change.settings.bitbake.loggingLevel bitBakeProjectScanner.loadSettings(change.settings.bitbake, workspaceRoot) + checkBitbakeSettingsSanity() bitBakeDocScanner.parseVariablesFile(bitBakeProjectScanner.bitbakeDriver.bitbakeSettings.pathToBitbakeFolder) bitBakeDocScanner.parseVariableFlagFile(bitBakeProjectScanner.bitbakeDriver.bitbakeSettings.pathToBitbakeFolder) - checkBitbakePresence() bitBakeProjectScanner.rescanProject() })