MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / declarationSourceWindow

Function declarationSourceWindow

src/resolution/frameworks/swift-objc.ts:158–173  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

156 * an empty string if the source can't be read.
157 */
158function 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.

Callers 1

resolveObjcCallToSwiftFunction · 0.85

Calls 4

linesOfFunction · 0.90
mapMethod · 0.80
readFileMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected