forked from KhaosCoders/VSCodeBlockEndTag
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CBETaggerProvider.cs
81 lines (69 loc) · 2.66 KB
/
CBETaggerProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Operations;
using Microsoft.VisualStudio.Text.Tagging;
using Microsoft.VisualStudio.Utilities;
using Microsoft.VisualStudio.Editor;
using System.ComponentModel.Composition;
namespace CodeBlockEndTag
{
/// <summary>
/// This class serves as factory for VS to create the CBETagger
/// </summary>
[Export(typeof(IViewTaggerProvider))]
[ContentType("code")]
[TextViewRole(PredefinedTextViewRoles.Interactive)]
[TagType(typeof(IntraTextAdornmentTag))]
internal class CBETaggerProvider : IViewTaggerProvider
{
#region MEF-Imports: Services from VisualStudio
#pragma warning disable CS0649
// Disabled waring about default value. Value will be set by VS.
[Import]
internal ITextStructureNavigatorSelectorService TextStructureNavigatorSelector { get; set; }
[Import]
internal ITextBufferFactoryService TextBufferFactory { get; set; }
[Import]
internal ITextSearchService TextSearchService { get; set; }
[Import]
internal IVsFontsAndColorsInformationService VsFontsAndColorsInformationService { get; set; }
#pragma warning restore CS0649
#endregion
/// <summary>
/// Factory function for a CBETagger instance.
/// Used by VS to create the tagger
/// </summary>
public ITagger<T> CreateTagger<T>(ITextView textView, ITextBuffer buffer) where T : ITag
{
// provide the tag only on the top-level buffer
if (textView.TextBuffer != buffer)
{
return null;
}
// Check if content type (language) is supported and active for tagging
var type = textView.TextBuffer.ContentType;
if (!CBETagPackage.IsLanguageSupported(type.TypeName))
{
return null;
}
// only works with IWpfTextView
if (textView is IWpfTextView wpfTextView)
{
// return new instance of CBETagger
return new CBETagger(this, wpfTextView) as ITagger<T>;
}
else
{
return null;
}
}
/// <summary>
/// Returns a TextStructureNavigator for the given TextBuffer
/// This is a service by VisualStudio for fast navigation in structured texts
/// </summary>
internal ITextStructureNavigator GetTextStructureNavigator(ITextBuffer buffer)
{
return TextStructureNavigatorSelector.GetTextStructureNavigator(buffer);
}
}
}