mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-06-12 15:16:33 +00:00
Restart the language server when the board is changed
This commit is contained in:
parent
065f9f042b
commit
aa4f216544
@ -1,10 +1,8 @@
|
|||||||
import { injectable, inject, postConstruct } from 'inversify';
|
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 { BoardsServiceClientImpl } from '../boards/boards-service-client-impl';
|
||||||
import { BoardsConfig } from '../boards/boards-config';
|
import { BoardsConfig } from '../boards/boards-config';
|
||||||
|
|
||||||
const SELECTED_BOARD = new NotificationType<BoardsConfig.Config, void>('arduino/selectedBoard');
|
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class ArduinoLanguageClientContribution extends BaseLanguageClientContribution {
|
export class ArduinoLanguageClientContribution extends BaseLanguageClientContribution {
|
||||||
|
|
||||||
@ -19,27 +17,24 @@ export class ArduinoLanguageClientContribution extends BaseLanguageClientContrib
|
|||||||
return ['**/*.ino'];
|
return ['**/*.ino'];
|
||||||
}
|
}
|
||||||
|
|
||||||
private cancelationToken?: CancelationToken;
|
|
||||||
|
|
||||||
@inject(BoardsServiceClientImpl)
|
@inject(BoardsServiceClientImpl)
|
||||||
protected readonly boardsServiceClient: BoardsServiceClientImpl;
|
protected readonly boardsServiceClient: BoardsServiceClientImpl;
|
||||||
|
|
||||||
|
protected boardConfig?: BoardsConfig.Config;
|
||||||
|
|
||||||
@postConstruct()
|
@postConstruct()
|
||||||
protected init() {
|
protected init() {
|
||||||
this.boardsServiceClient.onBoardsConfigChanged(this.selectBoard.bind(this));
|
this.boardsServiceClient.onBoardsConfigChanged(this.selectBoard.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
async selectBoard(config: BoardsConfig.Config): Promise<void> {
|
selectBoard(config: BoardsConfig.Config): void {
|
||||||
// The board configuration may change multiple times before the language client is activated.
|
this.boardConfig = config;
|
||||||
const token: CancelationToken = {};
|
// Force a restart to send the new board config to the language server
|
||||||
this.cancelationToken = token;
|
this.restart();
|
||||||
const lc = await this.languageClient;
|
}
|
||||||
if (this.cancelationToken === token) {
|
|
||||||
lc.sendNotification(SELECTED_BOARD, config);
|
protected getStartParameters(): BoardsConfig.Config | undefined {
|
||||||
this.cancelationToken = undefined;
|
return this.boardConfig;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type CancelationToken = {}
|
|
||||||
|
@ -46,7 +46,8 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
|||||||
bind(BackendApplicationContribution).toService(ArduinoDaemon);
|
bind(BackendApplicationContribution).toService(ArduinoDaemon);
|
||||||
|
|
||||||
// Language server
|
// Language server
|
||||||
bind(LanguageServerContribution).to(ArduinoLanguageServerContribution).inSingletonScope();
|
bind(ArduinoLanguageServerContribution).toSelf().inSingletonScope();
|
||||||
|
bind(LanguageServerContribution).toService(ArduinoLanguageServerContribution);
|
||||||
|
|
||||||
// Library service
|
// Library service
|
||||||
const libraryServiceConnectionModule = ConnectionContainerModule.create(({ bind, bindBackendService }) => {
|
const libraryServiceConnectionModule = ConnectionContainerModule.create(({ bind, bindBackendService }) => {
|
||||||
@ -64,10 +65,9 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
|||||||
});
|
});
|
||||||
bind(ConnectionContainerModule).toConstantValue(sketchesServiceConnectionModule);
|
bind(ConnectionContainerModule).toConstantValue(sketchesServiceConnectionModule);
|
||||||
|
|
||||||
|
// Config service
|
||||||
bind(ConfigServiceImpl).toSelf().inSingletonScope();
|
bind(ConfigServiceImpl).toSelf().inSingletonScope();
|
||||||
bind(ConfigService).toService(ConfigServiceImpl);
|
bind(ConfigService).toService(ConfigServiceImpl);
|
||||||
|
|
||||||
// Config service
|
|
||||||
const configServiceConnectionModule = ConnectionContainerModule.create(({ bind, bindBackendService }) => {
|
const configServiceConnectionModule = ConnectionContainerModule.create(({ bind, bindBackendService }) => {
|
||||||
bindBackendService(ConfigServicePath, ConfigService);
|
bindBackendService(ConfigServicePath, ConfigService);
|
||||||
});
|
});
|
||||||
|
@ -2,7 +2,8 @@ import * as which from 'which';
|
|||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import { join, delimiter } from 'path';
|
import { join, delimiter } from 'path';
|
||||||
import { injectable } from 'inversify';
|
import { injectable } from 'inversify';
|
||||||
import { BaseLanguageServerContribution, IConnection } from '@theia/languages/lib/node';
|
import { BaseLanguageServerContribution, IConnection, LanguageServerStartOptions } from '@theia/languages/lib/node';
|
||||||
|
import { Board } from '../../common/protocol/boards-service';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class ArduinoLanguageServerContribution extends BaseLanguageServerContribution {
|
export class ArduinoLanguageServerContribution extends BaseLanguageServerContribution {
|
||||||
@ -22,12 +23,21 @@ export class ArduinoLanguageServerContribution extends BaseLanguageServerContrib
|
|||||||
return this.description.name;
|
return this.description.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
async start(clientConnection: IConnection): Promise<void> {
|
async start(clientConnection: IConnection, options: LanguageServerStartOptions): Promise<void> {
|
||||||
const clangd = await this.resolveExecutable('clangd');
|
const clangd = await this.resolveExecutable('clangd');
|
||||||
const languageServer = await this.resolveExecutable('arduino-language-server');
|
const languageServer = await this.resolveExecutable('arduino-language-server');
|
||||||
const cli = await this.resolveExecutable('arduino-cli');
|
const cli = await this.resolveExecutable('arduino-cli');
|
||||||
// Add '-log' argument to enable logging to files
|
// Add '-log' argument to enable logging to files
|
||||||
const args: string[] = ['-clangd', clangd, '-cli', cli];
|
const args: string[] = ['-clangd', clangd, '-cli', cli];
|
||||||
|
if (options.parameters && options.parameters.selectedBoard) {
|
||||||
|
const board = options.parameters.selectedBoard as Board;
|
||||||
|
if (board.fqbn) {
|
||||||
|
args.push('-fqbn', board.fqbn);
|
||||||
|
}
|
||||||
|
if (board.name) {
|
||||||
|
args.push('-board-name', `"${board.name}"`);
|
||||||
|
}
|
||||||
|
}
|
||||||
console.log(`Starting language server ${languageServer} ${args.join(' ')}`);
|
console.log(`Starting language server ${languageServer} ${args.join(' ')}`);
|
||||||
const serverConnection = await this.createProcessStreamConnectionAsync(languageServer, args);
|
const serverConnection = await this.createProcessStreamConnectionAsync(languageServer, args);
|
||||||
this.forward(clientConnection, serverConnection);
|
this.forward(clientConnection, serverConnection);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user