ATL-222: Moved the language feature to a VS Code extension.

Updated to next Theia: 1.6.0-next.b43a1623.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta
2020-09-08 13:15:55 +02:00
committed by Akos Kitta
parent fbebfc7cca
commit f26dae185b
30 changed files with 1368 additions and 3575 deletions

View File

@@ -5,8 +5,6 @@ import { ContainerModule } from 'inversify';
import { ArduinoDaemonImpl } from './arduino-daemon-impl';
import { ILogger } from '@theia/core/lib/common/logger';
import { BackendApplicationContribution } from '@theia/core/lib/node/backend-application';
import { LanguageServerContribution } from '@theia/languages/lib/node';
import { ArduinoLanguageServerContribution } from './language/arduino-language-server-contribution';
import { LibraryServiceServerPath, LibraryServiceServer, LibraryServiceClient } from '../common/protocol/library-service';
import { BoardsService, BoardsServicePath, BoardsServiceClient } from '../common/protocol/boards-service';
import { LibraryServiceServerImpl } from './library-service-server-impl';
@@ -37,6 +35,8 @@ import { NodeFileSystemExt } from './node-filesystem-ext';
import { FileSystemExt, FileSystemExtPath } from '../common/protocol/filesystem-ext';
import { ExamplesServiceImpl } from './examples-service-impl';
import { ExamplesService, ExamplesServicePath } from '../common/protocol/examples-service';
import { ExecutableService, ExecutableServicePath } from '../common/protocol/executable-service';
import { ExecutableServiceImpl } from './executable-service-impl';
export default new ContainerModule((bind, unbind, isBound, rebind) => {
rebind(EnvVariablesServer).to(ArduinoEnvVariablesServer).inSingletonScope();
@@ -73,9 +73,10 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(ExamplesService).toService(ExamplesServiceImpl);
bind(ConnectionHandler).toDynamicValue(context => new JsonRpcConnectionHandler(ExamplesServicePath, () => context.container.get(ExamplesService))).inSingletonScope();
// Language server
bind(ArduinoLanguageServerContribution).toSelf().inSingletonScope();
bind(LanguageServerContribution).toService(ArduinoLanguageServerContribution);
// Exposes the executable paths/URIs to the frontend
bind(ExecutableServiceImpl).toSelf().inSingletonScope();
bind(ExecutableService).toService(ExecutableServiceImpl);
bind(ConnectionHandler).toDynamicValue(context => new JsonRpcConnectionHandler(ExecutableServicePath, () => context.container.get(ExecutableService))).inSingletonScope();
// Library service
bind(LibraryServiceServerImpl).toSelf().inSingletonScope();

View File

@@ -1,5 +1,5 @@
import { inject, injectable, postConstruct } from 'inversify';
import { FileSystem } from '@theia/filesystem/lib/common/filesystem';
import { FileUri } from '@theia/core/lib/node/file-uri';
import { CoreService, CoreServiceClient } from '../common/protocol/core-service';
import { CompileReq, CompileResp } from './cli-protocol/commands/compile_pb';
import { BoardsService } from '../common/protocol/boards-service';
@@ -14,8 +14,6 @@ export class CoreServiceImpl implements CoreService {
@inject(CoreClientProvider)
protected readonly coreClientProvider: CoreClientProvider;
@inject(FileSystem)
protected readonly fileSystem: FileSystem;
@inject(BoardsService)
protected readonly boardsService: BoardsService;
@@ -37,10 +35,7 @@ export class CoreServiceImpl implements CoreService {
async compile(options: CoreService.Compile.Options): Promise<void> {
this.toolOutputService.append({ tool: 'compile', chunk: 'Compiling...\n' + JSON.stringify(options, null, 2) + '\n--------------------------\n' });
const { sketchUri, fqbn } = options;
const sketchFilePath = await this.fileSystem.getFsPath(sketchUri);
if (!sketchFilePath) {
throw new Error(`Cannot resolve filesystem path for URI: ${sketchUri}.`);
}
const sketchFilePath = FileUri.fsPath(sketchUri);
const sketchpath = path.dirname(sketchFilePath);
const coreClient = await this.coreClientProvider.client();
@@ -83,10 +78,7 @@ export class CoreServiceImpl implements CoreService {
await this.compile(options);
this.toolOutputService.append({ tool: 'upload', chunk: 'Uploading...\n' + JSON.stringify(options, null, 2) + '\n--------------------------\n' });
const { sketchUri, fqbn } = options;
const sketchFilePath = await this.fileSystem.getFsPath(sketchUri);
if (!sketchFilePath) {
throw new Error(`Cannot resolve filesystem path for URI: ${sketchUri}.`);
}
const sketchFilePath = FileUri.fsPath(sketchUri);
const sketchpath = path.dirname(sketchFilePath);
const coreClient = await this.coreClientProvider.client();

View File

@@ -0,0 +1,31 @@
import * as os from 'os';
import { injectable, inject } from 'inversify';
import { ILogger } from '@theia/core/lib/common/logger';
import { FileUri } from '@theia/core/lib/node/file-uri';
import { getExecPath } from './exec-util';
import { ExecutableService } from '../common/protocol/executable-service';
@injectable()
export class ExecutableServiceImpl implements ExecutableService {
@inject(ILogger)
protected logger: ILogger;
async list(): Promise<{ clangdUri: string, cliUri: string, lsUri: string }> {
const [ls, clangd, cli] = await Promise.all([
getExecPath('arduino-language-server', this.onError.bind(this)),
getExecPath('clangd', this.onError.bind(this), '--version', os.platform() !== 'win32'),
getExecPath('arduino-cli', this.onError.bind(this))
]);
return {
clangdUri: FileUri.create(clangd).toString(),
cliUri: FileUri.create(cli).toString(),
lsUri: FileUri.create(ls).toString()
};
}
protected onError(error: Error): void {
this.logger.error(error);
}
}

View File

@@ -1,55 +0,0 @@
import * as os from 'os';
import { injectable, inject } from 'inversify';
import { ILogger } from '@theia/core';
import { BaseLanguageServerContribution, IConnection, LanguageServerStartOptions } from '@theia/languages/lib/node';
import { Board } from '../../common/protocol/boards-service';
import { getExecPath } from '../exec-util';
@injectable()
export class ArduinoLanguageServerContribution extends BaseLanguageServerContribution {
readonly description = {
id: 'ino',
name: 'Arduino',
documentSelector: ['ino'],
fileEvents: ['**/*.ino']
}
get id() {
return this.description.id;
}
get name() {
return this.description.name;
}
@inject(ILogger)
protected logger: ILogger;
async start(clientConnection: IConnection, options: LanguageServerStartOptions): Promise<void> {
const [languageServer, clangd, cli] = await Promise.all([
getExecPath('arduino-language-server', this.onError.bind(this)),
getExecPath('clangd', this.onError.bind(this), '--version', os.platform() !== 'win32'),
getExecPath('arduino-cli', this.onError.bind(this))
]);
// Add '-log' argument to enable logging to files
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(' ')}`);
const serverConnection = await this.createProcessStreamConnectionAsync(languageServer, args);
this.forward(clientConnection, serverConnection);
}
protected onError(error: Error): void {
this.logger.error(error);
}
}