Skip to content
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

Merged
merged 4 commits into from May 26, 2023
Merged

Conversation

iisaduan
Copy link
Member

The baseline lets us know exactly when linked editing does and doesn't occur, and it makes long tests more readable.

@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels May 18, 2023
Copy link
Member

@andrewbranch andrewbranch left a 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!

Copy link
Member

@DanielRosenwasser DanielRosenwasser left a 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 Show resolved Hide resolved
Comment on lines 3638 to 3639
const n = inlineLinkedEditBaseline[inlineLinkedEditBaseline.length - 1];
baselineContent += `[|/*${n.index}*/` + fileText.slice(n.start, n.end) + `|]` + fileText.slice(inlineLinkedEditBaseline[inlineLinkedEditBaseline.length - 1].end) + linkedEditInfoBaseline;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;

Copy link
Member

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 Show resolved Hide resolved
src/harness/fourslashImpl.ts Outdated Show resolved Hide resolved
return { baselineContent: baselineContent + activeFile.content + `\n\n--No linked edits found--`, offset };
}

let inlineLinkedEditBaseline: { start: number, end: number, index: number }[] = [];
Copy link
Member

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?

Copy link
Member

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

Suggested change
let inlineLinkedEditBaseline: { start: number, end: number, index: number }[] = [];
let inlineLinkedEditBaselines: { start: number, end: number, index: number }[] = [];

Copy link
Member Author

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.

src/harness/fourslashImpl.ts Outdated Show resolved Hide resolved
@DanielRosenwasser
Copy link
Member

@typescript-bot cherry-pick this to release-5.1

@typescript-bot
Copy link
Collaborator

typescript-bot commented May 26, 2023

Heya @DanielRosenwasser, I've started to run the task to cherry-pick this into release-5.1 on this PR at 8a8956a. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

Hey @DanielRosenwasser, I've opened #54419 for you.

typescript-bot pushed a commit to typescript-bot/TypeScript that referenced this pull request May 26, 2023
Component commits:
e255542 add baselineLinkedEditing

e00ab81 remove extra marker linkedEditingJsxTag11.ts

8a8956a refactors
@iisaduan iisaduan merged commit ca0fafd into microsoft:main May 26, 2023
20 checks passed
@iisaduan iisaduan deleted the linkedEditBaseline branch May 26, 2023 23:02
DanielRosenwasser added a commit that referenced this pull request May 30, 2023
…54419)

Co-authored-by: Isabel Duan <isabelduan@microsoft.com>
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
</[|/*2*/Link|]>;

=== 0 ===
{"ranges":[{"start":13,"length":8},{"start":73,"length":8}],"wordPattern":"[a-zA-Z0-9:\\-\\._$]*"}
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants