<commit_before>// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.

using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.Shared.Tagging;
using Microsoft.CodeAnalysis.Editor.Tagging;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Tagging;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.Editor.Implementation.ReferenceHighlighting
{
    internal partial class ReferenceHighlightingTagSource : ProducerPopulatedTagSource<AbstractNavigatableReferenceHighlightingTag>
    {
        private const int VoidVersion = -1;

        private readonly ITextView _textView;

        // last solution version we used to update tags
        // * NOTE * here unfortunately, we only hold onto version without caret position since
        //          it is not easy to pass through it. for now, we will void the last version whenever
        //          we see caret changes.
        private int _lastUpdateTagsSolutionVersion = VoidVersion;

        public ReferenceHighlightingTagSource(
            ITextView textView,
            ITextBuffer subjectBuffer,
            IAsynchronousTaggerDataSource<AbstractNavigatableReferenceHighlightingTag> dataSource,
            IAsynchronousOperationListener asyncListener,
            IForegroundNotificationService notificationService)
            : base(textView, subjectBuffer, dataSource, asyncListener, notificationService)
        {
            _textView = textView;
        }

        protected override SnapshotPoint? GetCaretPoint()
        {
            return _textView.Caret.Position.Point.GetPoint(b => b.ContentType.IsOfType(ContentTypeNames.RoslynContentType), PositionAffinity.Successor);
        }

        protected override void RecalculateTagsOnChangedCore(TaggerEventArgs e)
        {
            var cancellationToken = this.WorkQueue.CancellationToken;

            VoidLastSolutionVersionIfCaretChanged(e);

            RegisterNotification(() =>
            {
                this.WorkQueue.AssertIsForeground();

                var caret = GetCaretPoint();
                if (!caret.HasValue)
                {
                    ClearTags(cancellationToken);
                    return;
                }

                var spansToTag = TryGetSpansAndDocumentsToTag(e.Kind);
                if (spansToTag != null)
                {
                    // we will eagerly remove tags except for semantic change case.
                    // in semantic change case, we don't actually know whether it will affect highlight we currently
                    // have, so we will wait until we get new tags before removing them.
                    if (e.Kind != PredefinedChangedEventKinds.SemanticsChanged)
                    {
                        ClearTags(spansToTag, cancellationToken);
                    }

                    base.RecalculateTagsOnChanged(e);
                }
            }, delay: TaggerConstants.NearImmediateDelay, cancellationToken: cancellationToken);
        }<commit_msg>Call correct base method.<commit_after>// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.

using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.Shared.Tagging;
using Microsoft.CodeAnalysis.Editor.Tagging;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Tagging;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.Editor.Implementation.ReferenceHighlighting
{
    internal partial class ReferenceHighlightingTagSource : ProducerPopulatedTagSource<AbstractNavigatableReferenceHighlightingTag>
    {
        private const int VoidVersion = -1;

        private readonly ITextView _textView;

        // last solution version we used to update tags
        // * NOTE * here unfortunately, we only hold onto version without caret position since
        //          it is not easy to pass through it. for now, we will void the last version whenever
        //          we see caret changes.
        private int _lastUpdateTagsSolutionVersion = VoidVersion;

        public ReferenceHighlightingTagSource(
            ITextView textView,
            ITextBuffer subjectBuffer,
            IAsynchronousTaggerDataSource<AbstractNavigatableReferenceHighlightingTag> dataSource,
            IAsynchronousOperationListener asyncListener,
            IForegroundNotificationService notificationService)
            : base(textView, subjectBuffer, dataSource, asyncListener, notificationService)
        {
            _textView = textView;
        }

        protected override SnapshotPoint? GetCaretPoint()
        {
            return _textView.Caret.Position.Point.GetPoint(b => b.ContentType.IsOfType(ContentTypeNames.RoslynContentType), PositionAffinity.Successor);
        }

        protected override void RecalculateTagsOnChangedCore(TaggerEventArgs e)
        {
            var cancellationToken = this.WorkQueue.CancellationToken;

            VoidLastSolutionVersionIfCaretChanged(e);

            RegisterNotification(() =>
            {
                this.WorkQueue.AssertIsForeground();

                var caret = GetCaretPoint();
                if (!caret.HasValue)
                {
                    ClearTags(cancellationToken);
                    return;
                }

                var spansToTag = TryGetSpansAndDocumentsToTag(e.Kind);
                if (spansToTag != null)
                {
                    // we will eagerly remove tags except for semantic change case.
                    // in semantic change case, we don't actually know whether it will affect highlight we currently
                    // have, so we will wait until we get new tags before removing them.
                    if (e.Kind != PredefinedChangedEventKinds.SemanticsChanged)
                    {
                        ClearTags(spansToTag, cancellationToken);
                    }

                    base.RecalculateTagsOnChangedCore(e);
                }
            }, delay: TaggerConstants.NearImmediateDelay, cancellationToken: cancellationToken);
        }
{'fraction_non_alphanumeric': 0.06222547584187409, 'fraction_numerical': 0.0008784773060029283, 'mean_word_length': 2.4001991040318567, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2282217', 'n_tokens_mistral': 1639, 'n_tokens_neox': 1547, 'n_words': 425}