Skip to content

fix(lsp): keep a CRLF line break whole in the fix-all edit - #1108

Merged
psteinroe merged 13 commits into
mainfrom
fix/fix-all-crlf
Nov 6, 2026
Merged

psteinroe merged 13 commits into
mainfrom
fix/fix-all-crlf

Conversation

@psteinroe

Copy link
Copy Markdown
Collaborator

Stacked on #1070.

The fix-all code action replaces only the part of the file that its fixes changed. The language server and the WASM bindings each had their own changed_range for that, and only the WASM one (#969) took in the whole \r\n when only one half of it changed. In the language server, such an edit ended between the \r and the \n, a position the LSP doesn't allow, so it lost the half that changed:

-- the fixes turn "select 1;\r\nselect 2;" into "select 1;\nselect 2;"
-- before: the edit is empty at (0, 9), the end of line 0, and the \r stays
-- now: the edit replaces the \r\n at (0, 9)-(1, 0) with \n

changed_range now lives in pgls_line_index, next to the rule that a position can't point into a \r\n, and both use it. The WASM bindings keep their behaviour; the language server gets the widening. Each caller still turns the range into an LSP edit in its own position types (fix_all_edit).

Tests: fix_all_edits_keep_crlf_whole in pgls_lsp applies the fix-all edit through from_lsp for CRLF and LF changes and a non-ASCII line; it fails without this change. changed_range_keeps_the_common_start_and_end (moved from pgls_lsp) and changed_range_keeps_crlf_whole test the function in pgls_line_index; the WASM test from #969 runs against it unchanged. cargo test -p pgls_line_index -p pgls_lsp -p pgls_wasm, cargo clippy --workspace --all-targets -- -D warnings, and bun run build && bun test in the WASM package (49 pass).

Not covered: to_lsp::text_edits, which formatting uses, still doesn't widen a diff that changes one half of a \r\n (see #1070). #1107 also adds a module to pgls_line_index; whichever merges second gets a small conflict in the module list of lib.rs, where both lines stay.

The language server's LineIndex converts offsets to line/column positions
in UTF-8, UTF-16 and UTF-32. It lives in pgls_lsp, which pulls in tokio and
tower-lsp, so the WASM bindings and pgls_suppressions couldn't use it and
have their own line handling. Move it, with LineCol, WideLineCol,
WideEncoding and WideChar, into a small crate that only depends on
pgls_text_size and rustc-hash. No behaviour change.
The WASM bindings had their own position conversion, which treats the \r of
a \r\n as part of the line break (#969), while the language server's index
clamped a column past the end of a CRLF line to the \n and reported an
offset between \r and \n as a column after the \r. Neither is a position the
LSP allows.

The shared LineIndex now follows the WASM rules: the end of a line is before
its \r\n, an offset between \r and \n is the end of its line, and an offset
past the end of the text is the end of the text. A column inside a
character is the start of the character. The WASM bindings keep a LineIndex
per document and convert positions with it.
Keep the index in line_index.rs, nearly unchanged, with the position types
in lib.rs and the tests in tests.rs, so that git still follows the file
from pgls_lsp when merging branches that change it.
…/wasm-line-index

# Conflicts:
#	crates/pgls_line_index/src/lib.rs
# Conflicts:
#	crates/pgls_lsp/src/session.rs
@psteinroe
psteinroe added this pull request to stack #1100 November 2, 2026 12:50
# Conflicts:
#	ARCHITECTURE.md
#	crates/pgls_line_index/src/lib.rs
#	crates/pgls_line_index/src/line_index.rs
#	crates/pgls_lsp/src/adapters/mod.rs
# Conflicts:
#	crates/pgls_line_index/src/lib.rs
#	crates/pgls_line_index/src/tests.rs
Base automatically changed from refactor/wasm-line-index to main November 6, 2026 19:59
@psteinroe
psteinroe merged commit eeb3b80 into main Nov 6, 2026
12 checks passed
@psteinroe
psteinroe deleted the fix/fix-all-crlf branch November 6, 2026 20:20
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.

2 participants