Merge pull request #64 from bcmi-labs/msp_sendBoardConfig

Added JSON-RPC message to send the board configuration to the language server
This commit is contained in:
Miro Spönemann 2019-09-25 09:12:59 +02:00 committed by GitHub
commit ed4f23a32a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,18 +1,45 @@
import { injectable } from 'inversify';
import { BaseLanguageClientContribution } from '@theia/languages/lib/browser';
import { injectable, inject, postConstruct } from 'inversify';
import { BaseLanguageClientContribution, NotificationType } 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 {
readonly id = 'ino'
readonly name = 'Arduino'
readonly id = 'ino';
readonly name = 'Arduino';
protected get documentSelector(): string[] {
return ['ino'];
}
protected get globPatterns() {
return ['**/*.ino']
return ['**/*.ino'];
}
private cancelationToken?: CancelationToken;
@inject(BoardsServiceClientImpl)
protected readonly boardsServiceClient: BoardsServiceClientImpl;
@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;
}
}
}
type CancelationToken = {}