-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrayLogTagger.cs
More file actions
56 lines (50 loc) · 1.9 KB
/
GrayLogTagger.cs
File metadata and controls
56 lines (50 loc) · 1.9 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
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Tagging;
namespace GrayLog
{
/// <summary>
/// Empty GrayLogTag class.
/// </summary>
internal class GrayLogTag : IGlyphTag { }
/// <summary>
/// This class implements ITagger for GrayLogTag. It is responsible for creating
/// GrayLogTag TagSpans, which our GlyphFactory will then create glyphs for.
/// </summary>
internal class GrayLogTagger : ITagger<GrayLogTag>
{
private const string SEARCH_TEXT = "log.,logger.,log?.,logger?.";
private static readonly string[] TagsList = SEARCH_TEXT.Split(',');
/// <summary>
/// This method creates GrayLogTag TagSpans over a set of SnapshotSpans.
/// </summary>
/// <param name="spans">A set of spans we want to get tags for.</param>
/// <returns>The list of GrayLogTag TagSpans.</returns>
IEnumerable<ITagSpan<GrayLogTag>> ITagger<GrayLogTag>.GetTags(NormalizedSnapshotSpanCollection spans)
{
//GrayLog: implement tagging
return from curSpan in spans
where GetSearchTextPos(curSpan) > -1
select new SnapshotSpan(curSpan.Snapshot, new Span(curSpan.Start, curSpan.Length))
into grayLogSpan
select new TagSpan<GrayLogTag>(grayLogSpan, new GrayLogTag());
}
private static int GetSearchTextPos(SnapshotSpan span)
{
foreach (var str in TagsList)
{
var rez = span.GetText().ToLower().IndexOf(str, StringComparison.Ordinal);
if (rez > -1) return rez;
}
return -1;
}
public event EventHandler<SnapshotSpanEventArgs> TagsChanged
{
add {}
remove {}
}
}
}