( query: TextSearchQuery, _options: TextSearchOptions, progress: Progress<TextSearchResult>, uri: Uri, content: string, limit: Limit )
| 45 | } |
| 46 | |
| 47 | function searchInFile( |
| 48 | query: TextSearchQuery, |
| 49 | _options: TextSearchOptions, |
| 50 | progress: Progress<TextSearchResult>, |
| 51 | uri: Uri, |
| 52 | content: string, |
| 53 | limit: Limit |
| 54 | ): void { |
| 55 | let { pattern } = query; |
| 56 | |
| 57 | const originalLines = content.split("\n"); |
| 58 | |
| 59 | if (!query.isCaseSensitive) { |
| 60 | content = content.toLowerCase(); |
| 61 | pattern = pattern.toLowerCase(); |
| 62 | } |
| 63 | |
| 64 | const lines = content.split("\n"); |
| 65 | |
| 66 | for ( |
| 67 | let lineIndex = 0; |
| 68 | lineIndex < lines.length && !limit.isHit(); |
| 69 | lineIndex++ |
| 70 | ) { |
| 71 | const line = lines[lineIndex]; |
| 72 | const matches: TextSearchMatch[] = []; |
| 73 | |
| 74 | if (query.isRegExp) { |
| 75 | const regex = new RegExp(fixNewline(pattern), "g"); |
| 76 | |
| 77 | let hits = Array.from(line.matchAll(regex)).filter(hasIndex); |
| 78 | if (!hits.length) continue; |
| 79 | |
| 80 | limit.increase(hits.length); |
| 81 | if (limit.isHit()) { |
| 82 | hits = hits.slice(0, limit.max - limit.current()); |
| 83 | } |
| 84 | |
| 85 | matches.push({ |
| 86 | uri, |
| 87 | ranges: hits.map( |
| 88 | (hit) => |
| 89 | new Range( |
| 90 | lineIndex, |
| 91 | hit.index, |
| 92 | lineIndex, |
| 93 | hit.index + hit[0].length |
| 94 | ) |
| 95 | ), |
| 96 | preview: { |
| 97 | text: originalLines[lineIndex], |
| 98 | matches: hits.map( |
| 99 | (hit) => new Range(0, hit.index, 0, hit.index + hit[0].length) |
| 100 | ), |
| 101 | }, |
| 102 | }); |
| 103 | } else { |
| 104 | let indices = getIndicesOf(pattern, line); |
no test coverage detected