Skip to content

fix(parser): keep the \r of a CRLF line out of comment spans - #19504

Merged
kronberger-droid merged 1 commit into
nushell:mainfrom
kronberger-droid:fix-crlf-doc-comments
Nov 13, 2026
Merged

kronberger-droid merged 1 commit into
nushell:mainfrom
kronberger-droid:fix-crlf-doc-comments

Conversation

@kronberger-droid

@kronberger-droid kronberger-droid commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Description

In a file with CRLF line endings the lexer ended a comment at the \n, thus the \r before it became part of the Comment span.
Every doc comment built from those spans carried it, so def and alias descriptions and module comments ended in \r.
It used to stay invisible, since the menu sent it raw and it only moved the cursor to column 0.
reedline 0.53 shows control characters instead of sending them, so the completion menu now prints it as ^M.

The comment span now stops before a \r that directly precedes the \n.
curr_offset still advances to the \n, so the main loop skips the \r as before and emits the same Eol token as on LF.
Since no comment span can carry the \r anymore, the "\r\n\r\n" split in build_desc is dead and removed.

Tests: lex_comment_crlf and lex_comment_empty_crlf in test_lex.rs check the comment span and that the Eol still lands on the \n.
Two tests expected the old \r and now assert the clean value: commands_from_crlf_source_have_extra_description no longer trims it before comparing, and the nu-lsp completion tests drop their Windows-only "detail\r", since git checks those fixtures out as CRLF there.
doc_comments_from_crlf_source adds alias and module descriptions from a CRLF source, which nothing covered before.
The full nu-parser and nu-lsp suites pass, the latter also with all LSP fixtures converted to CRLF, and sourcing a CRLF script now gives clean description and extra_description in scope commands.

Out of scope: string literals in a CRLF file still keep their \r\n ("a<CRLF>b" evaluates to "a\r\nb").
Normalizing line endings once when a file is loaded would fix that too, but it shifts spans against the editor's buffer and changes string semantics, so that wants its own discussion.

User-facing changes (Release notes)

Fixed an issue where commands defined in a script with CRLF (Windows) line endings showed a stray ^M at the end of their description, for example in the completion menu.

Additional notes

fixes #19499

AI:R READ

A comment ended at the `\n`, thus on CRLF files every doc comment
description ended in `\r`. It went unnoticed until reedline 0.53
started escaping control characters, which shows it as `^M` in the
completion menu (nushell#19499).

`curr_offset` still stops at the `\n` so the main loop drops the `\r`
and emits the same `Eol` as on LF. The `"\r\n\r\n"` split in
`build_desc` patched the same leak on the consumer side and is gone,
as are the tests that expected it: the `trim_end_matches('\r')` in
the CRLF extra description test and the Windows-only `"detail\r"` in
the nu-lsp completion tests, whose fixtures git checks out as CRLF
there.
@fdncred

fdncred commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

are we ready to land this?

@kronberger-droid
kronberger-droid merged commit a93aaef into nushell:main Nov 13, 2026
14 checks passed
@kronberger-droid

Copy link
Copy Markdown
Contributor Author

@fdncred Yeah landed it.

@github-actions github-actions Bot added this to the v0.118.0 milestone Nov 13, 2026
@kronberger-droid
kronberger-droid deleted the fix-crlf-doc-comments branch November 13, 2026 16:50
@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:parser Issues related to parsing notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nushell shows extra ^M in tab-completion decsriptions when scripts using CRLF line endings

2 participants