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

Format completion snippet text before escaping #48793

Merged
merged 2 commits into from
Apr 21, 2022

Conversation

andrewbranch
Copy link
Member

Fixes #48139
Fixes #48215

I briefly tried to make the formatting scanner and/or actual scanner tolerant of \$ and \\, but it quickly became apparent that this approach would be easier.

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Apr 20, 2022
src/services/completions.ts Show resolved Hide resolved
return textChanges.applyChanges(syntheticFile.text, changes);

const allChanges = escapes
? stableSort(concatenate(changes, escapes), (a, b) => compareTextSpans(a.span, b.span))
Copy link
Member

Choose a reason for hiding this comment

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

this might be a dumb question, but is there a chance that we have overlapping text changes, and if so, will this sorting make sure everything works correctly?

Copy link
Member Author

Choose a reason for hiding this comment

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

Overlapping edits can defeat the sorting, but since the formatter deals only in whitespace and semicolons, and the characters we need to escape are only part of tokens, I don’t think it can ever be a problem in practice.

Copy link
Member

Choose a reason for hiding this comment

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

I see, thanks.

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

LGTM, though I sort of worry about someone adding a new function to this and forgetting to clear escapes; right now it's fine since both functions call printUnescapedSnippetList, though.

@andrewbranch andrewbranch merged commit 7abdb9e into microsoft:main Apr 21, 2022
@andrewbranch andrewbranch deleted the bug/48139 branch April 21, 2022 20:40
Jack-Works pushed a commit to Jack-Works/TypeScript that referenced this pull request Apr 22, 2022
* Format snippet text before escaping

* Reset `escapes` before printing so printer can be reused
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
4 participants