withastro / compiler

The Astro compiler. Written in Go. Distributed as WASM.
Other
502 stars 59 forks source link

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

Closed Princesseuh closed 3 months ago

Princesseuh commented 3 months ago

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 https://github.com/microsoft/vscode-languageserver-node/issues/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

changeset-bot[bot] commented 3 months ago

🦋 Changeset detected

Latest commit: 97a9313a3df7d2195df033ef293f18f0cbeff40a

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