forked from O-n-y/SyntaxLume
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaggerProvider.cs
More file actions
45 lines (34 loc) · 1.1 KB
/
TaggerProvider.cs
File metadata and controls
45 lines (34 loc) · 1.1 KB
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
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Utilities;
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Text.Tagging;
namespace Ony.SyntaxLume;
[Export(typeof(ITaggerProvider))]
[ContentType("CSharp")]
[TagType(typeof(ClassificationTag))]
internal class TaggerProvider : ITaggerProvider
{
[Import] internal IClassificationTypeRegistryService ClassificationTypeRegistry { get; set; }
[Import] internal IClassifierAggregatorService ClassifierAggregator { get; set; }
private bool _isCreatingTagger = false;
public ITagger<T> CreateTagger<T>(ITextBuffer buffer) where T : ITag
{
if (buffer == null)
return null;
if (_isCreatingTagger)
return null;
if (!buffer.ContentType.IsOfType("CSharp"))
return null;
try
{
_isCreatingTagger = true;
var classifier = ClassifierAggregator.GetClassifier(buffer);
return new Tagger(buffer, ClassificationTypeRegistry, classifier) as ITagger<T>;
}
finally
{
_isCreatingTagger = false;
}
}
}