@@ -96,9 +96,6 @@ public Server() {
9696
9797 _disposableBag
9898 . Add ( ProjectFiles )
99- . Add ( ( ) => Analyzer ? . Dispose ( ) )
100- . Add ( ( ) => _shutdownCts . Cancel ( ) )
101- . Add ( AnalysisQueue )
10299 . Add ( ( ) => {
103100 foreach ( var ext in _extensions . Values ) {
104101 ( ext as IDisposable ) ? . Dispose ( ) ;
@@ -121,7 +118,12 @@ private void Analysis_UnhandledException(object sender, UnhandledExceptionEventA
121118 internal ServerSettings Settings { get ; private set ; } = new ServerSettings ( ) ;
122119 internal ProjectFiles ProjectFiles { get ; } = new ProjectFiles ( ) ;
123120
124- public void Dispose ( ) => _disposableBag . TryDispose ( ) ;
121+ public void Dispose ( ) {
122+ _shutdownCts . Cancel ( ) ;
123+ AnalysisQueue . Dispose ( ) ;
124+ Analyzer ? . Dispose ( ) ;
125+ _disposableBag . TryDispose ( ) ;
126+ }
125127
126128 #region ILogger
127129 public void TraceMessage ( IFormattable message ) {
@@ -625,6 +627,7 @@ internal Task EnqueueItemAsync(IDocument doc, AnalysisPriority priority = Analys
625627 LogMessage ( MessageType . Error , t . Exception . Message ) ;
626628 return ;
627629 }
630+ _shutdownCts . Token . ThrowIfCancellationRequested ( ) ;
628631 await OnDocumentChangeProcessingCompleteAsync ( doc , t . Result as VersionCookie , enqueueForAnalysis , priority , pending ) ;
629632 } ) ;
630633 } catch {
@@ -635,6 +638,7 @@ internal Task EnqueueItemAsync(IDocument doc, AnalysisPriority priority = Analys
635638
636639 private async Task OnDocumentChangeProcessingCompleteAsync ( IDocument doc , VersionCookie vc , bool enqueueForAnalysis , AnalysisPriority priority , IDisposable disposeWhenEnqueued ) {
637640 try {
641+ _shutdownCts . Token . ThrowIfCancellationRequested ( ) ;
638642 _disposableBag . ThrowIfDisposed ( ) ;
639643 if ( vc != null ) {
640644 foreach ( var kv in vc . GetAllParts ( doc . DocumentUri ) ) {
@@ -645,6 +649,7 @@ private async Task OnDocumentChangeProcessingCompleteAsync(IDocument doc, Versio
645649 }
646650
647651 if ( doc is IAnalyzable analyzable && enqueueForAnalysis ) {
652+ _shutdownCts . Token . ThrowIfCancellationRequested ( ) ;
648653 AnalysisQueued ( doc . DocumentUri ) ;
649654 AnalysisQueue . Enqueue ( analyzable , priority ) ;
650655 }
@@ -658,6 +663,7 @@ private async Task OnDocumentChangeProcessingCompleteAsync(IDocument doc, Versio
658663 if ( doc is ProjectEntry entry ) {
659664 var reanalyzeEntries = Analyzer . GetEntriesThatImportModule ( entry . ModuleName , false ) ;
660665 foreach ( var d in reanalyzeEntries . OfType < IDocument > ( ) ) {
666+ _shutdownCts . Token . ThrowIfCancellationRequested ( ) ;
661667 await EnqueueItemAsync ( d , parse : false ) ;
662668 }
663669 }
0 commit comments