zed icon indicating copy to clipboard operation
zed copied to clipboard

Ruff format on save doesn't work during zed session until I push changes to server settings

Open lowrollr opened this issue 10 months ago • 8 comments

Summary

Ruff format on save doesn't work during a zed remote session until I push changes to server settings. In my case, I'm simply deleting all the content in the settings.json file, saving, and then adding back the original content.

Local Settings:

{
  "features": {
    "inline_completion_provider": "supermaven"
  },
  "assistant": {
    "default_model": {
      "provider": "zed.dev",
      "model": "claude-3-5-sonnet-latest"
    },
    "inline_alternatives": [
      {
        "provider": "zed.dev",
        "model": "gpt-4o"
      }
    ],
    "version": "2"
  },
  // I also have remote connection settings here
  "ui_font_size": 16,
  "buffer_font_size": 16,
  "theme": {
    "mode": "system",
    "light": "One Light",
    "dark": "Gruvbox Dark Hard"
  },
  "active_pane_modifiers": {
    "inactive_opacity": 0.5,
    "border_size": 0.0,
    "magnification": 1.5
  },
  "autosave": "on_focus_change",
  "autoscroll_on_clicks": true,
  "base_keymap": "VSCode",
  "buffer_font_family": "Fira Code",
  "centered_layout": {
    "left_padding": 0.0,
    "right_padding": 0.0
  },
  "inline_completions": {
    "disabled_globs": [".env", "*.md", "*.txt", "*.json", "*.jsonl"]
  },
  "inline_completions_disabled_in": ["comment"],
  "current_line_highlight": "all",
  "cursor_shape": "underline",
  "scrollbar": {
    "show": "always",
    "cursors": true,
    "git_diff": true,
    "search_results": true,
    "selected_symbol": true,
    "diagnostics": "none",
    "axes": {
      "horizontal": false
    }
  },
  "tab_bar": {
    "show": true,
    "show_nav_history_buttons": false
  },
  "tabs": {
    "close_position": "right",
    "file_icons": false,
    "git_status": false,
    "activate_on_close": "history",
    "always_show_close_button": false
  },
  "toolbar": {
    "breadcrumbs": true,
    "quick_actions": false
  },
  "enable_language_server": true,
  "ensure_final_newline_on_save": true,
  "terminal": {
    "detect_venv": {
      "on": {
        // Default directories to search for virtual environments, relative
        // to the current working directory. We recommend overriding this
        // in your project's settings, rather than globally.
        "directories": [".venv", "venv"],
        // Can also be `csh`, `fish`, and `nushell`
        "activate_script": "default"
      }
    }
  }
}

Server Settings:

{
    "enable_language_server": true,
    "ensure_final_newline_on_save": null,
    "lsp": {
        "ruff": {
            "initialization_options": {
                "settings": {
                    // Ruff server settings goes here
                    "lineLength": 80,
                    "lint": {
                        "extendSelect": ["I"]
                    }
                }
            }
        }
    },
    "languages": {
        "Python": {
            "language_servers": ["ruff"],
            "format_on_save": "on",
            "formatter": [
                {
                    "code_actions": {
                        "source.organizeImports.ruff": true,
                        "source.fixAll.ruff": true
                    }
                },
                {
                    "language_server": {
                        "name": "ruff"
                    }
                }
            ]
        }
    }
}

Steps to trigger the problem:

  1. Start a remote connection
  2. Attempt to format a Python file
  3. Delete all lines in server settings.json and save
  4. Restore all lines in server settings.json and save
  5. Now ruff works

Is there something I've configured incorrectly here?

Zed Version and System Specs

Zed: v0.170.2 (Zed) OS: macOS 14.5.0 Memory: 16 GiB Architecture: aarch64

lowrollr avatar Feb 03 '25 04:02 lowrollr

This is super wierd. Would you mind looking through your zed log (zed: open log) and language server log (debug: open language server logs and then select ruff from the lsp dropdown on the left, and click through the different lsp logs under the Server Logs button) and let me know if you see anything weird or any errors that seem related?

note: sorry if the lsp log instructions are confusing, feel free to ask questions if you're confused. It's a kinda scuffed UI and we're hoping to improve it at some point

probably-neb avatar Feb 04 '25 17:02 probably-neb

Sorry, missed your response here.

In zed logs I see a lot of: 2025-03-24T01:32:22.899698-07:00 [ERROR] language not found

When I first open Zed, I don't see ruff listed in the lsp dropdown. Upon applying the fix above, I see it listed twice! I don't see any messages under either ruff instance though

lowrollr avatar Mar 24 '25 08:03 lowrollr

Weird. Would you make sure you're on the latest version of Zed and try again, and then copy paste the zed log contents here? I'd like to take a look at them if possible

probably-neb avatar Mar 24 '25 16:03 probably-neb

I have a similar problem - formatting with ruff doesn't work. But after I changed the autosave setting from “after_delay” to “on_focus_change”, everything worked.

4uku avatar Apr 02 '25 13:04 4uku

Hey @lowrollr is this issue still occuring? We've had some changes around formatting recently that may have improved things.

Additionally, @4uku, would you mind creating a new issue for that? It sounds like you're able to reproduce it consistently which makes it easier for us to fix!

probably-neb avatar Apr 04 '25 14:04 probably-neb

Fwiw, as of today the latest stable (0.188.5) still has the issue

sygi avatar May 31 '25 14:05 sygi

Could you share your settings @sygi? If you have any MCP servers configured please make sure to omit any keys :)

probably-neb avatar Jun 03 '25 10:06 probably-neb

I don't have any MCP. I'm attaching my (redacted) settings below, but I'm not sure if I see the same issue as above:

{
  "ssh_connections": [
    {
      "host": "sygi-workspace",
      "projects": [
        {
          "paths": ["/home/sygi/code"]
        }
      ]
    }
  ],
  "telemetry": {
    "diagnostics": false,
    "metrics": false
  },
  "tab_size": 2,
  "lsp": {
    "pyright": {
      "settings": {
        "python.analysis": {
          "diagnosticMode": "workspace",
          "typeCheckingMode": "basic"
        }
      }
    },
    "ruff": {
      "initialization_options": {
        "settings": {
          "lint": {
            "ignore": ["C901", "W291"]
          }
        }
      }
    }
  },
  "show_completions_on_input": true,
  "languages": {
    "Python": {
      "tab_size": 2,
      "format_on_save": "on",
      "language_servers": ["pyright", "ruff"],
      "formatter": [
        {
          "code_actions": {
            "source.organizeImports.ruff": true,
            "source.fixAll.ruff": true
          }
        },
        {
          "language_server": {
            "name": "ruff"
          }
        }
      ]
    }
  }
}

Apart from these, I have ruff.toml settings in /home/sygi/code/ and project settings with the same Python languages section and a pyright setting for server venv.

What I see is:

  1. the ruff server starts non-deterministically: sometimes I see ruff in the LSP list, sometimes I don't. Even if it isn't there, it sometimes works (and sometimes doesn't).
  2. sometimes ruff stops working when the session is open
  3. even when ruff works there is no logs related to ruff in the LSP pane.
  4. ruff doesn't adhere to the settings, neither in settings.json nor in ruff.toml (eg. corrects trailing whitespace despite ignore W291).

sygi avatar Jun 03 '25 13:06 sygi

@probably-neb Hi, I have this annoying problem 100% time reproduced( What information would be helpful to debug it?

I tried to take a look at Ruff LSP logs but server doesn't even appear in the list Image

Relevant config part

        "Python": {
            "formatter": [
                {
                    "language_server": {
                        "name": "ruff"
                    }
                }
            ],
            "language_servers": ["pyright", "ruff", "!pylsp"]
        }

Even uploading settings.json in advance before connecting to Remote host doesn't help. But everything starts to work normally once I do touch settings.json on remote, so I guess it may be something related to file watching subsystem.

ssergiienko avatar Jul 15 '25 12:07 ssergiienko

I have the same issue. Previously I would just push the settings to remote and it would work, but it doesn't anymore.

It would be really helpful if there were logs somewhere which actually showed what the issue was but the default logs don't show anything.

vikramsg avatar Aug 06 '25 11:08 vikramsg

@ssergiienko Remote LSP log support was just added recently in #37083, it is currently in preview but will be released to stable this Wednesday. If you run the latest preview release or stable after updating this coming Wednesday (Sept 10th) you should be able to look at the Ruff server logs

probably-neb avatar Sep 08 '25 15:09 probably-neb