rust-lang / rust-lang/rust-analyzer
Formatting sends wrong response when line endings are supposed to be changed
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
When line endings are changed during a formatting request, the whole document is sent to the client.
The change is correctly detected and new_text contains the changed endings.
But then to_proto::text_edit_vec subsequently changes the line endings back, because it uses the ones passed in by line_index instead of new_line_endings
So the actual TextEdit in the response contains new_text with the old line endings.
Steps to reproduce
- be on LF system
- open file with CRLF endings
- make document formating request
- https://github.com/rust-lang/rust-analyzer/blob/65874dfff205335840cc9265ba06d74f234b719d/crates/rust-analyzer/src/handlers.rs#L1876 reports CRLF -> LF change and new_text contains LF endings
- the client receives TextEdit replacing the document but still containing CRLF endings
This results in clients receiving the whole document on each request, because they always make requests with line endings that rust-analyzer wants to convert.
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/rust-analyzer/src/handlers.rs around lines 1874-1884 and trace the formatting response through to_proto::text_edit_vec. Verify how line_index and new_line_endings affect the returned TextEdit. Done means formatting a CRLF document on an LF system returns the intended line endings without replacing the whole document repeatedly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100