Skip to content

Commit 98e29c6

Browse files
authored
Smaller text edits in lsp formatting handler (#1031)
* Reply with correct server information * Compute more granular textedits for formatting requests * Use byte diff instead of line diff * Add missing range formatting capability * Use correct package name * Test exact edits returned by formatting handler * Update CHANGELOG.md * Add initialization option to respect editor's formatting options
1 parent 3e86a9d commit 98e29c6

File tree

5 files changed

+231
-45
lines changed

5 files changed

+231
-45
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- The language server has an initialization option called `respect_editor_formatting_options`.
13+
If it's true, the formatting handler will override the configurations `indent-width` and `indent-type` with values from [FormattingOptions](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#formattingOptions)
14+
15+
### Changed
16+
17+
- In language server mode, compute the difference between the unformatted and formatted document and only respond with the changes.
18+
- Include `serverInfo` in the language server's [`InitializeResponse`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initializeResult)
19+
1020
### Fixed
1121

1222
- Fixed comments lost from expression after parentheses are removed when we are attempting to "hang" the expression. ([#1033](https://github.com/JohnnyMorganz/StyLua/issues/1033))
23+
- `document_range_formatting_provider` field missing from `ServerCapabilities`
1324

1425
## [2.2.0] - 2025-09-14
1526

Cargo.lock

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ num_cpus = "1.16.0"
5252
regex = "1.10.2"
5353
serde = "1.0.188"
5454
serde_json = "1.0.108"
55-
similar = { version = "2.3.0", features = ["text", "inline", "serde"] }
55+
similar = { version = "2.3.0", features = ["text", "inline", "serde", "bytes"] }
5656
strum = { version = "0.25.0", features = ["derive"], optional = true }
5757
thiserror = "1.0.49"
5858
threadpool = "1.8.1"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ StyLua can run as a language server, connecting with language clients that follo
253253
It will then respond to `textDocument/formatting` and `textDocument/rangeFormatting` requests.
254254
Formatting is only performed on files with a `lua` or `luau` language ID.
255255

256+
If the initialization option `respect_editor_formatting_options` is set to `true`, the formatting handler will override the configurations `indent-width` and `indent-type` with values from [FormattingOptions](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#formattingOptions).
257+
256258
You can start the language server by running:
257259

258260
```sh

0 commit comments

Comments
 (0)