-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add baseline for linked editing #54315
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't look too closely at the baseline generation but the result looks great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly looks good, though there's some duplication and style nits to address
src/harness/fourslashImpl.ts
Outdated
const n = inlineLinkedEditBaseline[inlineLinkedEditBaseline.length - 1]; | ||
baselineContent += `[|/*${n.index}*/` + fileText.slice(n.start, n.end) + `|]` + fileText.slice(inlineLinkedEditBaseline[inlineLinkedEditBaseline.length - 1].end) + linkedEditInfoBaseline; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const n = inlineLinkedEditBaseline[inlineLinkedEditBaseline.length - 1]; | |
baselineContent += `[|/*${n.index}*/` + fileText.slice(n.start, n.end) + `|]` + fileText.slice(inlineLinkedEditBaseline[inlineLinkedEditBaseline.length - 1].end) + linkedEditInfoBaseline; | |
const lastRange = inlineLinkedEditBaseline[inlineLinkedEditBaseline.length - 1]; | |
baselineContent += `[|/*${lastRange.index}*/` + fileText.slice(lastRange.start, lastRange.end) + `|]` + fileText.slice(lastRange.end) + linkedEditInfoBaseline; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, maybe instead of copying the same contents within the loop, you just loop on every element and then write
const sliceEnd = i + 1 < inlineLinkedEditBaseline.length ?
inlineLinkedEditBaseline[i + 1].start :
undefined;
const trailingText = fileText.slice(e.end, sliceEnd);
baselineContent += `[|/*${e.index}*/` + fileText.slice(e.start, e.end) + `|]` + sliceEnd;
src/harness/fourslashImpl.ts
Outdated
return { baselineContent: baselineContent + activeFile.content + `\n\n--No linked edits found--`, offset }; | ||
} | ||
|
||
let inlineLinkedEditBaseline: { start: number, end: number, index: number }[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason that this is named index
if it's always initialized with the current offset? Maybe offsetForBaseline
or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, since it's an array
let inlineLinkedEditBaseline: { start: number, end: number, index: number }[] = []; | |
let inlineLinkedEditBaselines: { start: number, end: number, index: number }[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
index
is the number it will be labeled with in the baseline output, and it's initalized to offset
since it made sense to me to just use the variable that's passed into the function. offset
is incremented per list entry in linkedEditsByRange
like an index.
@typescript-bot cherry-pick this to release-5.1 |
Heya @DanielRosenwasser, I've started to run the task to cherry-pick this into |
Hey @DanielRosenwasser, I've opened #54419 for you. |
…54419) Co-authored-by: Isabel Duan <[email protected]> Co-authored-by: Daniel Rosenwasser <[email protected]>
</[|/*2*/Link|]>; | ||
|
||
=== 0 === | ||
{"ranges":[{"start":13,"length":8},{"start":73,"length":8}],"wordPattern":"[a-zA-Z0-9:\\-\\._$]*"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can skip mentioning ranges here since they are already marked in the text above.
The baseline lets us know exactly when linked editing does and doesn't occur, and it makes long tests more readable.