Skip to content

Decrement line ends if they end with a carriage return. #31220

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

Conversation

jessetrinity
Copy link
Contributor

Attempting to enter a newline after the #name banner in the collapsed region depicted below causes a crash in Visual Studio.

//#region name

const a = 1;

//#endregion
//#name

Previously the carriage return character \r was being included in the outlining span, as line ends here are determined only by the presence of the new line character \n.

This change simply decrements the line end by one if the line ends with a carriage return \r.

Fixes JS region collapse area after carriage return.

@sheetalkamat
Copy link
Member

We need test for this

@jessetrinity
Copy link
Contributor Author

I suppose I could write a test to make sure we don't consume the \r.

@jessetrinity
Copy link
Contributor Author

A few things were discussed offline:

  1. We definitely want a Visual Studio test for this since it is crashing VS, not just the language service. A fourslash test would be nice, but

  2. Fourslash tests don't use CRLF endings (this change is invisible to the existing region tests).

  3. In general, TypeScript looks to split lines by new line characters, and deals with carriage returns later. Another example of this behavior here.

Copy link
Member

@amcasey amcasey left a comment

Choose a reason for hiding this comment

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

Most of my suggestions apply to parts of the code that you didn't touch, but I think this is a good opportunity to clean it up (and add test coverage).

@jessetrinity jessetrinity force-pushed the excludeCarriageReturnFromOutliningSpans branch from 7923588 to 2c90bda Compare July 25, 2019 00:28
@jessetrinity
Copy link
Contributor Author

@sheetalkamat I added a couple of tests. Do we have any concerns about how this could affect VSCode?

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

Looks good to me, but get @sheetalkamat's signoff for interactions with VS Code -- or manually test on VS Code.

@jessetrinity jessetrinity requested a review from amcasey July 26, 2019 02:03
@jessetrinity jessetrinity merged commit 599e36a into microsoft:master Jul 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants