diff --git a/src/BaseClasses/TokenClassificationTaggerBase.cs b/src/BaseClasses/TokenClassificationTaggerBase.cs index e06e37b..8a03922 100644 --- a/src/BaseClasses/TokenClassificationTaggerBase.cs +++ b/src/BaseClasses/TokenClassificationTaggerBase.cs @@ -35,15 +35,18 @@ internal TokenClassifier(IClassificationTypeRegistryService registry, ITagAggreg } - public override IEnumerable> GetTags(IMappingTagSpan span) + public override IEnumerable> GetTags(NormalizedSnapshotSpanCollection spans, bool isFullParse) { - if (_classificationMap.TryGetValue(span.Tag.TokenType, out ClassificationTag classificationTag)) + foreach (IMappingTagSpan tag in Tags.GetTags(spans)) { - NormalizedSnapshotSpanCollection tagSpans = span.Span.GetSpans(span.Span.AnchorBuffer.CurrentSnapshot); - - foreach (SnapshotSpan tagSpan in tagSpans) + if (_classificationMap.TryGetValue(tag.Tag.TokenType, out ClassificationTag classificationTag)) { - yield return new TagSpan(tagSpan, classificationTag); + NormalizedSnapshotSpanCollection tagSpans = tag.Span.GetSpans(tag.Span.AnchorBuffer.CurrentSnapshot); + + foreach (SnapshotSpan tagSpan in tagSpans) + { + yield return new TagSpan(tagSpan, classificationTag); + } } } } diff --git a/src/BaseClasses/TokenErrorTaggerBase.cs b/src/BaseClasses/TokenErrorTaggerBase.cs index 810b775..e7afcdb 100644 --- a/src/BaseClasses/TokenErrorTaggerBase.cs +++ b/src/BaseClasses/TokenErrorTaggerBase.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel.Composition; +using System.Linq; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Adornments; using Microsoft.VisualStudio.Text.Tagging; @@ -20,23 +21,46 @@ public ITagger CreateTagger(ITextBuffer buffer) where T : ITag public class ErrorTagger : TokenTaggerConsumerBase { + private readonly TableDataSource _dataSource; + public ErrorTagger(ITagAggregator tags) : base(tags) - { } + { + _dataSource = new TableDataSource(tags.BufferGraph.TopBuffer.ContentType.DisplayName); + } - public override IEnumerable> GetTags(IMappingTagSpan tagSpan) + public override IEnumerable> GetTags(NormalizedSnapshotSpanCollection spans, bool isFullParse) { - if (tagSpan.Tag.IsValid) + IEnumerable> tags = Tags.GetTags(spans).Where(t => !t.Tag.IsValid); + + foreach (IMappingTagSpan tag in tags) + { + NormalizedSnapshotSpanCollection tagSpans = tag.Span.GetSpans(tag.Span.AnchorBuffer.CurrentSnapshot); + var tooltip = string.Join(Environment.NewLine, tag.Tag.Errors); + var errorTag = new ErrorTag(PredefinedErrorTypeNames.SyntaxError, tooltip); + + foreach (SnapshotSpan span in tagSpans) + { + yield return new TagSpan(span, errorTag); + } + } + + if (isFullParse) { - yield break; + PopulateErrorList(tags); } + } - NormalizedSnapshotSpanCollection spans = tagSpan.Span.GetSpans(tagSpan.Span.AnchorBuffer.CurrentSnapshot); - var tooltip = string.Join(Environment.NewLine, tagSpan.Tag.Errors); - var errorTag = new ErrorTag(PredefinedErrorTypeNames.SyntaxError, tooltip); + private void PopulateErrorList(IEnumerable> tags) + { + IEnumerable errors = tags.SelectMany(t => t.Tag.Errors); - foreach (SnapshotSpan span in spans) + if (!errors.Any()) + { + _dataSource.CleanAllErrors(); + } + else { - yield return new TagSpan(span, errorTag); + _dataSource.AddErrors(errors); } } } diff --git a/src/BaseClasses/TokenOutliningTaggerBase.cs b/src/BaseClasses/TokenOutliningTaggerBase.cs index cfeb110..5827de2 100644 --- a/src/BaseClasses/TokenOutliningTaggerBase.cs +++ b/src/BaseClasses/TokenOutliningTaggerBase.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.ComponentModel.Composition; +using System.Linq; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Adornments; using Microsoft.VisualStudio.Text.Tagging; @@ -22,18 +23,16 @@ internal class StructureTagger : TokenTaggerConsumerBase public StructureTagger(ITagAggregator tags) : base(tags) { } - public override IEnumerable> GetTags(IMappingTagSpan span) + public override IEnumerable> GetTags(NormalizedSnapshotSpanCollection spans, bool isFullParse) { - if (!span.Tag.SupportOutlining) + foreach (IMappingTagSpan tag in Tags.GetTags(spans).Where(t => t.Tag.SupportOutlining)) { - yield break; - } - - NormalizedSnapshotSpanCollection tagSpans = span.Span.GetSpans(span.Span.AnchorBuffer.CurrentSnapshot); + NormalizedSnapshotSpanCollection tagSpans = tag.Span.GetSpans(tag.Span.AnchorBuffer.CurrentSnapshot); - foreach (SnapshotSpan tagSpan in tagSpans) - { - yield return CreateTag(tagSpan, tagSpan.GetText().Trim()); + foreach (SnapshotSpan tagSpan in tagSpans) + { + yield return CreateTag(tagSpan, tagSpan.GetText().Trim()); + } } } diff --git a/src/BaseClasses/TokenQuickInfoBase.cs b/src/BaseClasses/TokenQuickInfoBase.cs index e5fff48..986a4ca 100644 --- a/src/BaseClasses/TokenQuickInfoBase.cs +++ b/src/BaseClasses/TokenQuickInfoBase.cs @@ -16,7 +16,7 @@ internal abstract class TokenQuickInfoBase : IAsyncQuickInfoSourceProvider public IAsyncQuickInfoSource TryCreateQuickInfoSource(ITextBuffer buffer) { ITagAggregator tags = _bufferTagAggregator.CreateTagAggregator(buffer); - return buffer.Properties.GetOrCreateSingletonProperty(() => new TokenQuickInfo(buffer, tags)); + return buffer.Properties.GetOrCreateSingletonProperty(() => new TokenQuickInfo(tags)); } } @@ -25,9 +25,9 @@ internal sealed class TokenQuickInfo : IAsyncQuickInfoSource private readonly ITextBuffer _buffer; private readonly ITagAggregator _tags; - public TokenQuickInfo(ITextBuffer buffer, ITagAggregator tags) + public TokenQuickInfo(ITagAggregator tags) { - _buffer = buffer; + _buffer = tags.BufferGraph.TopBuffer; _tags = tags; } diff --git a/src/BaseClasses/TokenTaggerConsumerBase.cs b/src/BaseClasses/TokenTaggerConsumerBase.cs index fdba5fb..ca64032 100644 --- a/src/BaseClasses/TokenTaggerConsumerBase.cs +++ b/src/BaseClasses/TokenTaggerConsumerBase.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Tagging; @@ -7,15 +8,16 @@ namespace BaseClasses { public abstract class TokenTaggerConsumerBase : ITagger, IDisposable where TTag : ITag { - private readonly ITagAggregator _tags; private bool _isDisposed; public TokenTaggerConsumerBase(ITagAggregator tags) { - _tags = tags; - _tags.TagsChanged += TokenTagsChanged; + Tags = tags; + Tags.TagsChanged += TokenTagsChanged; } + public ITagAggregator Tags { get; } + private void TokenTagsChanged(object sender, TagsChangedEventArgs e) { ITextBuffer buffer = e.Span.BufferGraph.TopBuffer; @@ -26,20 +28,16 @@ private void TokenTagsChanged(object sender, TagsChangedEventArgs e) public IEnumerable> GetTags(NormalizedSnapshotSpanCollection spans) { - List> list = new(); - - if (!spans[0].IsEmpty) + if (spans[0].IsEmpty) { - foreach (IMappingTagSpan tagSpan in _tags.GetTags(spans)) - { - list.AddRange(GetTags(tagSpan)); - } + return null; } - return list; + var isFullParse = spans.First().Start == 0 && spans.Last().End == spans[0].Snapshot.Length; + return GetTags(spans, isFullParse); } - public abstract IEnumerable> GetTags(IMappingTagSpan span); + public abstract IEnumerable> GetTags(NormalizedSnapshotSpanCollection spans, bool isFullParse); public virtual void Dispose(bool disposing) { @@ -47,7 +45,7 @@ public virtual void Dispose(bool disposing) { if (disposing) { - _tags.TagsChanged -= TokenTagsChanged; + Tags.TagsChanged -= TokenTagsChanged; } _isDisposed = true; diff --git a/src/Language/EditorFeatures.cs b/src/Language/EditorFeatures.cs index a89c3ac..1260c8c 100644 --- a/src/Language/EditorFeatures.cs +++ b/src/Language/EditorFeatures.cs @@ -5,7 +5,6 @@ using Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion; using Microsoft.VisualStudio.Language.StandardClassification; using Microsoft.VisualStudio.Text.BraceCompletion; -using Microsoft.VisualStudio.Text.Editor; using Microsoft.VisualStudio.Text.Tagging; using Microsoft.VisualStudio.Utilities; @@ -39,12 +38,6 @@ public class Outlining : TokenOutliningTaggerBase public class ErrorSquigglies : TokenErrorTaggerBase { } - [Export(typeof(IWpfTextViewCreationListener))] - [ContentType(Constants.LanguageName)] - [TextViewRole(PredefinedTextViewRoles.PrimaryDocument)] - internal sealed class ErrorList : TokenErrorListBase - { } - [Export(typeof(IAsyncQuickInfoSourceProvider))] [ContentType(Constants.LanguageName)] internal sealed class Tooltips : TokenQuickInfoBase diff --git a/src/PkgdefLanguage.csproj b/src/PkgdefLanguage.csproj index 3133de3..c23b44c 100644 --- a/src/PkgdefLanguage.csproj +++ b/src/PkgdefLanguage.csproj @@ -89,7 +89,6 @@ -