MCPcopy Index your code
hub / github.com/simstudioai/sim / findAnchorLine

Function findAnchorLine

apps/sim/lib/copilot/tools/server/files/edit-content.ts:122–145  ·  view source on GitHub ↗
(
              anchor: string,
              occurrence = defaultOccurrence,
              afterIndex = -1
            )

Source from the content-addressed store, hash-verified

120 const defaultOccurrence = intent.edit.occurrence ?? 1
121
122 const findAnchorLine = (
123 anchor: string,
124 occurrence = defaultOccurrence,
125 afterIndex = -1
126 ): { index: number; error?: string } => {
127 const trimmed = anchor.trim()
128 let count = 0
129 for (let i = afterIndex + 1; i < lines.length; i++) {
130 if (lines[i].trim() === trimmed) {
131 count++
132 if (count === occurrence) return { index: i }
133 }
134 }
135 if (count === 0) {
136 return {
137 index: -1,
138 error: `Anchor line not found in "${fileRecord.name}": "${anchor.slice(0, 100)}"`,
139 }
140 }
141 return {
142 index: -1,
143 error: `Anchor line occurrence ${occurrence} not found (only ${count} match${count > 1 ? 'es' : ''}) in "${fileRecord.name}": "${anchor.slice(0, 100)}"`,
144 }
145 }
146
147 if (intent.edit.mode === 'replace_between') {
148 if (!intent.edit.before_anchor || !intent.edit.after_anchor) {

Callers 1

executeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected