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

Fix line returns segments being one character too long on Windows #1043

Merged
merged 3 commits into from
Aug 14, 2024

Conversation

Princesseuh
Copy link
Member

@Princesseuh Princesseuh commented Aug 13, 2024

Changes

Previously, due to how we skipped over CRLF, we'd end up with a mapping that looks like this:

Original:  ;    \n
Mapping : [;\r][\n]

Where the first segment would contain both the last character of the line, and the \r. This is fine, albeit wonky, however this ends up breaking downstream in libraries that are line-ending agnostic because they don't expect than an offset would end up after a line ending, even less so in the middle of a two-characters one. (the main culprit here is https://github.com/microsoft/vscode-languageserver-node/tree/main/textDocument, see microsoft/vscode-languageserver-node#1285)

This PR fixes this by handling it like this instead:

Original:  ;  \n
Mapping : [;][\r\n]

That way, asking for the last segment of a line will instead result on the ;, or before the two line endings, depending on which one you ask for, but nothing after or in the middle of it.

Testing

Added a test

Docs

N/A

Copy link

changeset-bot bot commented Aug 13, 2024

🦋 Changeset detected

Latest commit: 97a9313

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/compiler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Princesseuh Princesseuh marked this pull request as ready for review August 13, 2024 23:05
@Princesseuh Princesseuh merged commit 5d0023d into main Aug 14, 2024
5 checks passed
@Princesseuh Princesseuh deleted the fix/sourcemap-windows-crlf branch August 14, 2024 11:19
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.

3 participants