Skip to content

Commit 38989cb

Browse files
committed
get cli port from config
1 parent 134ec15 commit 38989cb

File tree

4 files changed

+47
-39
lines changed

4 files changed

+47
-39
lines changed

arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

+18-15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
import { inject, injectable, postConstruct } from 'inversify';
2+
import * as React from 'react';
3+
import { remote } from 'electron';
4+
import {
5+
BoardsService,
6+
Port,
7+
SketchesService,
8+
ExecutableService,
9+
Sketch,
10+
} from '../common/protocol';
111
import { Mutex } from 'async-mutex';
212
import {
313
MAIN_MENU_BAR,
@@ -40,16 +50,10 @@ import { OutputContribution } from '@theia/output/lib/browser/output-contributio
4050
import { ScmContribution } from '@theia/scm/lib/browser/scm-contribution';
4151
import { SearchInWorkspaceFrontendContribution } from '@theia/search-in-workspace/lib/browser/search-in-workspace-frontend-contribution';
4252
import { TerminalMenus } from '@theia/terminal/lib/browser/terminal-frontend-contribution';
43-
import { inject, injectable, postConstruct } from 'inversify';
44-
import * as React from 'react';
45-
import { remote } from 'electron';
46-
import {
47-
BoardsService,
48-
Port,
49-
SketchesService,
50-
ExecutableService,
51-
Sketch,
52-
} from '../common/protocol';
53+
import { HostedPluginSupport } from '@theia/plugin-ext/lib/hosted/browser/hosted-plugin';
54+
import { FileService } from '@theia/filesystem/lib/browser/file-service';
55+
import { FileChangeType } from '@theia/filesystem/lib/browser';
56+
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
5357
import { ConfigService } from '../common/protocol/config-service';
5458
import { ArduinoCommands } from './arduino-commands';
5559
import { BoardsConfig } from './boards/boards-config';
@@ -60,13 +64,9 @@ import { EditorMode } from './editor-mode';
6064
import { ArduinoMenus } from './menu/arduino-menus';
6165
import { MonitorViewContribution } from './serial/monitor/monitor-view-contribution';
6266
import { ArduinoToolbar } from './toolbar/arduino-toolbar';
63-
import { HostedPluginSupport } from '@theia/plugin-ext/lib/hosted/browser/hosted-plugin';
64-
import { FileService } from '@theia/filesystem/lib/browser/file-service';
6567
import { ArduinoPreferences } from './arduino-preferences';
6668
import { SketchesServiceClientImpl } from '../common/protocol/sketches-service-client-impl';
6769
import { SaveAsSketch } from './contributions/save-as-sketch';
68-
import { FileChangeType } from '@theia/filesystem/lib/browser';
69-
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
7070
import { SketchbookWidgetContribution } from './widgets/sketchbook/sketchbook-widget-contribution';
7171

7272
const INIT_AVR_PACKAGES = 'initializedAvrPackages';
@@ -345,6 +345,9 @@ export class ArduinoFrontendContribution
345345
this.fileService.fsPath(new URI(clangdUri)),
346346
this.fileService.fsPath(new URI(lsUri)),
347347
]);
348+
349+
const config = await this.configService.getConfiguration();
350+
348351
this.languageServerFqbn = await Promise.race([
349352
new Promise<undefined>((_, reject) =>
350353
setTimeout(
@@ -356,7 +359,7 @@ export class ArduinoFrontendContribution
356359
'arduino.languageserver.start',
357360
{
358361
lsPath,
359-
cliDaemonAddr: 'localhost:50051',
362+
cliDaemonAddr: `localhost:${config.daemon.port}`,
360363
clangdPath,
361364
log: currentSketchPath ? currentSketchPath : log,
362365
cliDaemonInstance: '1',

arduino-ide-extension/src/common/protocol/config-service.ts

+26
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { RecursivePartial } from '@theia/core/lib/common/types';
2+
13
export const ConfigServicePath = '/services/config-service';
24
export const ConfigService = Symbol('ConfigService');
35
export interface ConfigService {
@@ -11,6 +13,29 @@ export interface ConfigService {
1113
isInSketchDir(uri: string): Promise<boolean>;
1214
}
1315

16+
export interface Daemon {
17+
readonly port: string | number;
18+
}
19+
export namespace Daemon {
20+
export function is(
21+
daemon: RecursivePartial<Daemon> | undefined
22+
): daemon is Daemon {
23+
return !!daemon && !!daemon.port;
24+
}
25+
export function sameAs(
26+
left: RecursivePartial<Daemon> | undefined,
27+
right: RecursivePartial<Daemon> | undefined
28+
): boolean {
29+
if (left === undefined) {
30+
return right === undefined;
31+
}
32+
if (right === undefined) {
33+
return left === undefined;
34+
}
35+
return String(left.port) === String(right.port);
36+
}
37+
}
38+
1439
export interface ProxySettings {
1540
protocol: string;
1641
hostname: string;
@@ -93,6 +118,7 @@ export interface Config {
93118
readonly downloadsDirUri: string;
94119
readonly additionalUrls: string[];
95120
readonly network: Network;
121+
readonly daemon: Daemon;
96122
}
97123
export namespace Config {
98124
export function sameAs(left: Config, right: Config): boolean {

arduino-ide-extension/src/node/cli-config.ts

+1-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { RecursivePartial } from '@theia/core/lib/common/types';
2+
import { Daemon } from '../common/protocol/config-service';
23

34
export const CLI_CONFIG = 'arduino-cli.yaml';
45

@@ -21,29 +22,6 @@ export namespace BoardManager {
2122
}
2223
}
2324

24-
export interface Daemon {
25-
readonly port: string | number;
26-
}
27-
export namespace Daemon {
28-
export function is(
29-
daemon: RecursivePartial<Daemon> | undefined
30-
): daemon is Daemon {
31-
return !!daemon && !!daemon.port;
32-
}
33-
export function sameAs(
34-
left: RecursivePartial<Daemon> | undefined,
35-
right: RecursivePartial<Daemon> | undefined
36-
): boolean {
37-
if (left === undefined) {
38-
return right === undefined;
39-
}
40-
if (right === undefined) {
41-
return left === undefined;
42-
}
43-
return String(left.port) === String(right.port);
44-
}
45-
}
46-
4725
export interface Directories {
4826
readonly data: string;
4927
readonly downloads: string;

arduino-ide-extension/src/node/config-service-impl.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export class ConfigServiceImpl
216216
protected async mapCliConfigToAppConfig(
217217
cliConfig: DefaultCliConfig
218218
): Promise<Config> {
219-
const { directories, locale = 'en' } = cliConfig;
219+
const { directories, locale = 'en', daemon } = cliConfig;
220220
const { data, user, downloads } = directories;
221221
const additionalUrls: Array<string> = [];
222222
if (cliConfig.board_manager && cliConfig.board_manager.additional_urls) {
@@ -232,6 +232,7 @@ export class ConfigServiceImpl
232232
additionalUrls,
233233
network,
234234
locale,
235+
daemon,
235236
};
236237
}
237238

0 commit comments

Comments
 (0)