mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-28 00:35:16 +02:00
line numbering improvements
This commit is contained in:
@@ -301,20 +301,21 @@ async function applyFileEdits(filePath: string, edits: z.infer<typeof EditOperat
|
|||||||
let startIdx = edit.startLine ? edit.startLine - 1 : -1;
|
let startIdx = edit.startLine ? edit.startLine - 1 : -1;
|
||||||
|
|
||||||
if (edit.findAnchor) {
|
if (edit.findAnchor) {
|
||||||
// Use normalized comparison for finding anchor
|
// Use line-by-line comparison for accurate anchor matching
|
||||||
const content = lines.join('\n');
|
let foundLine = -1;
|
||||||
const normalizedContent = normalizeForComparison(content);
|
|
||||||
const normalizedAnchor = normalizeForComparison(edit.findAnchor);
|
const normalizedAnchor = normalizeForComparison(edit.findAnchor);
|
||||||
const anchorIdx = normalizedContent.indexOf(normalizedAnchor);
|
|
||||||
|
|
||||||
if (anchorIdx === -1) {
|
for (let i = 0; i < lines.length; i++) {
|
||||||
|
const normalizedLine = normalizeForComparison(lines[i]);
|
||||||
|
if (normalizedLine.includes(normalizedAnchor)) {
|
||||||
|
foundLine = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (foundLine === -1) {
|
||||||
throw new Error(`Edit failed - anchor text not found: ${edit.findAnchor} in ${filePath}`);
|
throw new Error(`Edit failed - anchor text not found: ${edit.findAnchor} in ${filePath}`);
|
||||||
}
|
}
|
||||||
|
startIdx = foundLine + (edit.anchorOffset || 0);
|
||||||
// Map normalized index back to original content
|
|
||||||
const beforeAnchor = content.substring(0, content.length * anchorIdx / normalizedContent.length);
|
|
||||||
const anchorLine = beforeAnchor.split(/\r?\n/).length - 1;
|
|
||||||
startIdx = anchorLine + (edit.anchorOffset || 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startIdx === -1) {
|
if (startIdx === -1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user