zed
zed copied to clipboard
TOML: taplo lsp config not working
Summary
Description
According to the Zed TOML extension documentation, adding the following configuration to settings.json should enable TOML formatting via taplo without requiring a .taplo.toml file in the project directory:
"lsp": {
"taplo": {
"settings": {
"array_auto_collapse": false
}
}
}
However, after adding this configuration, running editor:format does not format TOML files as expected.
Steps to Reproduce
- Open
settings.jsonvia Zed preferences. - Add the above
lspconfiguration fortaplo. - Create a TOML file (e.g.,
example.toml) with unformatted content, such as:[section] key = [1,2,3] - Run
editor:format - Observe that the TOML file remains unformatted.
Expected Behavior
Running editor:format should format the TOML file according to taplo settings.
Actual Behavior
The TOML file is not formatted, and no changes are applied.
Apologies if this is due to a misunderstanding of the TOML extension or taplo configuration.
Zed Version and System Specs
Zed 0.182.9 – /usr/lib/zed/zed-editor 6.14.2-arch1-1
I can‘t reproduce it; it works well on my machine. The toml extension auto-downloads and runs taplo LSP.
Check taplo downloaded to ~/.local/share/zed/extensions/work/toml and verified it's running with pgrep taplo while zed running and open a toml file.
Check taplo downloaded to ~/.local/share/zed/extensions/work/toml
taplo is installed correctly 👍
verified it's running with pgrep taplo while zed running and open a toml file
pgrep taplo
19258
seems like its running, but the editor:format has still no effect. However, the lsp works fine, if I make a syntax error, the error is displayed.
Just tried it on my other machine, with the same result.
Just added a .taplo.toml to the root dir of the project, the issue persists. So, I guess it's not an issue with the json config.
~~There is a callout warning on the documentation that for certain editors should use camel-case instead. So array_auto_collapse must be arrayAutoCollapse. I tried it and seems now it is taking some of the settings, but looks not very consistent to me... Worth spending more time testing the behaviour of this.~~
In some environments (e.g. in Visual Studio Code and JavaScript) the option keys are camelCase to better fit the conventions. For example align_entries becomes alignEntries.
In some environments (e.g., Visual Studio Code), one needs to reload the extension to let the settings take effect.
Edit: not working either.
LSP settings are not working for me either. Default formatting works, but I'm not able to customize it.
FWIW, I had a quick look to https://github.com/zed-industries/zed/blob/10ded0ab75980ee42ec2e2f225b77c3dbd8ed6e4/extensions/toml/src/toml.rs, and I'm not seeing any code to deal with LSP settings, except for the binary path.
I'm not familiar at all with this code base, so surely I'm wrong, but it's quite different from https://github.com/zed-industries/zed/blob/10ded0ab75980ee42ec2e2f225b77c3dbd8ed6e4/extensions/ruff/src/ruff.rs for example.
I've been experiencing this issue with the lua lsp. everything works fine with using a .luarc.json but I would really like all my settings to be integrated within zed.
to reproduce (snippet from settings.json):
"lsp": {
"lua-language-server": {
"settings": {
// any configuration
}
}
}
can confirm the lua issue 👍🏿
I don't believe that taplo supports providing settings via LSP settings keys and you must use .taplo.toml. I believe you may have been following an example in zed toml docs which I removed in https://github.com/zed-industries/zed/commit/6db974dd324e1b7f41f09a29c04e1234cc99723c
My apologies. Of note, Taplo also does not watch .taplo.toml for config changes you will need to manually trigger editor: restart language server or by reloading your zed workspace.
@nealxm / @domi413 Please open issues with the lua extension here:
- https://github.com/zed-extensions/lua/
Sorry, could someone explain the correct TOML extension installation and configuration steps to make editor:format work?
I installed the TOML v0.1.4 extension and opened a TOML file. I can see the PID of a running taplo process using pgrep taplo. Syntax errors in TOML files are highlighted, but editor:format does nothing when I introduce unformatted TOML code.
I'm on NixOS unstable with Zed 0.189.5. I haven't added anything TOML related in settings.json. Formatting works fine for e.g. Python and .nix files.
Note: Formatting does work if I install taplo globally on my system and add this in settings.json:
{
"languages": {
"TOML": {
"language_servers": ["taplo"],
"formatter": {
"external": {
"command": "taplo",
"arguments": ["format", "-"]}}}}}
But if I understand correctly this shouldn't be necessary since the TOML extension downloads and runs its own taplo instance?
@akaihola
- Is there anything in your Zed log?
- Open
dev: language server logsthen selecttaploand RPC messages is there anything of not there? - Do you perhaps have a
.zed/settings.jsoninside your project which overrides your TOML.formatter in user settings? (like the zed repo does) https://github.com/zed-industries/zed/blob/c35f22dde0dd4adfae1a6522a991e3e32dc55214/.zed/settings.json#L7-L10
The extension will prefer taplo in your path, but if it doesn't find one it will download a binary directly -- never sure how much nix changes that. https://github.com/zed-industries/zed/blob/c35f22dde0dd4adfae1a6522a991e3e32dc55214/extensions/toml/src/toml.rs#L35
@notpeter I've upgraded Zed since your message above, and now my TOML files are automatically formatted as soon as I hit Ctrl+Shift+I (Editor::format) or move the focus out of the editor.
Is there anything in your Zed log?
Open
dev: language server logsthen selecttaploand RPC messages is there anything of not there?Do you perhaps have a
.zed/settings.jsoninside your project which overrides your TOML.formatter in user settings? (like the zed repo does)[zed/.zed/settings.json](https://github.com/zed-industries/zed/blob/c35f22dde0dd4adfae1a6522a991e3e32dc55214/.zed/settings.json#L7-L10) Lines 7 to 10 in [c35f22d](/zed-industries/zed/commit/c35f22dde0dd4adfae1a6522a991e3e32dc55214) "TOML": { "formatter": "prettier", "format_on_save": "off" },The extension will prefer taplo in your path, but if it doesn't find one it will download a binary directly -- never sure how much nix changes that.
zed/extensions/toml/src/toml.rs
Line 35 in c35f22d
if let Some(path) = worktree.which("taplo") {
For a while now i've noticed that the formatting has stopped working on my toml files. RPC Messages show only Send and no receive messages.
Zed: v0.195.5 (Zed)
OS: macOS 15.5.0
Memory: 64 GiB
Architecture: aarch64
* Server: taplo (id 13)
* Binary: LanguageServerBinary {
path: "/Users/miha/Library/Application Support/Zed/extensions/work/toml/taplo-0.10.0/taplo",
arguments: [
"lsp",
"stdio",
],
env: Some(
{
"TMPDIR": "/var/folders/bk/l0q154t55v962lzb0rxf0x880000gn/T/",
"ZSH": "/Users/miha/.oh-my-zsh",
"SHLVL": "1",
"LIBCLANG_PATH": "/Users/miha/.rustup/toolchains/esp/xtensa-esp32-elf-clang/esp-16.0.4-20231113/esp-clang/lib",
"LS_COLORS": "di=1;36:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43",
"CAML_LD_LIBRARY_PATH": "/Users/miha/.opam/default/lib/stublibs:/opt/homebrew/lib/ocaml/stublibs:/opt/homebrew/lib/ocaml",
"__CF_USER_TEXT_ENCODING": "0x1F5:0x24:0x42",
"SSH_AUTH_SOCK": "/private/tmp/com.apple.launchd.4oINjqUCth/Listeners",
"LSCOLORS": "Gxfxcxdxbxegedabagacad",
"HOME": "/Users/miha",
"LOGNAME": "miha",
"XPC_FLAGS": "0x0",
"PATH": "...",
"OPAM_SWITCH_PREFIX": "/Users/miha/.opam/default",
"LESS": "-R",
"__CFBundleIdentifier": "dev.zed.Zed",
"USER": "miha",
"OLDPWD": "/",
"_": "/Applications/Zed.app/Contents/MacOS/zed",
"XPC_SERVICE_NAME": "0",
"PAGER": "less",
"COMMAND_MODE": "unix2003",
"ZED_ENVIRONMENT": "worktree-shell",
"SHELL": "/bin/zsh",
"OCAML_TOPLEVEL_PATH": "/Users/miha/.opam/default/lib/toplevel",
"RAVEDUDE_PORT": "/dev/cu.usbmodem2112401",
"PWD": "/Users/miha/Documents/development/rust/matter",
},
),
}
* Registered workspace folders:
/Users/miha/Documents/development/rust/matter
* Capabilities: {
"textDocumentSync": 1,
"hoverProvider": true,
"completionProvider": {
"resolveProvider": false,
"triggerCharacters": [
".",
"=",
"[",
"{",
",",
"\""
]
},
"documentSymbolProvider": true,
"documentFormattingProvider": true,
"renameProvider": {
"prepareProvider": true
},
"documentLinkProvider": {},
"foldingRangeProvider": true,
"workspace": {
"workspaceFolders": {
"supported": true,
"changeNotifications": true
}
},
"semanticTokensProvider": {
"workDoneProgress": false,
"legend": {
"tokenTypes": [
"tomlArrayKey",
"tomlTableKey"
],
"tokenModifiers": [
"readonly"
]
},
"range": false,
"full": true
}
}
* Configuration: {}
.taplo.toml
[formatting]
column_width = 250
array_auto_collapse = true
align_comments = true
align_entries = true
indent_entries = true
reorder_keys = true
And yes, taplo is running