1
//***************************************************************************
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 // This code is licensed under the Visual Studio SDK license terms.
5 // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
6 // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
7 // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
8 // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
10 //***************************************************************************
15 using System
.Collections
.Generic
;
16 using System
.ComponentModel
.Composition
;
17 using Microsoft
.VisualStudio
.Text
;
18 using Microsoft
.VisualStudio
.Text
.Classification
;
19 using Microsoft
.VisualStudio
.Text
.Editor
;
20 using Microsoft
.VisualStudio
.Text
.Tagging
;
21 using Microsoft
.VisualStudio
.Utilities
;
23 [Export(typeof(ITaggerProvider
))]
25 [TagType(typeof(ClassificationTag
))]
26 internal sealed class OokClassifierProvider
: ITaggerProvider
31 [BaseDefinition("code")]
32 internal static ContentTypeDefinition OokContentType
= null;
35 [FileExtension(".ook")]
37 internal static FileExtensionToContentTypeDefinition OokFileType
= null;
40 internal IClassificationTypeRegistryService ClassificationTypeRegistry
= null;
43 internal IBufferTagAggregatorFactoryService aggregatorFactory
= null;
45 public ITagger
<T
> CreateTagger
<T
>(ITextBuffer buffer
) where T
: ITag
48 ITagAggregator
<OokTokenTag
> ookTagAggregator
=
49 aggregatorFactory
.CreateTagAggregator
<OokTokenTag
>(buffer
);
51 return new OokClassifier(buffer
, ookTagAggregator
, ClassificationTypeRegistry
) as ITagger
<T
>;
55 internal sealed class OokClassifier
: ITagger
<ClassificationTag
>
58 ITagAggregator
<OokTokenTag
> _aggregator
;
59 IDictionary
<OokTokenTypes
, IClassificationType
> _ookTypes
;
62 /// Construct the classifier and define search tokens
64 internal OokClassifier(ITextBuffer buffer
,
65 ITagAggregator
<OokTokenTag
> ookTagAggregator
,
66 IClassificationTypeRegistryService typeService
)
69 _aggregator
= ookTagAggregator
;
70 _ookTypes
= new Dictionary
<OokTokenTypes
, IClassificationType
>();
71 _ookTypes
[OokTokenTypes
.OokExclamation
] = typeService
.GetClassificationType("ook!");
72 _ookTypes
[OokTokenTypes
.OokPeriod
] = typeService
.GetClassificationType("ook.");
73 _ookTypes
[OokTokenTypes
.OokQuestion
] = typeService
.GetClassificationType("ook?");
76 public event EventHandler
<SnapshotSpanEventArgs
> TagsChanged
83 /// Search the given span for any instances of classified tags
85 public IEnumerable
<ITagSpan
<ClassificationTag
>> GetTags(NormalizedSnapshotSpanCollection spans
)
87 foreach (var tagSpan
in _aggregator
.GetTags(spans
))
89 var tagSpans
= tagSpan
.Span
.GetSpans(spans
[0].Snapshot
);
91 new TagSpan
<ClassificationTag
>(tagSpans
[0],
92 new ClassificationTag(_ookTypes
[tagSpan
.Tag
.type
]));