1
+ import * as remote from '@theia/core/electron-shared/@electron/remote' ;
1
2
import {
2
3
inject ,
3
4
injectable ,
4
5
postConstruct ,
5
6
} from '@theia/core/shared/inversify' ;
6
7
import * as React from '@theia/core/shared/react' ;
7
- import * as remote from '@theia/core/electron-shared/@electron/remote' ;
8
8
import {
9
9
BoardsService ,
10
- SketchesService ,
11
- ExecutableService ,
12
- Sketch ,
13
10
LibraryService ,
14
- ArduinoDaemon ,
11
+ Sketch ,
12
+ SketchesService ,
15
13
} from '../common/protocol' ;
16
- import { Mutex } from 'async-mutex' ;
14
+
17
15
import {
16
+ DisposableCollection ,
18
17
MAIN_MENU_BAR ,
19
18
MenuContribution ,
20
19
MenuModelRegistry ,
21
- ILogger ,
22
- DisposableCollection ,
23
20
} from '@theia/core' ;
24
21
import {
25
22
Dialog ,
@@ -31,47 +28,46 @@ import {
31
28
StatusBar ,
32
29
StatusBarAlignment ,
33
30
} from '@theia/core/lib/browser' ;
34
- import { nls } from '@theia/core/lib/common' ;
35
31
import { ColorContribution } from '@theia/core/lib/browser/color-application-contribution' ;
36
32
import { ColorRegistry } from '@theia/core/lib/browser/color-registry' ;
37
33
import { CommonMenus } from '@theia/core/lib/browser/common-frontend-contribution' ;
34
+ import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state' ;
38
35
import {
39
36
TabBarToolbarContribution ,
40
37
TabBarToolbarRegistry ,
41
38
} from '@theia/core/lib/browser/shell/tab-bar-toolbar' ;
39
+ import { nls } from '@theia/core/lib/common' ;
42
40
import {
43
41
CommandContribution ,
44
42
CommandRegistry ,
45
43
} from '@theia/core/lib/common/command' ;
46
44
import { MessageService } from '@theia/core/lib/common/message-service' ;
47
45
import URI from '@theia/core/lib/common/uri' ;
48
46
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' ;
49
50
import { MonacoMenus } from '@theia/monaco/lib/browser/monaco-menu' ;
50
51
import { FileNavigatorCommands } from '@theia/navigator/lib/browser/navigator-contribution' ;
51
52
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' ;
55
58
import { ArduinoCommands } from './arduino-commands' ;
59
+ import { ArduinoPreferences } from './arduino-preferences' ;
56
60
import { BoardsConfig } from './boards/boards-config' ;
57
61
import { BoardsConfigDialog } from './boards/boards-config-dialog' ;
58
62
import { BoardsServiceProvider } from './boards/boards-service-provider' ;
59
63
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' ;
60
67
import { EditorMode } from './editor-mode' ;
61
68
import { ArduinoMenus } from './menu/arduino-menus' ;
62
69
import { MonitorViewContribution } from './serial/monitor/monitor-view-contribution' ;
63
70
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' ;
75
71
76
72
const INIT_LIBS_AND_PACKAGES = 'initializedLibsAndPackages' ;
77
73
export const SKIP_IDE_VERSION = 'skipIDEVersion' ;
@@ -85,9 +81,6 @@ export class ArduinoFrontendContribution
85
81
MenuContribution ,
86
82
ColorContribution
87
83
{
88
- @inject ( ILogger )
89
- private readonly logger : ILogger ;
90
-
91
84
@inject ( MessageService )
92
85
private readonly messageService : MessageService ;
93
86
@@ -118,12 +111,6 @@ export class ArduinoFrontendContribution
118
111
@inject ( EditorMode )
119
112
private readonly editorMode : EditorMode ;
120
113
121
- @inject ( HostedPluginEvents )
122
- private readonly hostedPluginEvents : HostedPluginEvents ;
123
-
124
- @inject ( ExecutableService )
125
- private readonly executableService : ExecutableService ;
126
-
127
114
@inject ( ArduinoPreferences )
128
115
private readonly arduinoPreferences : ArduinoPreferences ;
129
116
@@ -145,9 +132,6 @@ export class ArduinoFrontendContribution
145
132
@inject ( IDEUpdaterDialog )
146
133
private readonly updaterDialog : IDEUpdaterDialog ;
147
134
148
- @inject ( ArduinoDaemon )
149
- private readonly daemon : ArduinoDaemon ;
150
-
151
135
protected toDisposeOnStop = new DisposableCollection ( ) ;
152
136
153
137
@postConstruct ( )
@@ -272,27 +256,9 @@ export class ArduinoFrontendContribution
272
256
) ;
273
257
} ) ;
274
258
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
- ) ;
290
259
this . arduinoPreferences . onPreferenceChanged ( ( event ) => {
291
260
if ( event . newValue !== event . oldValue ) {
292
261
switch ( event . preferenceName ) {
293
- case 'arduino.language.log' :
294
- start ( this . boardsServiceClientImpl . boardsConfig ) ;
295
- break ;
296
262
case 'arduino.window.zoomLevel' :
297
263
if ( typeof event . newValue === 'number' ) {
298
264
const webContents = remote . getCurrentWebContents ( ) ;
@@ -340,95 +306,6 @@ export class ArduinoFrontendContribution
340
306
this . toDisposeOnStop . dispose ( ) ;
341
307
}
342
308
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
-
432
309
registerToolbarItems ( registry : TabBarToolbarRegistry ) : void {
433
310
registry . registerItem ( {
434
311
id : BoardsToolBarItem . TOOLBAR_ID ,
0 commit comments