Restart the language server when the board is changed

This commit is contained in:
Miro Spönemann
2019-10-02 13:16:10 +02:00
parent 065f9f042b
commit aa4f216544
3 changed files with 26 additions and 21 deletions

View File

@@ -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 = {}