@@ -584,37 +584,44 @@ private IDisposable GetDocumentParseCounter(IDocument doc, out int count) {
584584 }
585585 }
586586
587- internal async Task EnqueueItemAsync ( IDocument doc , AnalysisPriority priority = AnalysisPriority . Normal , bool parse = true , bool enqueueForAnalysis = true ) {
587+ internal Task EnqueueItemAsync ( IDocument doc , AnalysisPriority priority = AnalysisPriority . Normal , bool parse = true , bool enqueueForAnalysis = true ) {
588588 _disposableBag . ThrowIfDisposed ( ) ;
589589 var pending = _pendingAnalysisEnqueue . Incremented ( ) ;
590590 try {
591591 var entry = doc as ProjectEntry ;
592592 entry ? . ResetCompleteAnalysis ( ) ;
593593
594- // If we don't need to parse, use null cooking
595- IAnalysisCookie cookie = null ;
594+ // If we don't need to parse, use null cookie
595+ var cookieTask = Task . FromResult < IAnalysisCookie > ( null ) ;
596596 if ( parse ) {
597597 using ( GetDocumentParseCounter ( doc , out var count ) ) {
598598 if ( count > 3 ) {
599599 // Rough check to prevent unbounded queueing. If we have
600600 // multiple parses in queue, we will get the latest doc
601601 // version in one of the ones to come.
602- return ;
602+ return Task . CompletedTask ;
603603 }
604604 TraceMessage ( $ "Parsing document { doc . DocumentUri } ") ;
605- cookie = await ParseQueue . EnqueueAsync ( doc , Analyzer . LanguageVersion ) ;
605+ cookieTask = ParseQueue . EnqueueAsync ( doc , Analyzer . LanguageVersion ) ;
606606 }
607607 }
608608
609609 // The call must be fire and forget, but should not be yielding.
610610 // It is called from DidChangeTextDocument which must fully finish
611611 // since otherwise Complete() may come before the change is enqueued
612612 // for processing and the completion list will be driven off the stale data.
613- var p = pending ;
614- await OnDocumentChangeProcessingCompleteAsync ( doc , cookie as VersionCookie , enqueueForAnalysis , priority , p ) ;
615- pending = null ;
616- } finally {
613+ return cookieTask . ContinueWith ( async t => {
614+ if ( t . IsFaulted ) {
615+ // Happens when file got deleted before processing
616+ pending . Dispose ( ) ;
617+ LogMessage ( MessageType . Error , t . Exception . Message ) ;
618+ return ;
619+ }
620+ await OnDocumentChangeProcessingCompleteAsync ( doc , t . Result as VersionCookie , enqueueForAnalysis , priority , pending ) ;
621+ } ) ;
622+ } catch {
617623 pending ? . Dispose ( ) ;
624+ throw ;
618625 }
619626 }
620627
0 commit comments