Skip to content

formatter: support TextEdit LSP struct #13629

@Sysix

Description

@Sysix

Starting on working to implement oxfmt into the language server, the first problem I found is that the service of oxfmt will check if the complete source code is changed and modifies it

let code = Formatter::new(&allocator, options).build(&ret.program);
let elapsed = start_time.elapsed();
let is_changed = source_text != code;

The Language Server Protocol supports formatting too, but tells the client what to change.
This happens normally with Range/Span and the new source text:
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_formatting

Feature request:

Implement a logic, so the server can send the partial source text, which should be modified, to the client.

Response:
result: TextEdit[] | null describing the modification to the document to be formatted.
error: code and message set in case an exception happens during the formatting request.

Other solution:

Just send the complete text file. Do not know how this will result into text cursor position and maybe other problems.

Metadata

Metadata

Assignees

Labels

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

Priority

None yet

Start date

None yet

Target date

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions