Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7d04c7e

Browse files
committedSep 6, 2019
Added language contribution for ino files
1 parent fb542e2 commit 7d04c7e

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed
 

‎arduino-ide-extension/src/browser/arduino-frontend-module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { TabBarToolbarContribution } from '@theia/core/lib/browser/shell/tab-bar
77
import { WebSocketConnectionProvider } from '@theia/core/lib/browser/messaging/ws-connection-provider';
88
import { FrontendApplicationContribution, FrontendApplication } from '@theia/core/lib/browser/frontend-application'
99
import { LanguageGrammarDefinitionContribution } from '@theia/monaco/lib/browser/textmate';
10+
import { LanguageClientContribution } from '@theia/languages/lib/browser';
11+
import { ArduinoLanguageClientContribution } from './language/arduino-language-client-contribution';
1012
import { LibraryListWidget } from './library/library-list-widget';
1113
import { ArduinoFrontendContribution, ArduinoAdvancedMode } from './arduino-frontend-contribution';
1214
import { ArduinoLanguageGrammarContribution } from './language/arduino-language-grammar-contribution';
@@ -78,8 +80,9 @@ export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Un
7880
bind(ArduinoToolbarContribution).toSelf().inSingletonScope();
7981
bind(FrontendApplicationContribution).toService(ArduinoToolbarContribution);
8082

81-
// `ino` TextMate grammar
83+
// `ino` TextMate grammar and language client
8284
bind(LanguageGrammarDefinitionContribution).to(ArduinoLanguageGrammarContribution).inSingletonScope();
85+
bind(LanguageClientContribution).to(ArduinoLanguageClientContribution).inSingletonScope();
8386

8487
// Library service
8588
bind(LibraryService).toDynamicValue(context => WebSocketConnectionProvider.createProxy(context.container, LibraryServicePath)).inSingletonScope();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { injectable } from 'inversify';
2+
import { BaseLanguageClientContribution } from '@theia/languages/lib/browser';
3+
4+
@injectable()
5+
export class ArduinoLanguageClientContribution extends BaseLanguageClientContribution {
6+
7+
readonly id = 'ino'
8+
readonly name = 'Arduino'
9+
10+
protected get documentSelector(): string[] {
11+
return ['ino'];
12+
}
13+
14+
protected get globPatterns() {
15+
return ['**/*.ino']
16+
}
17+
18+
}

‎arduino-ide-extension/src/node/arduino-backend-module.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { ContainerModule } from 'inversify';
22
import { ArduinoDaemon } from './arduino-daemon';
33
import { ILogger } from '@theia/core/lib/common/logger';
44
import { BackendApplicationContribution } from '@theia/core/lib/node/backend-application';
5+
import { LanguageServerContribution } from '@theia/languages/lib/node';
6+
import { ArduinoLanguageServerContribution } from './language/arduino-language-server-contribution';
57
import { LibraryService, LibraryServicePath } from '../common/protocol/library-service';
68
import { BoardsService, BoardsServicePath, BoardsServiceClient } from '../common/protocol/boards-service';
79
import { LibraryServiceImpl } from './library-service-impl';
@@ -40,6 +42,9 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
4042
bind(ArduinoDaemon).toSelf().inSingletonScope();
4143
bind(BackendApplicationContribution).toService(ArduinoDaemon);
4244

45+
// Language server
46+
bind(LanguageServerContribution).to(ArduinoLanguageServerContribution).inSingletonScope();
47+
4348
// Library service
4449
const libraryServiceConnectionModule = ConnectionContainerModule.create(({ bind, bindBackendService }) => {
4550
bind(LibraryServiceImpl).toSelf().inSingletonScope();
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import * as which from 'which';
2+
import * as os from 'os';
3+
import { join, delimiter } from 'path';
4+
import { injectable } from 'inversify';
5+
import { BaseLanguageServerContribution, IConnection } from '@theia/languages/lib/node';
6+
7+
@injectable()
8+
export class ArduinoLanguageServerContribution extends BaseLanguageServerContribution {
9+
10+
readonly description = {
11+
id: 'ino',
12+
name: 'Arduino',
13+
documentSelector: ['ino'],
14+
fileEvents: ['**/*.ino']
15+
}
16+
17+
get id() {
18+
return this.description.id;
19+
}
20+
21+
get name() {
22+
return this.description.name;
23+
}
24+
25+
async start(clientConnection: IConnection): Promise<void> {
26+
const clangd = await this.resolveExecutable('clangd')
27+
const languageServer = await this.resolveExecutable('arduino-language-server')
28+
// Add '-log' argument to enable logging to files
29+
const args: string[] = ['-clangd', clangd]
30+
console.log(`Starting language server ${languageServer} ${args.join(' ')}`)
31+
const serverConnection = await this.createProcessStreamConnectionAsync(languageServer, args)
32+
this.forward(clientConnection, serverConnection)
33+
}
34+
35+
protected resolveExecutable(name: string): Promise<string> {
36+
return new Promise<string>((resolve, reject) => {
37+
const path = `${process.env.PATH}${delimiter}${join(__dirname, '..', '..', '..', 'build')}`;
38+
const suffix = os.platform() === 'win32' ? '.exe' : '';
39+
which(name + suffix, { path }, (err, execPath) => {
40+
if (err) {
41+
reject(err);
42+
} else {
43+
resolve(execPath);
44+
}
45+
});
46+
});
47+
}
48+
}

0 commit comments

Comments
 (0)
Please sign in to comment.