@@ -166,22 +166,16 @@ export class Session {
166
166
*/
167
167
private sendPendingDiagnostics ( openFiles : string [ ] ) {
168
168
for ( const fileName of openFiles ) {
169
- const scriptInfo = this . projectService . getScriptInfo ( fileName ) ;
170
- if ( ! scriptInfo ) {
169
+ const result = this . getLSAndScriptInfo ( fileName ) ;
170
+ if ( ! result ) {
171
171
continue ;
172
172
}
173
-
174
- const ngLS = this . getDefaultLanguageService ( scriptInfo ) ;
175
- if ( ! ngLS ) {
176
- continue ;
177
- }
178
-
179
- const diagnostics = ngLS . getSemanticDiagnostics ( fileName ) ;
173
+ const diagnostics = result . languageService . getSemanticDiagnostics ( fileName ) ;
180
174
// Need to send diagnostics even if it's empty otherwise editor state will
181
175
// not be updated.
182
176
this . connection . sendDiagnostics ( {
183
177
uri : filePathToUri ( fileName ) ,
184
- diagnostics : diagnostics . map ( d => tsDiagnosticToLspDiagnostic ( d , scriptInfo ) ) ,
178
+ diagnostics : diagnostics . map ( d => tsDiagnosticToLspDiagnostic ( d , result . scriptInfo ) ) ,
185
179
} ) ;
186
180
}
187
181
}
@@ -224,16 +218,6 @@ export class Session {
224
218
return project ;
225
219
}
226
220
227
- /**
228
- * Returns a language service for a default project created for the specified `scriptInfo`. If the
229
- * project does not support a language service, nothing is returned.
230
- */
231
- getDefaultLanguageService ( scriptInfo : ts . server . ScriptInfo ) : ts . LanguageService | undefined {
232
- const project = this . getDefaultProjectForScriptInfo ( scriptInfo ) ;
233
- if ( ! project ?. languageServiceEnabled ) return ;
234
- return project . getLanguageService ( ) ;
235
- }
236
-
237
221
private onInitialize ( params : lsp . InitializeParams ) : lsp . InitializeResult {
238
222
return {
239
223
capabilities : {
@@ -402,21 +386,26 @@ export class Session {
402
386
return results ;
403
387
}
404
388
405
- private getLSAndScriptInfo ( textDocument : lsp . TextDocumentIdentifier ) :
389
+ private getLSAndScriptInfo ( textDocumentOrFileName : lsp . TextDocumentIdentifier | string ) :
406
390
{ languageService : ts . LanguageService , scriptInfo : ts . server . ScriptInfo } | undefined {
407
- const filePath = uriToFilePath ( textDocument . uri ) ;
391
+ const filePath = lsp . TextDocumentIdentifier . is ( textDocumentOrFileName ) ?
392
+ uriToFilePath ( textDocumentOrFileName . uri ) :
393
+ textDocumentOrFileName ;
408
394
const scriptInfo = this . projectService . getScriptInfo ( filePath ) ;
409
395
if ( ! scriptInfo ) {
410
396
this . error ( `Script info not found for ${ filePath } ` ) ;
411
397
return ;
412
398
}
413
399
414
- const languageService = this . getDefaultLanguageService ( scriptInfo ) ;
415
- if ( ! languageService ) {
400
+ const project = this . getDefaultProjectForScriptInfo ( scriptInfo ) ;
401
+ if ( ! project ?. languageServiceEnabled ) {
416
402
return ;
417
403
}
418
404
419
- return { languageService, scriptInfo} ;
405
+ return {
406
+ languageService : project . getLanguageService ( ) ,
407
+ scriptInfo,
408
+ } ;
420
409
}
421
410
422
411
private onHover ( params : lsp . TextDocumentPositionParams ) {
0 commit comments