zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
51k stars 3.16k forks source link

ruff settings not applied correctly #20576

Open fletcher97 opened 2 weeks ago

fletcher97 commented 2 weeks ago

Check for existing issues

Describe the bug / provide steps to reproduce it

I tried to setup ruff for python formatting but I'm having issues with the configuration. According to the documentation, i should be able to place all the ruff setting I wish to set inside lsp.ruff.initialization_options.settings. That certainly does work for the provided examples but anything else I try to change doesn't seem to work.

I tried changing indent-width, format.indent-style and format.quote-style. I noticed that the option line-length was changed to lineLength so I tried multiple permutations of the other options with and without the dash (-), with and without capital letter. I tried to place the format option inside and outside an object named format. Nothing I tried worked.

I also tried to install ruff from my package manager to see if that would make a difference. It didn't. The version was 0.7.3 (Same as the one installed through zed and currently the latest release)

To make sure ruff was working I created a pyproject.toml and tried changing in there the options mentioned above. The values entered on that file worked fine.

My guess is that, either I'm entering the wrong config name/value or that zed isn't correctly passing my configuration to ruff.

Environment

Zed: v0.160.7 (Zed) OS: Linux Wayland arch unknown Memory: 61.9 GiB Architecture: x86_64 GPU: AMD Radeon RX 7900 GRE || AMD open-source driver || 2024.Q3.3 (LLPC)

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your Zed.log file to this issue.

From my logs I extracted the part where zed tries to reload the language server when I change values in the settings. Not sure if this will help. the first snippet is with ruff installed only through zed and the second is with it installed through my package manager.

Zed.log ``` 2024-11-13T01:28:14.626421199+01:00 [INFO] stopping language server ruff 2024-11-13T01:28:14.637289283+01:00 [ERROR] oneshot canceled 2024-11-13T01:28:14.637401855+01:00 [ERROR] cannot read LSP message headers 2024-11-13T01:28:14.637538432+01:00 [INFO] attempting to start language server "ruff", path: "/home/fletcher/Documents/twAnalyzer", id: 10 2024-11-13T01:28:14.637943806+01:00 [INFO] starting language server process. binary path: "/home/fletcher/.local/share/zed/extensions/work/ruff/ruff-0.7.3/ruff-x86_64-unknown-linux-gnu/ruff", working directory: "/home/fletcher/Documents/twAnalyzer", args: ["server"] ``` ``` 2024-11-13T11:04:20.699317397+01:00 [INFO] stopping language server ruff 2024-11-13T11:04:20.709789367+01:00 [ERROR] oneshot canceled 2024-11-13T11:04:20.709919592+01:00 [ERROR] cannot read LSP message headers 2024-11-13T11:04:20.71007255+01:00 [INFO] attempting to start language server "ruff", path: "/home/fletcher/Documents/twAnalyzer", id: 17 2024-11-13T11:04:20.710379559+01:00 [INFO] starting language server process. binary path: "/usr/bin/ruff", working directory: "/home/fletcher/Documents/twAnalyzer", args: ["server"] ```
0xtimsb commented 1 week ago

can you provide your settings.json?

fletcher97 commented 1 week ago

Sure. Here is the file. I left a few of the attempts I did commented out. Neither the commented out nor the active ones work. Only lineLength seems to work.

settings.json ```jsonc // Zed settings // // For information on how to configure Zed, see the Zed // documentation: https://zed.dev/docs/configuring-zed // // To see all of Zed's default settings without changing your // custom settings, run `zed: open default settings` from the // command palette (cmd-shift-p / ctrl-shift-p) { "base_keymap": "VSCode", "telemetry": { "diagnostics": false, "metrics": false }, "ui_font_size": 16, "buffer_font_size": 16, "theme": { "mode": "system", "light": "One Dark", "dark": "One Dark" }, "features": { "inline_completion_provider": "none" }, "project_panel": { "dock": "right" }, "preferred_line_length": 120, "hard_tabs": true, "auto_update": true, "prettier": { "allowed": false }, "languages": { "Python": { "language_servers": [ "pyright", "ruff", ], "format_on_save": "on", "formatter": [ { "code_actions": { "source.fixAll.ruff": true, "source.organizeImports.ruff": true } }, { "language_server": { "name": "ruff" } } ] }, "JSON": { "format_on_save": "on", "formatter": [ { "external": { "command": "jq", "arguments": [ "-S", "." ] } } ] } }, "lsp": { "pyright": { "settings": { "python.analysis": { "diagnosticMode": "workspace" // "typeCheckingMode": "strict" } // "python": { // "pythonPath": ".venv/bin/python" // } } }, "ruff": { "initialization_options": { "settings": { "indent-width": 8, "lineLength": 120, "quoteStyle": "single", // "quoteStyle": "single", // "indent-style": "tab", "format": { // "tabWidth": 8, "indent-style": "tab" }, "lint": { "extendSelect": [ "I" ] } } } } } } ```