@@ -39,6 +39,7 @@ export class Session {
39
39
private readonly connection : lsp . IConnection ;
40
40
private readonly projectService : ProjectService ;
41
41
private diagnosticsTimeout : NodeJS . Timeout | null = null ;
42
+ private isProjectLoading = false ;
42
43
43
44
constructor ( options : SessionOptions ) {
44
45
// Create a connection for the server. The connection uses Node's IPC as a transport.
@@ -79,14 +80,17 @@ export class Session {
79
80
private handleProjectServiceEvent ( event : ts . server . ProjectServiceEvent ) {
80
81
switch ( event . eventName ) {
81
82
case ts . server . ProjectLoadingStartEvent :
82
- this . connection . sendNotification (
83
- projectLoadingNotification . start , event . data . project . projectName ) ;
83
+ this . isProjectLoading = true ;
84
+ this . connection . sendNotification ( projectLoadingNotification . start ) ;
84
85
break ;
85
86
case ts . server . ProjectLoadingFinishEvent : {
86
87
const { project} = event . data ;
87
88
// Disable language service if project is not Angular
88
89
this . checkIsAngularProject ( project ) ;
89
- this . connection . sendNotification ( projectLoadingNotification . finish , project . projectName ) ;
90
+ if ( this . isProjectLoading ) {
91
+ this . isProjectLoading = false ;
92
+ this . connection . sendNotification ( projectLoadingNotification . finish ) ;
93
+ }
90
94
break ;
91
95
}
92
96
case ts . server . ProjectsUpdatedInBackgroundEvent :
@@ -172,24 +176,35 @@ export class Session {
172
176
// is up-to-date when a file is first opened in the editor.
173
177
// In this case, we should not pass fileContent to projectService.
174
178
const fileContent = undefined ;
175
- const result = this . projectService . openClientFile ( filePath , fileContent , scriptKind ) ;
179
+ try {
180
+ const result = this . projectService . openClientFile ( filePath , fileContent , scriptKind ) ;
176
181
177
- const { configFileName, configFileErrors} = result ;
178
- if ( configFileErrors && configFileErrors . length ) {
179
- // configFileErrors is an empty array even if there's no error, so check length.
180
- this . connection . console . error ( configFileErrors . map ( e => e . messageText ) . join ( '\n' ) ) ;
181
- }
182
- if ( ! configFileName ) {
183
- this . connection . console . error ( `No config file for ${ filePath } ` ) ;
184
- return ;
185
- }
186
- const project = this . projectService . findProject ( configFileName ) ;
187
- if ( ! project ) {
188
- this . connection . console . error ( `Failed to find project for ${ filePath } ` ) ;
189
- return ;
190
- }
191
- if ( project . languageServiceEnabled ) {
192
- project . refreshDiagnostics ( ) ; // Show initial diagnostics
182
+ const { configFileName, configFileErrors} = result ;
183
+ if ( configFileErrors && configFileErrors . length ) {
184
+ // configFileErrors is an empty array even if there's no error, so check length.
185
+ this . connection . console . error ( configFileErrors . map ( e => e . messageText ) . join ( '\n' ) ) ;
186
+ }
187
+ if ( ! configFileName ) {
188
+ this . connection . console . error ( `No config file for ${ filePath } ` ) ;
189
+ return ;
190
+ }
191
+ const project = this . projectService . findProject ( configFileName ) ;
192
+ if ( ! project ) {
193
+ this . connection . console . error ( `Failed to find project for ${ filePath } ` ) ;
194
+ return ;
195
+ }
196
+ if ( project . languageServiceEnabled ) {
197
+ project . refreshDiagnostics ( ) ; // Show initial diagnostics
198
+ }
199
+ } catch ( error ) {
200
+ if ( this . isProjectLoading ) {
201
+ this . isProjectLoading = false ;
202
+ this . connection . sendNotification ( projectLoadingNotification . finish ) ;
203
+ }
204
+ if ( error . stack ) {
205
+ this . error ( error . stack ) ;
206
+ }
207
+ throw error ;
193
208
}
194
209
}
195
210
0 commit comments