@@ -2,7 +2,7 @@ import { nls } from '@theia/core/lib/common/nls';
2
2
import { inject , injectable } from '@theia/core/shared/inversify' ;
3
3
import type { EditorOpenerOptions } from '@theia/editor/lib/browser/editor-manager' ;
4
4
import { Later } from '../../common/nls' ;
5
- import { SketchesError } from '../../common/protocol' ;
5
+ import { Sketch , SketchesError } from '../../common/protocol' ;
6
6
import {
7
7
Command ,
8
8
CommandRegistry ,
@@ -66,12 +66,20 @@ export class OpenSketchFiles extends SketchContribution {
66
66
} ) ;
67
67
}
68
68
const { workspaceError } = this . workspaceService ;
69
+ // This happens when the IDE2 has been started from a terminal with a /path/to/invalid/sketch. (#964)
70
+ // Or user has started the IDE2 from clicking on an `ino` file.
69
71
if ( SketchesError . InvalidName . is ( workspaceError ) ) {
70
- return this . promptMove ( workspaceError ) ;
72
+ await this . promptMove ( workspaceError ) ;
71
73
}
72
74
} catch ( err ) {
75
+ // This happens when the user gracefully closed IDE2, all went well
76
+ // but the main sketch file or the sketch folder was modified and when user restarts the IDE2
77
+ // the sketch path is not valid anymore. (#964)
73
78
if ( SketchesError . InvalidName . is ( err ) ) {
74
- return this . promptMove ( err ) ;
79
+ const movedSketch = await this . promptMove ( err ) ;
80
+ if ( ! movedSketch ) {
81
+ return this . openFallbackSketch ( ) ;
82
+ }
75
83
}
76
84
77
85
if ( SketchesError . NotFound . is ( err ) ) {
@@ -96,7 +104,7 @@ export class OpenSketchFiles extends SketchContribution {
96
104
invalidMainSketchUri : string ;
97
105
}
98
106
>
99
- ) : Promise < void > {
107
+ ) : Promise < Sketch | undefined > {
100
108
const { invalidMainSketchUri } = err . data ;
101
109
requestAnimationFrame ( ( ) => this . messageService . error ( err . message ) ) ;
102
110
await wait ( 10 ) ; // let IDE2 toast the error message.
@@ -106,10 +114,12 @@ export class OpenSketchFiles extends SketchContribution {
106
114
labelProvider : this . labelProvider ,
107
115
} ) ;
108
116
if ( movedSketch ) {
109
- return this . workspaceService . open ( new URI ( movedSketch . uri ) , {
117
+ this . workspaceService . open ( new URI ( movedSketch . uri ) , {
110
118
preserveWindow : true ,
111
119
} ) ;
120
+ return movedSketch ;
112
121
}
122
+ return undefined ;
113
123
}
114
124
115
125
private async openFallbackSketch ( ) : Promise < void > {
0 commit comments