diff --git a/src/BaseClasses/TokenErrorListBase.cs b/src/BaseClasses/TokenErrorListBase.cs deleted file mode 100644 index 20618d4..0000000 --- a/src/BaseClasses/TokenErrorListBase.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel.Composition; -using System.Linq; -using Microsoft.VisualStudio.Shell; -using Microsoft.VisualStudio.Text; -using Microsoft.VisualStudio.Text.Editor; -using Microsoft.VisualStudio.Text.Tagging; - -namespace BaseClasses -{ - internal abstract class TokenErrorListBase : WpfTextViewCreationListener - { - private ITextBuffer _buffer; - private TableDataSource _dataSource; - private ITagAggregator _tags; - - [Import] internal IBufferTagAggregatorFactoryService _bufferTagAggregator = null; - - protected override void Created(DocumentView docView) - { - _buffer = docView.TextBuffer; - _dataSource = new TableDataSource(_buffer.ContentType.DisplayName); - - _tags = _bufferTagAggregator.CreateTagAggregator(_buffer); - _tags.TagsChanged += OnTokenTagsChanged; - } - - private void OnTokenTagsChanged(object sender = null, TagsChangedEventArgs e = null) - { - var span = new SnapshotSpan(_buffer.CurrentSnapshot, 0, _buffer.CurrentSnapshot.Length); - NormalizedSnapshotSpanCollection spans = new(span); - - ThreadHelper.JoinableTaskFactory.StartOnIdle(() => - { - IEnumerable> errorTags = _tags.GetTags(spans).Where(t => !t.Tag.IsValid); - - if (!errorTags.Any()) - { - _dataSource.CleanAllErrors(); - } - else - { - IEnumerable errors = errorTags.SelectMany(e => e.Tag.Errors); - _dataSource.AddErrors(errors); - } - }); - } - - protected override void Closed(IWpfTextView textView) - { - _tags.TagsChanged -= OnTokenTagsChanged; - _dataSource.CleanAllErrors(); - } - } -} - diff --git a/src/BaseClasses/TokenErrorTaggerBase.cs b/src/BaseClasses/TokenErrorTaggerBase.cs index e7afcdb..159199f 100644 --- a/src/BaseClasses/TokenErrorTaggerBase.cs +++ b/src/BaseClasses/TokenErrorTaggerBase.cs @@ -63,5 +63,15 @@ private void PopulateErrorList(IEnumerable> tags) _dataSource.AddErrors(errors); } } + + public override void Dispose(bool disposing) + { + if (disposing) + { + _dataSource.CleanAllErrors(); + } + + base.Dispose(disposing); + } } }