* Read a small window of source ending at `node.startLine`, used to * inspect Swift attribute annotations attached to a declaration. Returns * an empty string if the source can't be read.
(node: Node, context: ResolutionContext)
| 156 | * an empty string if the source can't be read. |
| 157 | */ |
| 158 | function declarationSourceWindow(node: Node, context: ResolutionContext): string { |
| 159 | const content = context.readFile(node.filePath); |
| 160 | if (!content) return ''; |
| 161 | // The file's lines, split once (linesOf) where they were split for each |
| 162 | // ObjC message a Swift method might answer: a class of eight thousand |
| 163 | // `@objc` methods, each sent to once, split its file that many times. |
| 164 | // linesOf splits at `\n`, where this split at `\r?\n`: a line that ends |
| 165 | // in `\r` before its newline is read without it, as before. |
| 166 | const lines = linesOf(content); |
| 167 | const startIdx = Math.max(0, node.startLine - 1 - SOURCE_PROBE_LINES); |
| 168 | const endIdx = Math.min(lines.length, node.startLine); |
| 169 | return lines |
| 170 | .slice(startIdx, endIdx) |
| 171 | .map((line, i) => (startIdx + i < lines.length - 1 && line.endsWith('\r') ? line.slice(0, -1) : line)) |
| 172 | .join('\n'); |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Try to resolve a Swift caller's bare reference to an ObjC implementation. |
no test coverage detected