posit-dev / posit-dev/air

LSP: Extra newlines are inserted when requesting `"crlf"` in a document with pre-existing unix line endings

Open
#314 2 comments 1 reaction 0 assignees View on GitHub

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 an air.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() sets LineIndex's endings to LineEnding::Lf
  • Formatting occurs on save. Formatter uses air.toml option and generates a formatted string output with Crlf endings (\r\n)
  • replace_all_edit() is called using the original line index and its original stored options, i.e. endings of Lf! A bunch of Indels are generated, with insertions of \r because that is the only difference. It does seem like we keep the \r all the way through this function and send it back to the frontend?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.