InlineHintsTaggerProvider.cs 3.2 KB
Newer Older
A
Ankita Khera 已提交
1 2 3 4
// 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.

A
Ankita Khera 已提交
5
using System;
A
Ankita Khera 已提交
6
using System.ComponentModel.Composition;
7
using Microsoft.CodeAnalysis.Editor.Host;
A
Ankita Khera 已提交
8
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
A
Ankita Khera 已提交
9
using Microsoft.CodeAnalysis.Host.Mef;
A
Ankita Khera 已提交
10
using Microsoft.VisualStudio.Text;
11
using Microsoft.VisualStudio.Text.Adornments;
12
using Microsoft.VisualStudio.Text.Classification;
A
Ankita Khera 已提交
13 14 15 16
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Tagging;
using Microsoft.VisualStudio.Utilities;

C
Cyrus Najmabadi 已提交
17
namespace Microsoft.CodeAnalysis.Editor.InlineHints
A
Ankita Khera 已提交
18
{
19

A
Ankita Khera 已提交
20 21 22 23
    /// <summary>
    /// The provider that is used as a middleman to create the tagger so that the data tag
    /// can be used to create the UI tag
    /// </summary>
A
Ankita Khera 已提交
24
    [Export(typeof(IViewTaggerProvider))]
25
    [ContentType(ContentTypeNames.RoslynContentType)]
26
    [TagType(typeof(IntraTextAdornmentTag))]
C
Renames  
Cyrus Najmabadi 已提交
27 28
    [Name(nameof(InlineHintsTaggerProvider))]
    internal class InlineHintsTaggerProvider : IViewTaggerProvider
A
Ankita Khera 已提交
29
    {
30
        private readonly IViewTagAggregatorFactoryService _viewTagAggregatorFactoryService;
31
        public readonly IClassificationFormatMapService ClassificationFormatMapService;
A
Ankita Khera 已提交
32
        public readonly IClassificationTypeRegistryService ClassificationTypeRegistryService;
A
Ankita Khera 已提交
33
        public readonly IThreadingContext ThreadingContext;
34
        public readonly IToolTipService ToolTipService;
35
        public readonly Lazy<IStreamingFindUsagesPresenter> StreamingFindUsagesPresenter;
A
Ankita Khera 已提交
36

A
Ankita Khera 已提交
37
        [ImportingConstructor]
A
Ankita Khera 已提交
38
        [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
C
Renames  
Cyrus Najmabadi 已提交
39
        public InlineHintsTaggerProvider(
40 41 42 43 44 45
            IViewTagAggregatorFactoryService viewTagAggregatorFactoryService,
            IClassificationFormatMapService classificationFormatMapService,
            IClassificationTypeRegistryService classificationTypeRegistryService,
            IThreadingContext threadingContext,
            IToolTipService toolTipService,
            Lazy<IStreamingFindUsagesPresenter> streamingFindUsagesPresenter)
A
Ankita Khera 已提交
46
        {
47
            _viewTagAggregatorFactoryService = viewTagAggregatorFactoryService;
48
            this.ClassificationFormatMapService = classificationFormatMapService;
A
Ankita Khera 已提交
49
            this.ClassificationTypeRegistryService = classificationTypeRegistryService;
A
Ankita Khera 已提交
50
            this.ThreadingContext = threadingContext;
51
            this.ToolTipService = toolTipService;
52
            this.StreamingFindUsagesPresenter = streamingFindUsagesPresenter;
A
Ankita Khera 已提交
53 54
        }

C
NRT  
Cyrus Najmabadi 已提交
55
        public ITagger<T>? CreateTagger<T>(ITextView textView, ITextBuffer buffer) where T : ITag
A
Ankita Khera 已提交
56
        {
A
Ankita Khera 已提交
57 58
            // Determining of the textView's buffer does not match the buffer in order to skip showing the hints for
            // the interactive window
A
Ankita Khera 已提交
59 60 61 62 63
            if (buffer != textView.TextBuffer)
            {
                return null;
            }

C
Renames  
Cyrus Najmabadi 已提交
64 65
            var tagAggregator = _viewTagAggregatorFactoryService.CreateTagAggregator<InlineHintDataTag>(textView);
            return new InlineHintsTagger(this, (IWpfTextView)textView, buffer, tagAggregator) as ITagger<T>;
A
Ankita Khera 已提交
66
        }
A
Ankita Khera 已提交
67 68
    }
}