@@ -377,6 +377,14 @@ type AdaptiveState
377377 disposables.Add
378378 <| fileParsed.Publish.Subscribe( fun ( parseResults , proj , ct ) -> detectTests parseResults proj ct)
379379
380+ let analyzersLocker = new SemaphoreSlim( 1 , 1 )
381+
382+ let typecheckLocker =
383+ let maxConcurrency =
384+ Math.Max( 1.0 , Math.Floor( float System.Environment.ProcessorCount * 0.75 )) |> int
385+
386+ new SemaphoreSlim( maxConcurrency, maxConcurrency)
387+
380388 let builtInCompilerAnalyzers config ( file : VolatileFile ) ( tyRes : ParseAndCheckResults ) =
381389 let filePath = file.FileName
382390 let filePathUntag = UMX.untag filePath
@@ -390,14 +398,15 @@ type AdaptiveState
390398 let checkUnusedOpens =
391399 asyncEx {
392400 try
401+ let! ct = Async.CancellationToken
402+ use! _l = analyzersLocker.LockAsync( ct)
393403 use progress = progressLookup.CreateProgressReport( lspClient, cancellable = true )
394404 do ! progress.Begin( $" Checking unused opens {fileName}..." , message = filePathUntag)
395405
396406 let! unused =
397407 UnusedOpens.getUnusedOpens ( tyRes.GetCheckResults, getSourceLine)
398408 |> Async.withCancellation progress.CancellationToken
399409
400- let! ct = Async.CancellationToken
401410 notifications.Trigger( NotificationEvent.UnusedOpens( filePath, ( unused |> List.toArray), file.Version), ct)
402411 with e ->
403412 logger.error ( Log.setMessage " checkUnusedOpens failed" >> Log.addExn e)
@@ -406,6 +415,8 @@ type AdaptiveState
406415 let checkUnusedDeclarations =
407416 asyncEx {
408417 try
418+ let! ct = Async.CancellationToken
419+ use! _l = analyzersLocker.LockAsync( ct)
409420 use progress = progressLookup.CreateProgressReport( lspClient, cancellable = true )
410421 do ! progress.Begin( $" Checking unused declarations {fileName}..." , message = filePathUntag)
411422
@@ -417,7 +428,6 @@ type AdaptiveState
417428
418429 let unused = unused |> Seq.toArray
419430
420- let! ct = Async.CancellationToken
421431 notifications.Trigger( NotificationEvent.UnusedDeclarations( filePath, unused, file.Version), ct)
422432 with e ->
423433 logger.error ( Log.setMessage " checkUnusedDeclarations failed" >> Log.addExn e)
@@ -426,6 +436,8 @@ type AdaptiveState
426436 let checkSimplifiedNames =
427437 asyncEx {
428438 try
439+ let! ct = Async.CancellationToken
440+ use! _l = analyzersLocker.LockAsync( ct)
429441 use progress = progressLookup.CreateProgressReport( lspClient, cancellable = true )
430442 do ! progress.Begin( $" Checking simplifying of names {fileName}..." , message = filePathUntag)
431443
@@ -434,7 +446,6 @@ type AdaptiveState
434446 |> Async.withCancellation progress.CancellationToken
435447
436448 let simplified = Array.ofSeq simplified
437- let! ct = Async.CancellationToken
438449 notifications.Trigger( NotificationEvent.SimplifyNames( filePath, simplified, file.Version), ct)
439450 with e ->
440451 logger.error ( Log.setMessage " checkSimplifiedNames failed" >> Log.addExn e)
@@ -443,6 +454,8 @@ type AdaptiveState
443454 let checkUnnecessaryParentheses =
444455 asyncEx {
445456 try
457+ let! ct = Async.CancellationToken
458+ use! _l = analyzersLocker.LockAsync( ct)
446459 use progress = progressLookup.CreateProgressReport( lspClient)
447460 do ! progress.Begin( $" Checking for unnecessary parentheses {fileName}..." , message = filePathUntag)
448461
@@ -464,8 +477,6 @@ type AdaptiveState
464477
465478 | _ -> ranges)
466479
467- let! ct = Async.CancellationToken
468-
469480 notifications.Trigger(
470481 NotificationEvent.UnnecessaryParentheses( filePath, Array.ofSeq unnecessaryParentheses, file.Version),
471482 ct
@@ -1599,6 +1610,8 @@ type AdaptiveState
15991610
16001611 ]
16011612
1613+ let! ct = Async.CancellationToken
1614+ use! _l = typecheckLocker.LockAsync ct
16021615 use _ = fsacActivitySource.StartActivityForType( thisType, tags = tags)
16031616
16041617
0 commit comments