(query: string)
| 70 | * @returns Array of potential symbol names |
| 71 | */ |
| 72 | export function extractSymbolsFromQuery(query: string): string[] { |
| 73 | const symbols = new Set<string>(); |
| 74 | // The ASCII patterns below would read `état` as `tat`; they see such words |
| 75 | // blanked out, and the Unicode pass at the end takes them whole. |
| 76 | const asciiView = blankNonAsciiWords(query); |
| 77 | |
| 78 | // Extract CamelCase identifiers (2+ chars, starts with letter) |
| 79 | const camelCasePattern = /\b([A-Z][a-z]+(?:[A-Z][a-z]*)*|[a-z]+(?:[A-Z][a-z]*)+)\b/g; |
| 80 | let match; |
| 81 | while ((match = camelCasePattern.exec(asciiView)) !== null) { |
| 82 | if (match[1] && match[1].length >= 2) { |
| 83 | symbols.add(match[1]); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | // Extract snake_case identifiers |
| 88 | const snakeCasePattern = /\b([a-z][a-z0-9]*(?:_[a-z0-9]+)+)\b/gi; |
| 89 | while ((match = snakeCasePattern.exec(asciiView)) !== null) { |
| 90 | if (match[1] && match[1].length >= 3) { |
| 91 | symbols.add(match[1]); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | // Extract SCREAMING_SNAKE_CASE |
| 96 | const screamingPattern = /\b([A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+)\b/g; |
| 97 | while ((match = screamingPattern.exec(asciiView)) !== null) { |
| 98 | if (match[1]) { |
| 99 | symbols.add(match[1]); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | // Extract ALL_CAPS acronyms (2+ chars, e.g., REST, HTTP, LRU, API) |
| 104 | const acronymPattern = /\b([A-Z]{2,})\b/g; |
| 105 | while ((match = acronymPattern.exec(asciiView)) !== null) { |
| 106 | if (match[1]) { |
| 107 | symbols.add(match[1]); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | // Extract dot.notation and split into parts (e.g., "app.isPackaged" -> ["app", "isPackaged"]) |
| 112 | const dotPattern = /\b([a-zA-Z][a-zA-Z0-9]*(?:\.[a-zA-Z][a-zA-Z0-9]*)+)\b/g; |
| 113 | while ((match = dotPattern.exec(asciiView)) !== null) { |
| 114 | if (match[1]) { |
| 115 | // Add both the full path and individual parts |
| 116 | symbols.add(match[1]); |
| 117 | const parts = match[1].split('.'); |
| 118 | for (const part of parts) { |
| 119 | if (part.length >= 2) { |
| 120 | symbols.add(part); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | // Extract plain lowercase identifiers (3+ chars, not already matched) |
| 127 | // Catches symbol names like "undo", "redo", "history", "render", "parse" |
| 128 | const lowercasePattern = /\b([a-z][a-z0-9]{2,})\b/g; |
| 129 | while ((match = lowercasePattern.exec(asciiView)) !== null) { |
no test coverage detected