Skip to content

Preserve the input's newline style instead of forcing platform newlines #209

Description

@webdevred

Newline handling is currently tied to the build platform. The formatter converts \n to \r\n only on Windows builds, via replaceNewlines behind ENABLE_WINDOWS_NEWLINES, and only in the CLI file writing path. Two problems follow:

  1. It ignores the input file's actual newline style. A CRLF file formatted on Linux comes out LF, and an LF file formatted on Windows comes out CRLF. The tool changes a property of the file the user did not ask to change.

  2. formatNode itself returns LF, so any consumer that does not replicate the CLI's platform logic gets LF regardless. The language server (now in webdevred/jbeam-edit-lsp) consumes formatNode directly and therefore always emits LF, silently converting CRLF documents.

Better: detect the input's newline style and preserve it, independent of platform. A CRLF file stays CRLF, an LF file stays LF. Expose this so the CLI and the language server share one mechanism rather than each reimplementing it.

Related consumer: runFormatNode in webdevred/jbeam-edit-lsp (src/JbeamEdit/LSP/Handlers/Formatting.hs).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions