public TextRange?FilterSearchHit(TextRange match) { var lineExtentStart = _getLineExtentCache.GetLineExtent(match.Position); var lineExtentEnd = _getLineExtentCache.GetLineExtent(match.EndPosition); var lineExtent = new TextRange( lineExtentStart.Position, lineExtentEnd.EndPosition - lineExtentStart.Position); if (_previousMatch.HasValue) { // If match overlaps with previous one, fail if (match.Position < _previousMatch.Value.EndPosition) { return(null); } // If line extent overlaps with previous match, shrink it. if (lineExtent.Position < _previousMatch.Value.EndPosition) { lineExtent = new TextRange( _previousMatch.Value.EndPosition, lineExtent.EndPosition - _previousMatch.Value.EndPosition); } } // We got the line extent, the offset at which we found the MainEntry. // Now we need to check that "OtherEntries" are present (in order) and // in appropriate intervals. var range1 = new TextRange( lineExtent.Position, match.Position - lineExtent.Position); var entriesInterval1 = _parsedSearchString.EntriesBeforeMainEntry; var foundRange1 = entriesInterval1.Any() ? CheckEntriesInRange(range1, entriesInterval1) : match; var range2 = new TextRange( match.EndPosition, lineExtent.EndPosition - match.EndPosition); var entriesInterval2 = _parsedSearchString.EntriesAfterMainEntry; var foundRange2 = entriesInterval2.Any() ? CheckEntriesInRange(range2, entriesInterval2) : match; if (foundRange1.HasValue && foundRange2.HasValue) { var newMatch = new TextRange( foundRange1.Value.Position, foundRange2.Value.EndPosition - foundRange1.Value.Position); // Save the this match for next iteration _previousMatch = newMatch; return(newMatch); } return(null); }
public IEnumerable <FilePositionSpan> FilterOnOtherEntries(ParsedSearchString parsedSearchString, IEnumerable <FilePositionSpan> matches) { var getLineExtentCache = new GetLineExtentCache(_getLineExtent); return(matches .Select(match => { var lineExtent = getLineExtentCache.GetLineExtent(match.Position); // We got the line extent, the offset at which we found the MainEntry. // Now we need to check that "OtherEntries" are present (in order) and // in appropriate intervals. var positionInterval1 = lineExtent.Position; var lengthInterval1 = match.Position - lineExtent.Position; var entriesInterval1 = parsedSearchString.EntriesBeforeMainEntry; var positionInterval2 = match.Position + match.Length; var lengthInterval2 = (lineExtent.Position + lineExtent.Length) - (match.Position + match.Length); var entriesInterval2 = parsedSearchString.EntriesAfterMainEntry; int foundPositionInterval1; int foundLengthInterval1; int foundPositionInterval2; int foundLengthInterval2; if (CheckEntriesInInterval(positionInterval1, lengthInterval1, entriesInterval1, out foundPositionInterval1, out foundLengthInterval1) && CheckEntriesInInterval(positionInterval2, lengthInterval2, entriesInterval2, out foundPositionInterval2, out foundLengthInterval2)) { // If there was no entries before MainEntry, adjust interval // location to be the same as the main entry. if (foundPositionInterval1 < 0) { foundPositionInterval1 = match.Position; foundLengthInterval1 = match.Length; } // If there was no entries after MainEntry, adjust interval to be // the same as the main entry. if (foundPositionInterval2 < 0) { foundPositionInterval2 = match.Position; foundLengthInterval2 = match.Length; } return new FilePositionSpan { Position = foundPositionInterval1, Length = foundPositionInterval2 + foundLengthInterval2 - foundPositionInterval1 }; } return new FilePositionSpan(); }) .Where(x => x.Length != default(FilePositionSpan).Length) .ToList()); }
public IEnumerable<FilePositionSpan> FilterOnOtherEntries(ParsedSearchString parsedSearchString, IEnumerable<FilePositionSpan> matches) { var getLineExtentCache = new GetLineExtentCache(_getLineExtent); return matches .Select(match => { var lineExtent = getLineExtentCache.GetLineExtent(match.Position); // We got the line extent, the offset at which we found the MainEntry. // Now we need to check that "OtherEntries" are present (in order) and // in appropriate intervals. var positionInterval1 = lineExtent.Position; var lengthInterval1 = match.Position - lineExtent.Position; var entriesInterval1 = parsedSearchString.EntriesBeforeMainEntry; var positionInterval2 = match.Position + match.Length; var lengthInterval2 = (lineExtent.Position + lineExtent.Length) - (match.Position + match.Length); var entriesInterval2 = parsedSearchString.EntriesAfterMainEntry; int foundPositionInterval1; int foundLengthInterval1; int foundPositionInterval2; int foundLengthInterval2; if (CheckEntriesInInterval(positionInterval1, lengthInterval1, entriesInterval1, out foundPositionInterval1, out foundLengthInterval1) && CheckEntriesInInterval(positionInterval2, lengthInterval2, entriesInterval2, out foundPositionInterval2, out foundLengthInterval2)) { // If there was no entries before MainEntry, adjust interval // location to be the same as the main entry. if (foundPositionInterval1 < 0) { foundPositionInterval1 = match.Position; foundLengthInterval1 = match.Length; } // If there was no entries after MainEntry, adjust interval to be // the same as the main entry. if (foundPositionInterval2 < 0) { foundPositionInterval2 = match.Position; foundLengthInterval2 = match.Length; } return new FilePositionSpan { Position = foundPositionInterval1, Length = foundPositionInterval2 + foundLengthInterval2 - foundPositionInterval1 }; } return new FilePositionSpan(); }) .Where(x => x.Length != default(FilePositionSpan).Length) .ToList(); }