提交 07aac7f3 编写于 作者: C CyrusNajmabadi

Simplify code.

上级 a631539c
...@@ -159,6 +159,15 @@ public void Dispose() ...@@ -159,6 +159,15 @@ public void Dispose()
// Disconnect us from our underlying taggers and make sure they're // Disconnect us from our underlying taggers and make sure they're
// released as well. // released as well.
DisconnectFromAllTaggers();
_owner.RemoveTagger(this, _subjectBuffer);
}
}
private void DisconnectFromAllTaggers()
{
this.AssertIsForeground();
foreach (var kvp in _idToProviderAndTagger) foreach (var kvp in _idToProviderAndTagger)
{ {
var tagger = kvp.Value.Item2; var tagger = kvp.Value.Item2;
...@@ -167,8 +176,6 @@ public void Dispose() ...@@ -167,8 +176,6 @@ public void Dispose()
} }
_idToProviderAndTagger.Clear(); _idToProviderAndTagger.Clear();
_owner.RemoveTagger(this, _subjectBuffer);
}
} }
private void DisconnectFromTagger(IAccurateTagger<TTag> tagger) private void DisconnectFromTagger(IAccurateTagger<TTag> tagger)
...@@ -225,6 +232,11 @@ private void OnDiagnosticsUpdatedOnForeground(DiagnosticsUpdatedArgs e) ...@@ -225,6 +232,11 @@ private void OnDiagnosticsUpdatedOnForeground(DiagnosticsUpdatedArgs e)
{ {
this.AssertIsForeground(); this.AssertIsForeground();
if (_disposed)
{
return;
}
// Do some quick checks to avoid doing any further work for diagnostics we don't // Do some quick checks to avoid doing any further work for diagnostics we don't
// care about. // care about.
var ourDocument = _subjectBuffer.AsTextContainer().GetOpenDocumentInCurrentContext(); var ourDocument = _subjectBuffer.AsTextContainer().GetOpenDocumentInCurrentContext();
...@@ -325,12 +337,16 @@ private void ProcessRemovedDiagnostics(DiagnosticsUpdatedArgs e) ...@@ -325,12 +337,16 @@ private void ProcessRemovedDiagnostics(DiagnosticsUpdatedArgs e)
// was removed. If so, clear out any diagnostics we have associated with this // was removed. If so, clear out any diagnostics we have associated with this
// diagnostic source ID and notify any listeners that // diagnostic source ID and notify any listeners that
if (_disposed) ValueTuple<TaggerProvider, IAccurateTagger<TTag>> providerAndTagger;
if (!_idToProviderAndTagger.TryGetValue(e.Id, out providerAndTagger))
{ {
// Wasn't a diagnostic source we care about.
return; return;
} }
RemoveCachedDiagnostics(e.Id); _idToProviderAndTagger.Remove(e.Id);
DisconnectFromTagger(providerAndTagger.Item2);
OnUnderlyingTaggerTagsChanged(this, new SnapshotSpanEventArgs(_subjectBuffer.CurrentSnapshot.GetFullSpan())); OnUnderlyingTaggerTagsChanged(this, new SnapshotSpanEventArgs(_subjectBuffer.CurrentSnapshot.GetFullSpan()));
} }
...@@ -338,40 +354,14 @@ private void RemoveAllCachedDiagnostics() ...@@ -338,40 +354,14 @@ private void RemoveAllCachedDiagnostics()
{ {
this.AssertIsForeground(); this.AssertIsForeground();
// Make a copy of all the IDs so that we don't change a collection as we're DisconnectFromAllTaggers();
// iterating over it.
var ids = _idToProviderAndTagger.Keys.ToArray();
foreach (var id in ids)
{
RemoveCachedDiagnostics(id);
}
OnUnderlyingTaggerTagsChanged(this, new SnapshotSpanEventArgs(_subjectBuffer.CurrentSnapshot.GetFullSpan())); OnUnderlyingTaggerTagsChanged(this, new SnapshotSpanEventArgs(_subjectBuffer.CurrentSnapshot.GetFullSpan()));
} }
private void RemoveCachedDiagnostics(object id)
{
this.AssertIsForeground();
ValueTuple<TaggerProvider, IAccurateTagger<TTag>> providerAndTagger;
if (!_idToProviderAndTagger.TryGetValue(id, out providerAndTagger))
{
// Wasn't a diagnostic source we care about.
return;
}
_idToProviderAndTagger.Remove(id);
DisconnectFromTagger(providerAndTagger.Item2);
}
private void OnDiagnosticsUpdatedOnForeground( private void OnDiagnosticsUpdatedOnForeground(
DiagnosticsUpdatedArgs e, SourceText sourceText, ITextSnapshot editorSnapshot) DiagnosticsUpdatedArgs e, SourceText sourceText, ITextSnapshot editorSnapshot)
{ {
this.AssertIsForeground(); this.AssertIsForeground();
if (_disposed)
{
return;
}
// Find the appropriate async tagger for this diagnostics id, and let it know that // Find the appropriate async tagger for this diagnostics id, and let it know that
// there were new diagnostics produced for it. // there were new diagnostics produced for it.
...@@ -413,6 +403,7 @@ private void OnUnderlyingTaggerTagsChanged(object sender, SnapshotSpanEventArgs ...@@ -413,6 +403,7 @@ private void OnUnderlyingTaggerTagsChanged(object sender, SnapshotSpanEventArgs
{ {
return; return;
} }
this.TagsChanged?.Invoke(sender, args); this.TagsChanged?.Invoke(sender, args);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册