diff --git a/arduino-ide-extension/package.json b/arduino-ide-extension/package.json index f6f09af97..f353e961f 100644 --- a/arduino-ide-extension/package.json +++ b/arduino-ide-extension/package.json @@ -169,13 +169,13 @@ ], "arduino": { "arduino-cli": { - "version": "0.35.1" + "version": "0.35.2" }, "arduino-fwuploader": { "version": "2.4.1" }, "arduino-language-server": { - "version": "0.7.5" + "version": "0.7.6" }, "clangd": { "version": "14.0.0" diff --git a/arduino-ide-extension/src/browser/arduino-preferences.ts b/arduino-ide-extension/src/browser/arduino-preferences.ts index f2c83a7f6..bc9cdb099 100644 --- a/arduino-ide-extension/src/browser/arduino-preferences.ts +++ b/arduino-ide-extension/src/browser/arduino-preferences.ts @@ -54,6 +54,10 @@ export function isMonitorWidgetDockPanel( return arg === 'bottom' || arg === 'right'; } +export const defaultAsyncWorkers = 0 as const; +export const minAsyncWorkers = defaultAsyncWorkers; +export const maxAsyncWorkers = 8 as const; + type StrictPreferenceSchemaProperties = { [p in keyof T]: PreferenceSchemaProperty; }; @@ -79,6 +83,16 @@ const properties: ArduinoPreferenceSchemaProperties = { ), default: false, }, + 'arduino.language.asyncWorkers': { + type: 'number', + description: nls.localize( + 'arduino/preferences/language.asyncWorkers', + 'Number of async workers used by the Arduino Language Server (clangd). Background index also uses this many workers. The minimum value is 0, and the maximum is 8. When it is 0, the language server uses all available cores. The default value is 0.' + ), + minimum: minAsyncWorkers, + maximum: maxAsyncWorkers, + default: defaultAsyncWorkers, + }, 'arduino.compile.verbose': { type: 'boolean', description: nls.localize( @@ -298,6 +312,7 @@ export const ArduinoConfigSchema: PreferenceSchema = { export interface ArduinoConfiguration { 'arduino.language.log': boolean; 'arduino.language.realTimeDiagnostics': boolean; + 'arduino.language.asyncWorkers': number; 'arduino.compile.verbose': boolean; 'arduino.compile.experimental': boolean; 'arduino.compile.revealRange': ErrorRevealStrategy; diff --git a/arduino-ide-extension/src/browser/contributions/ino-language.ts b/arduino-ide-extension/src/browser/contributions/ino-language.ts index 5d1fe4638..ab54c7ae4 100644 --- a/arduino-ide-extension/src/browser/contributions/ino-language.ts +++ b/arduino-ide-extension/src/browser/contributions/ino-language.ts @@ -6,19 +6,24 @@ import { inject, injectable } from '@theia/core/shared/inversify'; import { Mutex } from 'async-mutex'; import { ArduinoDaemon, - assertSanitizedFqbn, BoardIdentifier, BoardsService, ExecutableService, + assertSanitizedFqbn, isBoardIdentifierChangeEvent, sanitizeFqbn, } from '../../common/protocol'; -import { CurrentSketch } from '../sketches-service-client-impl'; +import { + defaultAsyncWorkers, + maxAsyncWorkers, + minAsyncWorkers, +} from '../arduino-preferences'; +import { BoardsDataStore } from '../boards/boards-data-store'; import { BoardsServiceProvider } from '../boards/boards-service-provider'; import { HostedPluginEvents } from '../hosted/hosted-plugin-events'; import { NotificationCenter } from '../notification-center'; +import { CurrentSketch } from '../sketches-service-client-impl'; import { SketchContribution, URI } from './contribution'; -import { BoardsDataStore } from '../boards/boards-data-store'; interface DaemonAddress { /** @@ -76,6 +81,10 @@ interface StartLanguageServerParams { * If `true`, the logging is not forwarded to the _Output_ view via the language client. */ readonly silentOutput?: boolean; + /** + * Number of async workers used by `clangd`. Background index also uses this many workers. If `0`, `clangd` uses all available cores. It's `0` by default. + */ + readonly jobs?: number; } /** @@ -137,6 +146,7 @@ export class InoLanguage extends SketchContribution { switch (preferenceName) { case 'arduino.language.log': case 'arduino.language.realTimeDiagnostics': + case 'arduino.language.asyncWorkers': forceRestart(); } } @@ -168,9 +178,12 @@ export class InoLanguage extends SketchContribution { } }), ]); - this.boardsServiceProvider.ready.then(() => - start(this.boardsServiceProvider.boardsConfig.selectedBoard) - ); + Promise.all([ + this.boardsServiceProvider.ready, + this.preferences.ready, + ]).then(() => { + start(this.boardsServiceProvider.boardsConfig.selectedBoard); + }); } onStop(): void { @@ -230,11 +243,16 @@ export class InoLanguage extends SketchContribution { // NOOP return; } - this.logger.info(`Starting language server: ${fqbnWithConfig}`); const log = this.preferences.get('arduino.language.log'); const realTimeDiagnostics = this.preferences.get( 'arduino.language.realTimeDiagnostics' ); + const jobs = this.getAsyncWorkersPreferenceSafe(); + this.logger.info( + `Starting language server: ${fqbnWithConfig}${ + jobs ? ` (async worker count: ${jobs})` : '' + }` + ); let currentSketchPath: string | undefined = undefined; if (log) { const currentSketch = await this.sketchServiceClient.currentSketch(); @@ -273,6 +291,7 @@ export class InoLanguage extends SketchContribution { }, realTimeDiagnostics, silentOutput: true, + jobs, }), ]); } catch (e) { @@ -283,6 +302,21 @@ export class InoLanguage extends SketchContribution { release(); } } + // The Theia preference UI validation is bogus. + // To restrict the number of jobs to a valid value. + private getAsyncWorkersPreferenceSafe(): number { + const jobs = this.preferences.get( + 'arduino.language.asyncWorkers', + defaultAsyncWorkers + ); + if (jobs < minAsyncWorkers) { + return minAsyncWorkers; + } + if (jobs > maxAsyncWorkers) { + return maxAsyncWorkers; + } + return jobs; + } private async start( params: StartLanguageServerParams diff --git a/electron-app/package.json b/electron-app/package.json index de1249641..d8a106c05 100644 --- a/electron-app/package.json +++ b/electron-app/package.json @@ -196,7 +196,7 @@ "theiaPlugins": { "vscode-builtin-cpp": "https://open-vsx.org/api/vscode/cpp/1.52.1/file/vscode.cpp-1.52.1.vsix", "vscode-arduino-api": "https://github.com/dankeboy36/vscode-arduino-api/releases/download/0.1.2/vscode-arduino-api-0.1.2.vsix", - "vscode-arduino-tools": "https://downloads.arduino.cc/vscode-arduino-tools/vscode-arduino-tools-0.1.1.vsix", + "vscode-arduino-tools": "https://downloads.arduino.cc/vscode-arduino-tools/vscode-arduino-tools-0.1.2.vsix", "vscode-builtin-json": "https://open-vsx.org/api/vscode/json/1.46.1/file/vscode.json-1.46.1.vsix", "vscode-builtin-json-language-features": "https://open-vsx.org/api/vscode/json-language-features/1.46.1/file/vscode.json-language-features-1.46.1.vsix", "cortex-debug": "https://downloads.arduino.cc/marus25.cortex-debug/marus25.cortex-debug-1.5.1.vsix", diff --git a/i18n/en.json b/i18n/en.json index 0f09cc75a..841ab3a91 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -385,6 +385,7 @@ "invalid.editorFontSize": "Invalid editor font size. It must be a positive integer.", "invalid.sketchbook.location": "Invalid sketchbook location: {0}", "invalid.theme": "Invalid theme.", + "language.asyncWorkers": "Number of async workers used by the Arduino Language Server (clangd). Background index also uses this many workers. The minimum value is 0, and the maximum is 8. When it is 0, the language server uses all available cores. The default value is 0.", "language.log": "True if the Arduino Language Server should generate log files into the sketch folder. Otherwise, false. It's false by default.", "language.realTimeDiagnostics": "If true, the language server provides real-time diagnostics when typing in the editor. It's false by default.", "manualProxy": "Manual proxy configuration",