@@ -994,7 +994,8 @@ export class Session<TMessage = string> implements EventSender {
994
994
private eventHandler : ProjectServiceEventHandler | undefined ;
995
995
private readonly noGetErrOnBackgroundUpdate ?: boolean ;
996
996
997
- private diagnosticsTime : [ number , number ] | undefined ;
997
+ // Minimum number of lines for attempting to use region diagnostics for a file.
998
+ protected regionDiagLineCountThreshold = 500 ;
998
999
999
1000
constructor ( opts : SessionOptions ) {
1000
1001
this . host = opts . host ;
@@ -1260,53 +1261,61 @@ export class Session<TMessage = string> implements EventSender {
1260
1261
}
1261
1262
1262
1263
private semanticCheck ( file : NormalizedPath , project : Project ) {
1263
- this . diagnosticsTime = this . hrtime ( ) ;
1264
+ const diagnosticsStartTime = this . hrtime ( ) ;
1264
1265
tracing ?. push ( tracing . Phase . Session , "semanticCheck" , { file, configFilePath : ( project as ConfiguredProject ) . canonicalConfigFilePath } ) ; // undefined is fine if the cast fails
1265
1266
const diags = isDeclarationFileInJSOnlyNonConfiguredProject ( project , file )
1266
1267
? emptyArray
1267
1268
: project . getLanguageService ( ) . getSemanticDiagnostics ( file ) . filter ( d => ! ! d . file ) ;
1268
- this . sendDiagnosticsEvent ( file , project , diags , "semanticDiag" ) ;
1269
+ this . sendDiagnosticsEvent ( file , project , diags , "semanticDiag" , diagnosticsStartTime ) ;
1269
1270
tracing ?. pop ( ) ;
1270
1271
}
1271
1272
1272
1273
private syntacticCheck ( file : NormalizedPath , project : Project ) {
1273
- this . diagnosticsTime = this . hrtime ( ) ;
1274
+ const diagnosticsStartTime = this . hrtime ( ) ;
1274
1275
tracing ?. push ( tracing . Phase . Session , "syntacticCheck" , { file, configFilePath : ( project as ConfiguredProject ) . canonicalConfigFilePath } ) ; // undefined is fine if the cast fails
1275
- this . sendDiagnosticsEvent ( file , project , project . getLanguageService ( ) . getSyntacticDiagnostics ( file ) , "syntaxDiag" ) ;
1276
+ this . sendDiagnosticsEvent ( file , project , project . getLanguageService ( ) . getSyntacticDiagnostics ( file ) , "syntaxDiag" , diagnosticsStartTime ) ;
1276
1277
tracing ?. pop ( ) ;
1277
1278
}
1278
1279
1279
1280
private suggestionCheck ( file : NormalizedPath , project : Project ) {
1280
- this . diagnosticsTime = this . hrtime ( ) ;
1281
+ const diagnosticsStartTime = this . hrtime ( ) ;
1281
1282
tracing ?. push ( tracing . Phase . Session , "suggestionCheck" , { file, configFilePath : ( project as ConfiguredProject ) . canonicalConfigFilePath } ) ; // undefined is fine if the cast fails
1282
- this . sendDiagnosticsEvent ( file , project , project . getLanguageService ( ) . getSuggestionDiagnostics ( file ) , "suggestionDiag" ) ;
1283
+ this . sendDiagnosticsEvent ( file , project , project . getLanguageService ( ) . getSuggestionDiagnostics ( file ) , "suggestionDiag" , diagnosticsStartTime ) ;
1283
1284
tracing ?. pop ( ) ;
1284
1285
}
1285
1286
1286
1287
private regionSemanticCheck ( file : NormalizedPath , project : Project , ranges : TextRange [ ] ) : void {
1287
- this . diagnosticsTime = this . hrtime ( ) ;
1288
+ const diagnosticsStartTime = this . hrtime ( ) ;
1288
1289
tracing ?. push ( tracing . Phase . Session , "regionSemanticCheck" , { file, configFilePath : ( project as ConfiguredProject ) . canonicalConfigFilePath } ) ; // undefined is fine if the cast fails
1289
1290
let diagnosticsResult ;
1290
1291
if ( ! this . shouldDoRegionCheck ( file ) || ! ( diagnosticsResult = project . getLanguageService ( ) . getRegionSemanticDiagnostics ( file , ranges ) ) ) {
1291
1292
tracing ?. pop ( ) ;
1292
1293
return ;
1293
1294
}
1294
- this . sendDiagnosticsEvent ( file , project , diagnosticsResult . diagnostics , "regionSemanticDiag" , diagnosticsResult . spans ) ;
1295
+ this . sendDiagnosticsEvent ( file , project , diagnosticsResult . diagnostics , "regionSemanticDiag" , diagnosticsStartTime , diagnosticsResult . spans ) ;
1295
1296
tracing ?. pop ( ) ;
1296
1297
return ;
1297
1298
}
1298
1299
1299
- // We should only do the region-based semantic check if we think it would be considerably faster than a whole-file semantic check
1300
+ // We should only do the region-based semantic check if we think it would be
1301
+ // considerably faster than a whole-file semantic check.
1300
1302
/** @internal */
1301
1303
protected shouldDoRegionCheck ( file : NormalizedPath ) : boolean {
1302
1304
const lineCount = this . projectService . getScriptInfoForNormalizedPath ( file ) ?. textStorage . getLineInfo ( ) . getLineCount ( ) ;
1303
- return ! ! ( lineCount && lineCount > 500 ) ;
1305
+ return ! ! ( lineCount && lineCount >= this . regionDiagLineCountThreshold ) ;
1304
1306
}
1305
1307
1306
- private sendDiagnosticsEvent ( file : NormalizedPath , project : Project , diagnostics : readonly Diagnostic [ ] , kind : protocol . DiagnosticEventKind , spans ?: TextSpan [ ] ) : void {
1308
+ private sendDiagnosticsEvent (
1309
+ file : NormalizedPath ,
1310
+ project : Project ,
1311
+ diagnostics : readonly Diagnostic [ ] ,
1312
+ kind : protocol . DiagnosticEventKind ,
1313
+ diagnosticsStartTime : [ number , number ] ,
1314
+ spans ?: TextSpan [ ] ,
1315
+ ) : void {
1307
1316
try {
1308
1317
const scriptInfo = Debug . checkDefined ( project . getScriptInfo ( file ) ) ;
1309
- const duration = hrTimeToMilliseconds ( this . hrtime ( this . diagnosticsTime ) ) ;
1318
+ const duration = hrTimeToMilliseconds ( this . hrtime ( diagnosticsStartTime ) ) ;
1310
1319
1311
1320
const body : protocol . DiagnosticEventBody = {
1312
1321
file,
0 commit comments