@@ -20,7 +20,8 @@ import { DisposableCollection } from '@theia/core/lib/common/disposable';
20
20
export class OpenSketchFiles extends SketchContribution {
21
21
override registerCommands ( registry : CommandRegistry ) : void {
22
22
registry . registerCommand ( OpenSketchFiles . Commands . OPEN_SKETCH_FILES , {
23
- execute : ( uri : URI ) => this . openSketchFiles ( uri ) ,
23
+ execute : ( uri : URI , focusMainSketchFile ) =>
24
+ this . openSketchFiles ( uri , focusMainSketchFile ) ,
24
25
} ) ;
25
26
registry . registerCommand ( OpenSketchFiles . Commands . ENSURE_OPENED , {
26
27
execute : (
@@ -33,13 +34,19 @@ export class OpenSketchFiles extends SketchContribution {
33
34
} ) ;
34
35
}
35
36
36
- private async openSketchFiles ( uri : URI ) : Promise < void > {
37
+ private async openSketchFiles (
38
+ uri : URI ,
39
+ focusMainSketchFile = false
40
+ ) : Promise < void > {
37
41
try {
38
42
const sketch = await this . sketchService . loadSketch ( uri . toString ( ) ) ;
39
43
const { mainFileUri, rootFolderFileUris } = sketch ;
40
44
for ( const uri of [ mainFileUri , ...rootFolderFileUris ] ) {
41
45
await this . ensureOpened ( uri ) ;
42
46
}
47
+ if ( focusMainSketchFile ) {
48
+ await this . ensureOpened ( mainFileUri , true , { mode : 'activate' } ) ;
49
+ }
43
50
if ( mainFileUri . endsWith ( '.pde' ) ) {
44
51
const message = nls . localize (
45
52
'arduino/common/oldFormat' ,
@@ -126,7 +133,7 @@ export class OpenSketchFiles extends SketchContribution {
126
133
uri : string ,
127
134
forceOpen = false ,
128
135
options ?: EditorOpenerOptions
129
- ) : Promise < unknown > {
136
+ ) : Promise < EditorWidget | undefined > {
130
137
const widget = this . editorManager . all . find (
131
138
( widget ) => widget . editor . uri . toString ( ) === uri
132
139
) ;
@@ -190,17 +197,18 @@ export class OpenSketchFiles extends SketchContribution {
190
197
} ) ;
191
198
192
199
const timeout = 5_000 ; // number of ms IDE2 waits for the editor to show up in the UI
193
- const result = await Promise . race ( [
200
+ const result : EditorWidget | undefined | 'timeout' = await Promise . race ( [
194
201
deferred . promise ,
195
202
wait ( timeout ) . then ( ( ) => {
196
203
disposables . dispose ( ) ;
197
- return 'timeout' ;
204
+ return 'timeout' as const ;
198
205
} ) ,
199
206
] ) ;
200
207
if ( result === 'timeout' ) {
201
208
console . warn (
202
209
`Timeout after ${ timeout } millis. The editor has not shown up in time. URI: ${ uri } `
203
210
) ;
211
+ return undefined ;
204
212
}
205
213
return result ;
206
214
}
0 commit comments