mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-12 11:49:27 +00:00
Restart the language server when the board is changed
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import { injectable, inject, postConstruct } from 'inversify';
|
||||
import { BaseLanguageClientContribution, NotificationType } from '@theia/languages/lib/browser';
|
||||
import { BaseLanguageClientContribution } from '@theia/languages/lib/browser';
|
||||
import { BoardsServiceClientImpl } from '../boards/boards-service-client-impl';
|
||||
import { BoardsConfig } from '../boards/boards-config';
|
||||
|
||||
const SELECTED_BOARD = new NotificationType<BoardsConfig.Config, void>('arduino/selectedBoard');
|
||||
|
||||
@injectable()
|
||||
export class ArduinoLanguageClientContribution extends BaseLanguageClientContribution {
|
||||
|
||||
@@ -19,27 +17,24 @@ export class ArduinoLanguageClientContribution extends BaseLanguageClientContrib
|
||||
return ['**/*.ino'];
|
||||
}
|
||||
|
||||
private cancelationToken?: CancelationToken;
|
||||
|
||||
@inject(BoardsServiceClientImpl)
|
||||
protected readonly boardsServiceClient: BoardsServiceClientImpl;
|
||||
|
||||
protected boardConfig?: BoardsConfig.Config;
|
||||
|
||||
@postConstruct()
|
||||
protected init() {
|
||||
this.boardsServiceClient.onBoardsConfigChanged(this.selectBoard.bind(this));
|
||||
}
|
||||
|
||||
async selectBoard(config: BoardsConfig.Config): Promise<void> {
|
||||
// The board configuration may change multiple times before the language client is activated.
|
||||
const token: CancelationToken = {};
|
||||
this.cancelationToken = token;
|
||||
const lc = await this.languageClient;
|
||||
if (this.cancelationToken === token) {
|
||||
lc.sendNotification(SELECTED_BOARD, config);
|
||||
this.cancelationToken = undefined;
|
||||
}
|
||||
selectBoard(config: BoardsConfig.Config): void {
|
||||
this.boardConfig = config;
|
||||
// Force a restart to send the new board config to the language server
|
||||
this.restart();
|
||||
}
|
||||
|
||||
protected getStartParameters(): BoardsConfig.Config | undefined {
|
||||
return this.boardConfig;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type CancelationToken = {}
|
||||
|
||||
Reference in New Issue
Block a user