InlineParamNameHintsDataTaggerProvider.cs 2.9 KB
Newer Older
A
Ankita Khera 已提交
1 2 3 4 5
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.ComponentModel.Composition;
6 7 8 9 10
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Tagging;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.Tagging;
11
using Microsoft.CodeAnalysis.InlineParameterNameHints;
12 13 14 15 16 17 18 19
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Tagging;
using Microsoft.VisualStudio.Utilities;

A
Ankita Khera 已提交
20
namespace Microsoft.CodeAnalysis.Editor.InlineParameterNameHints
21
{
A
Ankita Khera 已提交
22 23 24
    /// <summary>
    /// The TaggerProvider that calls upon the service in order to locate the spans and names
    /// </summary>
25 26 27 28 29 30 31 32 33 34 35
    [Export(typeof(ITaggerProvider))]
    [ContentType("csharp")]
    [TagType(typeof(InlineParamNameHintDataTag))]
    [Name(nameof(InlineParamNameHintsDataTaggerProvider))]
    internal class InlineParamNameHintsDataTaggerProvider : AsynchronousTaggerProvider<InlineParamNameHintDataTag>
    {
        [ImportingConstructor]
        public InlineParamNameHintsDataTaggerProvider(
            IThreadingContext threadingContext,
            IAsynchronousOperationListenerProvider listenerProvider,
            IForegroundNotificationService notificationService)
A
Ankita Khera 已提交
36
            : base(threadingContext, listenerProvider.GetListener(FeatureAttribute.InlineParameterNameHints), notificationService)
37 38 39 40 41 42 43 44 45 46 47 48 49 50
        {
        }

        protected override ITaggerEventSource CreateEventSource(ITextView textViewOpt, ITextBuffer subjectBuffer)
        {
            return TaggerEventSources.OnTextChanged(subjectBuffer, TaggerDelay.NearImmediate);
        }

        protected override async Task ProduceTagsAsync(TaggerContext<InlineParamNameHintDataTag> context, DocumentSnapshotSpan documentSnapshotSpan, int? caretPosition)
        {
            var cancellationToken = context.CancellationToken;
            var document = documentSnapshotSpan.Document;

            var snapshotSpan = documentSnapshotSpan.SnapshotSpan;
51
            var paramNameHintsService = document.GetLanguageService<IInlineParamNameHintsService>();
52 53 54 55 56
            var paramNameHintSpans = await paramNameHintsService.GetInlineParameterNameHintsAsync(document, snapshotSpan.Span.ToTextSpan(), cancellationToken).ConfigureAwait(false);
            cancellationToken.ThrowIfCancellationRequested();

            foreach (var span in paramNameHintSpans)
            {
57
                context.AddTag(new TagSpan<InlineParamNameHintDataTag>(span._span.ToSnapshotSpan(snapshotSpan.Snapshot), new InlineParamNameHintDataTag(span._name))); //span.Item1.Length + 1, _format); //));
58 59 60 61
            }
        }
    }
}