LSP: Extra newlines are inserted when requesting `"crlf"` in a document with pre-existing unix line endings
Open
Nobody has claimed this yet.
bug
- Dominant language
- Rust
- Stars
- 446
- Forks
- 32
- Avg merge
- 16h 48m
- Merged PRs (30d)
- 1
Description
- Open a Unix line ending R file
- Set
line-ending = "crlf"in anair.toml - Save using the LSP
https://github.com/user-attachments/assets/09ed3a96-35e9-436b-9e3f-ec3fd5a9bb93
I think this line is relevant?
https://github.com/posit-dev/air/blob/dac87ff76d4b0b4f2ad0d48c3d6a7386a04c54ca/crates/lsp/src/documents.rs#L64
I'm not 100% sure what is going on:
- Client opens unix document.
Document::new()setsLineIndex'sendingstoLineEnding::Lf - Formatting occurs on save. Formatter uses
air.tomloption and generates a formatted string output withCrlfendings (\r\n) replace_all_edit()is called using the original line index and its original stored options, i.e.endingsofLf! A bunch of Indels are generated, with insertions of\rbecause that is the only difference. It does seem like we keep the\rall the way through this function and send it back to the frontend?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in crates/lsp/src/documents.rs at Document::new and replace_all_edit(), then reproduce the reported save flow with a Unix-ending R file and line-ending = "crlf". Done means saving through the LSP no longer inserts extra newlines while applying the requested CRLF endings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r, rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100