Skip to content

Commit 4ea9fb3

Browse files
author
Akos Kitta
committed
moved LS to its own contribution.
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent 7d6bf47 commit 4ea9fb3

File tree

3 files changed

+174
-143
lines changed

3 files changed

+174
-143
lines changed

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

Lines changed: 19 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
1+
import * as remote from '@theia/core/electron-shared/@electron/remote';
12
import {
23
inject,
34
injectable,
45
postConstruct,
56
} from '@theia/core/shared/inversify';
67
import * as React from '@theia/core/shared/react';
7-
import * as remote from '@theia/core/electron-shared/@electron/remote';
88
import {
99
BoardsService,
10-
SketchesService,
11-
ExecutableService,
12-
Sketch,
1310
LibraryService,
14-
ArduinoDaemon,
11+
Sketch,
12+
SketchesService,
1513
} from '../common/protocol';
16-
import { Mutex } from 'async-mutex';
14+
1715
import {
16+
DisposableCollection,
1817
MAIN_MENU_BAR,
1918
MenuContribution,
2019
MenuModelRegistry,
21-
ILogger,
22-
DisposableCollection,
2320
} from '@theia/core';
2421
import {
2522
Dialog,
@@ -31,47 +28,46 @@ import {
3128
StatusBar,
3229
StatusBarAlignment,
3330
} from '@theia/core/lib/browser';
34-
import { nls } from '@theia/core/lib/common';
3531
import { ColorContribution } from '@theia/core/lib/browser/color-application-contribution';
3632
import { ColorRegistry } from '@theia/core/lib/browser/color-registry';
3733
import { CommonMenus } from '@theia/core/lib/browser/common-frontend-contribution';
34+
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
3835
import {
3936
TabBarToolbarContribution,
4037
TabBarToolbarRegistry,
4138
} from '@theia/core/lib/browser/shell/tab-bar-toolbar';
39+
import { nls } from '@theia/core/lib/common';
4240
import {
4341
CommandContribution,
4442
CommandRegistry,
4543
} from '@theia/core/lib/common/command';
4644
import { MessageService } from '@theia/core/lib/common/message-service';
4745
import URI from '@theia/core/lib/common/uri';
4846
import { EditorCommands, EditorMainMenu } from '@theia/editor/lib/browser';
47+
import { FileChangeType } from '@theia/filesystem/lib/browser';
48+
import { FileService } from '@theia/filesystem/lib/browser/file-service';
49+
import { FileSystemFrontendContribution } from '@theia/filesystem/lib/browser/filesystem-frontend-contribution';
4950
import { MonacoMenus } from '@theia/monaco/lib/browser/monaco-menu';
5051
import { FileNavigatorCommands } from '@theia/navigator/lib/browser/navigator-contribution';
5152
import { TerminalMenus } from '@theia/terminal/lib/browser/terminal-frontend-contribution';
52-
import { FileService } from '@theia/filesystem/lib/browser/file-service';
53-
import { FileChangeType } from '@theia/filesystem/lib/browser';
54-
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
53+
import { IDEUpdater } from '../common/protocol/ide-updater';
54+
import {
55+
CurrentSketch,
56+
SketchesServiceClientImpl,
57+
} from '../common/protocol/sketches-service-client-impl';
5558
import { ArduinoCommands } from './arduino-commands';
59+
import { ArduinoPreferences } from './arduino-preferences';
5660
import { BoardsConfig } from './boards/boards-config';
5761
import { BoardsConfigDialog } from './boards/boards-config-dialog';
5862
import { BoardsServiceProvider } from './boards/boards-service-provider';
5963
import { BoardsToolBarItem } from './boards/boards-toolbar-item';
64+
import { OpenSketchFiles } from './contributions/open-sketch-files';
65+
import { SaveAsSketch } from './contributions/save-as-sketch';
66+
import { IDEUpdaterDialog } from './dialogs/ide-updater/ide-updater-dialog';
6067
import { EditorMode } from './editor-mode';
6168
import { ArduinoMenus } from './menu/arduino-menus';
6269
import { MonitorViewContribution } from './serial/monitor/monitor-view-contribution';
6370
import { ArduinoToolbar } from './toolbar/arduino-toolbar';
64-
import { ArduinoPreferences } from './arduino-preferences';
65-
import {
66-
CurrentSketch,
67-
SketchesServiceClientImpl,
68-
} from '../common/protocol/sketches-service-client-impl';
69-
import { SaveAsSketch } from './contributions/save-as-sketch';
70-
import { IDEUpdaterDialog } from './dialogs/ide-updater/ide-updater-dialog';
71-
import { IDEUpdater } from '../common/protocol/ide-updater';
72-
import { FileSystemFrontendContribution } from '@theia/filesystem/lib/browser/filesystem-frontend-contribution';
73-
import { HostedPluginEvents } from './hosted-plugin-events';
74-
import { OpenSketchFiles } from './contributions/open-sketch-files';
7571

7672
const INIT_LIBS_AND_PACKAGES = 'initializedLibsAndPackages';
7773
export const SKIP_IDE_VERSION = 'skipIDEVersion';
@@ -85,9 +81,6 @@ export class ArduinoFrontendContribution
8581
MenuContribution,
8682
ColorContribution
8783
{
88-
@inject(ILogger)
89-
private readonly logger: ILogger;
90-
9184
@inject(MessageService)
9285
private readonly messageService: MessageService;
9386

@@ -118,12 +111,6 @@ export class ArduinoFrontendContribution
118111
@inject(EditorMode)
119112
private readonly editorMode: EditorMode;
120113

121-
@inject(HostedPluginEvents)
122-
private readonly hostedPluginEvents: HostedPluginEvents;
123-
124-
@inject(ExecutableService)
125-
private readonly executableService: ExecutableService;
126-
127114
@inject(ArduinoPreferences)
128115
private readonly arduinoPreferences: ArduinoPreferences;
129116

@@ -145,9 +132,6 @@ export class ArduinoFrontendContribution
145132
@inject(IDEUpdaterDialog)
146133
private readonly updaterDialog: IDEUpdaterDialog;
147134

148-
@inject(ArduinoDaemon)
149-
private readonly daemon: ArduinoDaemon;
150-
151135
protected toDisposeOnStop = new DisposableCollection();
152136

153137
@postConstruct()
@@ -272,27 +256,9 @@ export class ArduinoFrontendContribution
272256
);
273257
});
274258

275-
const start = async ({ selectedBoard }: BoardsConfig.Config) => {
276-
if (selectedBoard) {
277-
const { name, fqbn } = selectedBoard;
278-
if (fqbn) {
279-
this.startLanguageServer(fqbn, name);
280-
}
281-
}
282-
};
283-
this.boardsServiceClientImpl.onBoardsConfigChanged(start);
284-
this.hostedPluginEvents.onPluginsDidStart(() =>
285-
start(this.boardsServiceClientImpl.boardsConfig)
286-
);
287-
this.hostedPluginEvents.onPluginsWillUnload(
288-
() => (this.languageServerFqbn = undefined)
289-
);
290259
this.arduinoPreferences.onPreferenceChanged((event) => {
291260
if (event.newValue !== event.oldValue) {
292261
switch (event.preferenceName) {
293-
case 'arduino.language.log':
294-
start(this.boardsServiceClientImpl.boardsConfig);
295-
break;
296262
case 'arduino.window.zoomLevel':
297263
if (typeof event.newValue === 'number') {
298264
const webContents = remote.getCurrentWebContents();
@@ -340,95 +306,6 @@ export class ArduinoFrontendContribution
340306
this.toDisposeOnStop.dispose();
341307
}
342308

343-
protected languageServerFqbn?: string;
344-
protected languageServerStartMutex = new Mutex();
345-
protected async startLanguageServer(
346-
fqbn: string,
347-
name: string | undefined
348-
): Promise<void> {
349-
const port = await this.daemon.tryGetPort();
350-
if (!port) {
351-
return;
352-
}
353-
const release = await this.languageServerStartMutex.acquire();
354-
try {
355-
await this.hostedPluginEvents.didStart;
356-
const details = await this.boardsService.getBoardDetails({ fqbn });
357-
if (!details) {
358-
// Core is not installed for the selected board.
359-
console.info(
360-
`Could not start language server for ${fqbn}. The core is not installed for the board.`
361-
);
362-
if (this.languageServerFqbn) {
363-
try {
364-
await this.commandRegistry.executeCommand(
365-
'arduino.languageserver.stop'
366-
);
367-
console.info(
368-
`Stopped language server process for ${this.languageServerFqbn}.`
369-
);
370-
this.languageServerFqbn = undefined;
371-
} catch (e) {
372-
console.error(
373-
`Failed to start language server process for ${this.languageServerFqbn}`,
374-
e
375-
);
376-
throw e;
377-
}
378-
}
379-
return;
380-
}
381-
if (fqbn === this.languageServerFqbn) {
382-
// NOOP
383-
return;
384-
}
385-
this.logger.info(`Starting language server: ${fqbn}`);
386-
const log = this.arduinoPreferences.get('arduino.language.log');
387-
let currentSketchPath: string | undefined = undefined;
388-
if (log) {
389-
const currentSketch = await this.sketchServiceClient.currentSketch();
390-
if (CurrentSketch.isValid(currentSketch)) {
391-
currentSketchPath = await this.fileService.fsPath(
392-
new URI(currentSketch.uri)
393-
);
394-
}
395-
}
396-
const { clangdUri, lsUri } = await this.executableService.list();
397-
const [clangdPath, lsPath] = await Promise.all([
398-
this.fileService.fsPath(new URI(clangdUri)),
399-
this.fileService.fsPath(new URI(lsUri)),
400-
]);
401-
402-
this.languageServerFqbn = await Promise.race([
403-
new Promise<undefined>((_, reject) =>
404-
setTimeout(
405-
() => reject(new Error(`Timeout after ${20_000} ms.`)),
406-
20_000
407-
)
408-
),
409-
this.commandRegistry.executeCommand<string>(
410-
'arduino.languageserver.start',
411-
{
412-
lsPath,
413-
cliDaemonAddr: `localhost:${port}`,
414-
clangdPath,
415-
log: currentSketchPath ? currentSketchPath : log,
416-
cliDaemonInstance: '1',
417-
board: {
418-
fqbn,
419-
name: name ? `"${name}"` : undefined,
420-
},
421-
}
422-
),
423-
]);
424-
} catch (e) {
425-
console.log(`Failed to start language server for ${fqbn}`, e);
426-
this.languageServerFqbn = undefined;
427-
} finally {
428-
release();
429-
}
430-
}
431-
432309
registerToolbarItems(registry: TabBarToolbarRegistry): void {
433310
registry.registerItem({
434311
id: BoardsToolBarItem.TOOLBAR_ID,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ import { IndexesUpdateProgress } from './contributions/indexes-update-progress';
306306
import { Daemon } from './contributions/daemon';
307307
import { Notifications } from './contributions/notifications';
308308
import { OpenSketchFiles } from './contributions/open-sketch-files';
309+
import { InoLanguage } from './contributions/ino-language';
309310

310311
MonacoThemingService.register({
311312
id: 'arduino-theme',
@@ -701,9 +702,9 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
701702
Contribution.configure(bind, StartupTasks);
702703
Contribution.configure(bind, IndexesUpdateProgress);
703704
Contribution.configure(bind, Daemon);
704-
Contribution.configure(bind, StartupTasks);
705705
Contribution.configure(bind, Notifications);
706706
Contribution.configure(bind, OpenSketchFiles);
707+
Contribution.configure(bind, InoLanguage);
707708

708709
// Disabled the quick-pick customization from Theia when multiple formatters are available.
709710
// Use the default VS Code behavior, and pick the first one. In the IDE2, clang-format has `exclusive` selectors.

0 commit comments

Comments
 (0)