Beispiel #1
0
        private IEnumerable <NavigateToItem> FilterResults(
            string projectName,
            IEnumerable <AP.Completion> completions,
            IPatternMatcher matcher
            )
        {
            foreach (var c in completions)
            {
                var match = matcher.TryMatch(c.name);
                if (match == null)
                {
                    continue;
                }

                var itemTag = new ItemTag {
                    Services    = _services,
                    Completion  = c,
                    ProjectName = projectName
                };

                yield return(new NavigateToItem(
                                 c.name,
                                 c.memberType.ToString(),
                                 "Python",
                                 "",
                                 itemTag,
                                 match.Value,
                                 PythonNavigateToItemDisplayFactory.Instance
                                 ));
            }
        }
        IList <RunInfo> ToRunInfo(IReadOnlyCollection <ClassifiedText> parts, [CanBeNull] IPatternMatcher patternMatcher, out bool hasMatch)
        {
            hasMatch = false;

            if (patternMatcher == null)
            {
                return(parts.Select(part => new RunInfo(part, isMatch: false)).ToList());
            }

            var runInfos = new List <RunInfo>();

            foreach (var part in parts)
            {
                var patternMatch = patternMatcher.TryMatch(part.Text);

                if (patternMatch != null && patternMatch.Value.MatchedSpans.Length > 0)
                {
                    var matchedSpans = patternMatch.Value.MatchedSpans;

                    var currentIndex = 0;
                    foreach (var match in matchedSpans)
                    {
                        // Der Text vor dem Treffertext
                        if (match.Start > currentIndex)
                        {
                            var text = part.Text.Substring(currentIndex, length: match.Start - currentIndex);
                            runInfos.Add(new RunInfo(new ClassifiedText(text, part.Classification), isMatch: false));
                        }

                        // Der Treffertext
                        var matchtext = part.Text.Substring(match.Start, match.Length);
                        runInfos.Add(new RunInfo(new ClassifiedText(matchtext, part.Classification), isMatch: true));
                        currentIndex = match.End;
                    }

                    // Der Text nach dem letzten Treffertext
                    if (currentIndex < part.Text.Length)
                    {
                        var text = part.Text.Substring(currentIndex, length: part.Text.Length - currentIndex);
                        runInfos.Add(new RunInfo(new ClassifiedText(text, part.Classification), isMatch: false));
                    }

                    hasMatch = true;
                }
                else
                {
                    runInfos.Add(new RunInfo(part, false));
                }
            }

            return(runInfos);
        }
 public bool IsMatch(string input, out PatternMatch?patternMatch)
 {
     patternMatch = _patternMatcher?.TryMatch(input);
     return(_patternMatcher == null || patternMatch.HasValue);
 }
Beispiel #4
0
 public ImmutableArray <Span> TryMatch(string text)
 {
     return(_matcher.TryMatch(text)?.MatchedSpans ?? ImmutableArray <Span> .Empty);
 }