@@ -699,40 +699,22 @@ private bool HandleConfigurationChanges(ServerSettings newSettings) {
699699 }
700700 #endregion
701701
702- internal Task WaitForCompleteAnalysisAsync ( CancellationToken cancellationToken ) {
703- var tcs = new TaskCompletionSource < object > ( ) ;
704- var t = WaitForCompleteAnalysisWorker ( cancellationToken ) ;
705- Task . Run ( async ( ) => {
706- try {
707- while ( ! t . IsCompleted ) {
708- cancellationToken . ThrowIfCancellationRequested ( ) ;
709- await Task . Delay ( 100 ) ;
710- }
711- tcs . TrySetResult ( null ) ;
712- } catch ( OperationCanceledException ) {
713- tcs . TrySetCanceled ( ) ;
714- } catch ( Exception ex ) when ( ! ex . IsCriticalException ( ) ) {
715- tcs . TrySetException ( ex ) ;
716- }
717- } ) ;
718- return tcs . Task ;
719- }
702+ internal Task WaitForCompleteAnalysisAsync ( CancellationToken cancellationToken )
703+ => Task . WhenAny ( WaitForCompleteAnalysisWorker ( cancellationToken ) , Task . Delay ( Timeout . Infinite , cancellationToken ) ) . Unwrap ( ) ;
720704
721705 private async Task WaitForCompleteAnalysisWorker ( CancellationToken cancellationToken ) {
722- do {
723- // Wait for all current parsing to complete
724- TraceMessage ( $ "Waiting for parsing to complete.") ;
725- await ParseQueue . WaitForAllAsync ( ) ;
726- TraceMessage ( $ "Parsing complete. Waiting for analysis entries to enqueue.") ;
727- await _pendingAnalysisEnqueue . WaitForZeroAsync ( ) ;
728- TraceMessage ( $ "Enqueue complete. Waiting for analysis to complete.") ;
729- await AnalysisQueue . WaitForCompleteAsync ( ) ;
730- foreach ( var pf in ProjectFiles ) {
731- TraceMessage ( $ " Waiting for analysis of { pf . DocumentUri } to complete.") ;
732- await GetAnalysisAsync ( pf . DocumentUri , cancellationToken ) ;
733- }
734- TraceMessage ( $ "Analysis complete.") ;
735- } while ( ParseQueue . Count > 0 || _pendingAnalysisEnqueue . Count > 0 || AnalysisQueue . Count > 0 ) ;
706+ // Wait for all current parsing to complete
707+ TraceMessage ( $ "Waiting for parsing to complete.") ;
708+ await ParseQueue . WaitForAllAsync ( ) ;
709+ TraceMessage ( $ "Parsing complete. Waiting for analysis entries to enqueue.") ;
710+ await _pendingAnalysisEnqueue . WaitForZeroAsync ( ) ;
711+ TraceMessage ( $ "Enqueue complete. Waiting for analysis to complete.") ;
712+ await AnalysisQueue . WaitForCompleteAsync ( ) ;
713+ foreach ( var pf in ProjectFiles ) {
714+ TraceMessage ( $ " Waiting for analysis of { pf . DocumentUri } to complete.") ;
715+ await GetAnalysisAsync ( pf . DocumentUri , cancellationToken ) ;
716+ }
717+ TraceMessage ( $ "Analysis complete.") ;
736718 }
737719 }
738720}
0 commit comments