Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Added option `block_newline_gaps` to determine whether newline gaps at the start / end of blocks should be preserved. Defaults to `Never`, which is the original behaviour. ([#857](https://github.com/JohnnyMorganz/StyLua/pull/857))
- StyLua can now run in a language server mode. Start StyLua with `stylua --lsp` and connect with a language client. ([#936](https://github.com/JohnnyMorganz/StyLua/issues/936))

### Changed

Expand Down
87 changes: 73 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ path = "src/cli/main.rs"
bench = false

[features]
default = ["editorconfig", "wasm-bindgen"]
default = ["editorconfig", "wasm-bindgen", "lsp"]
serialize = []
fromstr = ["strum"]
luau = ["full_moon/roblox"]
Expand All @@ -33,6 +33,7 @@ lua54 = ["lua53", "full_moon/lua54"]
luajit = ["full_moon/luajit"]
cfxlua = ["lua54", "full_moon/cfxlua"]
editorconfig = ["ec4rs"]
lsp = ["lsp-server", "lsp-types", "lsp-textdocument"]

[dependencies]
anyhow = "1.0.75"
Expand All @@ -56,6 +57,9 @@ strum = { version = "0.25.0", features = ["derive"], optional = true }
thiserror = "1.0.49"
threadpool = "1.8.1"
toml = "0.8.1"
lsp-server = { version = "0.7", optional = true }
lsp-types = { version = "0.97", optional = true }
lsp-textdocument = { version = "0.4.2", optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = { version = "0.2.81", optional = true }
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,20 @@ Requires sorting is off by default. To enable it, add the following to your `sty
enabled = true
```

### Language Server Mode

StyLua can run as a language server, connecting with language clients that follow the [Language Server Protocol](https://microsoft.github.io/language-server-protocol/).
It will then respond to `textDocument/formatting` and `textDocument/rangeFormatting` requests.
Formatting is only performed on files with a `lua` or `luau` language ID.

You can start the language server by running:

```sh
stylua --lsp
```

StyLua will listen to LSP messages on stdin and respond on stdout.

## Configuration

StyLua has opinionated defaults, but also provides a few options that can be set per project.
Expand Down Expand Up @@ -293,7 +307,7 @@ StyLua only offers the following options:
| `quote_style` | `AutoPreferDouble` | Quote style for string literals. Possible options: `AutoPreferDouble`, `AutoPreferSingle`, `ForceDouble`, `ForceSingle`. `AutoPrefer` styles will prefer the specified quote style, but fall back to the alternative if it has fewer string escapes. `Force` styles always use the specified style regardless of escapes. |
| `call_parentheses` | `Always` | Whether parentheses should be applied on function calls with a single string/table argument. Possible options: `Always`, `NoSingleString`, `NoSingleTable`, `None`, `Input`. `Always` applies parentheses in all cases. `NoSingleString` omits parentheses on calls with a single string argument. Similarly, `NoSingleTable` omits parentheses on calls with a single table argument. `None` omits parentheses in both cases. Note: parentheses are still kept in situations where removal can lead to obscurity (e.g. `foo "bar".setup -> foo("bar").setup`, since the index is on the call result, not the string). `Input` removes all automation and preserves parentheses only if they were present in input code: consistency is not enforced. |
| `space_after_function_names` | `Never` | Specify whether to add a space between the function name and parentheses. Possible options: `Never`, `Definitions`, `Calls`, or `Always` |
| `block_newline_gaps` | `Never` | Specify whether to preserve leading and trailing newline gaps for blocks. Possible options: `Never`, `Preserve` |
| `block_newline_gaps` | `Never` | Specify whether to preserve leading and trailing newline gaps for blocks. Possible options: `Never`, `Preserve` |
| `collapse_simple_statement` | `Never` | Specify whether to collapse simple statements. Possible options: `Never`, `FunctionOnly`, `ConditionalOnly`, or `Always` |

Default `stylua.toml`, note you do not need to explicitly specify each option if you want to use the defaults:
Expand Down
Loading
Loading