Skip to content

oxfmt/lsp: newline with LF to CRLF text edit #23462

Description

@Sysix

Background

Original reported by @nrayburn-tech in oxc-project/oxc-intellij-plugin#477 (comment)

Setup

  • oxfmt setting endOfLine: 'crlf'
  • File content with LF, example debugger;\ndebugger;\n

Problem

When formatting the file will, oxfmt --lsp will generate internally debugger;\r\ndebugger;\r\n.
Then it calculates the minimal text edit.
The minimal text edit on this example is: \r\ndebugger;\r.
The result is returned to the editor.
The editor now sees the solo \r at the end, and will append a second line, next to the \n line.

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#textDocuments

Positions are line end character agnostic, so you cannot specify a position that denotes \r|\n or \n| where | represents the character offset.

Expected

The minimal text edit should be \r\ndebugger;\r\n, and covering the \n position too, so the editor knows that we want to replace the line, instead of appending one.

Metadata

Metadata

Assignees

Labels

A-editorArea - Editor and Language ServerA-formatterArea - Formatter

Type

Fields

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions