Exemplo n.º 1
0
        public void CreateTags(IEnumerable <UI.ViewModel.MatchNode> matches)
        {
            using (m_storage.Update())
            {
                m_storage.RemoveTagSpans(s => true);

                if (matches == null)
                {
                    return;
                }

                var snapshot = m_buffer.CurrentSnapshot;

                foreach (var match in matches)
                {
                    var matchInfo = new MatchInfo(match.Index);

                    foreach (var group in match.Groups)
                    {
                        if (group.Number == 0)
                        {
                            continue;
                        }

                        if (!group.Success)
                        {
                            continue;
                        }

                        var groupInfo = new GroupInfo(matchInfo, group.Index, group.Number, group.Name);

                        foreach (var capture in group.Captures)
                        {
                            var captureInfo = new CaptureInfo(groupInfo, capture.Index);

                            if (capture.Segment != null &&
                                0 < capture.Segment.Length &&
                                snapshot.TryCreateTrackingSpan(capture.Segment.Start, capture.Segment.Length, out var span))
                            {
                                // we do not add group with index 0 so it is better to adjust indices
                                var classificationType = GetGroupClassificationType(captureInfo.Parent.Index - 1);
                                m_storage.CreateTagSpan(span, new CaptureTag(captureInfo, classificationType));
                            }
                        }
                    }
                }

                m_storage.PinSnapshot(snapshot);
            }
        }
Exemplo n.º 2
0
 public CaptureTag(CaptureInfo data, IClassificationType classificationType)
 {
     Data = data ?? throw new ArgumentNullException(nameof(data));
     ClassificationType = classificationType;
 }