Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ruff: Pass --preview by default and make it configurable #15157

Closed
wants to merge 2 commits into from

Conversation

code-yeongyu
Copy link
Contributor

@code-yeongyu code-yeongyu commented Jul 25, 2024

Release Notes:

  • N/A

Although #15001 has merged to avoid passing --preview, executing without this flag is only supported on ruff binary versions higher than 0.5.3. Currently it does not work in environments where can't use latest ruff binary.

Therefore, we need to set --preview as the default option to support older versions, while also making it configurable through settings.

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Jul 25, 2024
@code-yeongyu code-yeongyu changed the title Make ruff extension to use preview server by default ruff: pass --preview by default and make it configurable Jul 25, 2024
@code-yeongyu code-yeongyu changed the title ruff: pass --preview by default and make it configurable ruff: Pass --preview by default and make it configurable Jul 25, 2024
@osiewicz
Copy link
Contributor

osiewicz commented Jul 25, 2024

FWIW, the user can already configure the flags passed to the language server:

"lsp": {
  "Ruff": {
    "binary": {
      "arguments": ["--preview"]
    }
  }
}

Given that, I'd err on the side of not adding it.
We could update docs to help users in older versions find their way around.

Edit: You need to pass in server as an argument as well. See this comment

@code-yeongyu
Copy link
Contributor Author

FWIW, the user can already configure the flags passed to the language server:


"lsp": {

  "Ruff": {

    "binary": {

      "arguments": ["--preview"]

    }

  }

}

Given that, I'd err on the side of not adding it.

We could update docs to help users in older versions find their way around.

Ah thats great.

I think it should be documented at least, since I had to look over ruff's release note and the zed's release note which is quite non-sense.

@pjv
Copy link

pjv commented Jul 25, 2024

@osiewicz

After installing the new extension, and using Zed preview v. 0.146.0 on a mac, when I use this:

"lsp": {
  "Ruff": {
    "binary": {
      "arguments": ["--preview"]
    }
  }
}

…in my settings.json, it seems to cause the ruff LSP to not work. (I also tried changing the name from Ruff to ruff). The ruff LSP from the extension works fine if I don’t include the above in my settings.json.

My goal is not actually to pass the —preview argument but instead to pass the —config argument with a path to my global ruff config, so I’ve tried every variation of one, the other or both of these arguments and in every case, using this method to send any kind of argument to the ruff LSP makes it die.

I am still able to use ruff as an external formatter using prior unofficial settings that don’t include the new ruff extension like this:

  "languages": {
    "Python": {
      "format_on_save": "on",
      "formatter": {
        "external": {
          "command": "bash",
          "arguments": [
            "-c",
            "ruff format --config=/Users/pjv/.config/ruff.toml --stdin-filename {buffer_path}"
          ]
        }
      }
    }
  }

Below is the log of starting Zed using this lsp configuration:

  "lsp": {
    "ruff": {
      "binary": {
        "arguments": ["--config=/Users/pjv/.config/ruff.toml"]
      }
    }
  }
2024-07-25T15:15:49.57658Z [INFO] ========== starting zed ==========
2024-07-25T15:15:49.578254Z [INFO] Opening main db
2024-07-25T15:15:49.582838Z [INFO] Using git binary path: Some("/Applications/Zed Preview.app/Contents/MacOS/git")
2024-07-25T15:15:49.831191Z [ERROR] theme not found: Ayu Dark Italic
2024-07-25T15:15:49.833312Z [INFO] extensions updated. loading 12, reloading 0, unloading 0
2024-07-25T15:15:49.977904Z [WARN] Theme "Ayu Dark Italic" is using a deprecated style property: scrollbar_thumb.background. Use `scrollbar.thumb.background` instead.
2024-07-25T15:15:49.978172Z [WARN] Theme "Ayu Light Italic" is using a deprecated style property: scrollbar_thumb.background. Use `scrollbar.thumb.background` instead.
2024-07-25T15:15:49.978492Z [WARN] Theme "Ayu Mirage Italic" is using a deprecated style property: scrollbar_thumb.background. Use `scrollbar.thumb.background` instead.
2024-07-25T15:15:49.981333Z [INFO] Opening main db
2024-07-25T15:15:50.043186Z [INFO] Opening main db
2024-07-25T15:15:50.047183Z [INFO] Opening main db
2024-07-25T15:15:50.184385Z [WARN] no language server found matching 'ruff'
2024-07-25T15:15:50.18466Z [INFO] starting language servers for Python: pyright
2024-07-25T15:15:50.184873Z [INFO] starting language server "pyright", path: "/Users/pjv/development/test/", id: 1
2024-07-25T15:15:50.185319Z [WARN] no language server found matching 'ruff'
2024-07-25T15:15:50.185528Z [INFO] starting language servers for Python: pyright
2024-07-25T15:15:50.20207Z [INFO] fetching latest version of language server "pyright"
2024-07-25T15:15:50.202374Z [INFO] Node runtime install_if_needed
2024-07-25T15:15:50.405111Z [INFO] Node runtime install_if_needed
2024-07-25T15:15:50.640623Z [INFO] starting language server. binary path: "/Users/pjv/Library/Application Support/Zed/node/node-v22.5.1-darwin-x64/bin/node", working directory: "/", args: ["/Users/pjv/Library/Application Support/Zed/copilot/copilot-v0.5.0/dist/agent.js", "--stdio"]
2024-07-25T15:15:51.122377Z [INFO] Language server with id 0 sent unhandled notification LogMessage:
{
  "level": 0,
  "message": "[DEBUG] [agent] [2024-07-25T15:15:51.117Z] Agent service starting",
  "metadataStr": "[DEBUG] [agent] [2024-07-25T15:15:51.117Z]",
  "extra": [
    "Agent service starting"
  ]
}
2024-07-25T15:15:51.124827Z [INFO] Language server with id 0 sent unhandled notification client/registerCapability:
{
  "registrations": [
    {
      "id": "f19d6676-d8a6-40a0-ab0b-68206029d65f",
      "method": "workspace/didChangeWorkspaceFolders",
      "registerOptions": {}
    }
  ]
}
2024-07-25T15:15:51.174969Z [INFO] Language server with id 0 sent unhandled notification LogMessage:
{
  "level": 0,
  "message": "[DEBUG] [agent] [2024-07-25T15:15:51.131Z] Telemetry initialized",
  "metadataStr": "[DEBUG] [agent] [2024-07-25T15:15:51.131Z]",
  "extra": [
    "Telemetry initialized"
  ]
}
2024-07-25T15:15:51.359579Z [INFO] downloading language server "pyright"
2024-07-25T15:15:51.360083Z [INFO] Node runtime install_if_needed
2024-07-25T15:15:51.567908Z [INFO] starting language server. binary path: "/Users/pjv/Library/Application Support/Zed/node/node-v22.5.1-darwin-x64/bin/node", working directory: "/Users/pjv/development/test/", args: ["/Users/pjv/Library/Application Support/Zed/languages/pyright/node_modules/pyright/langserver.index.js", "--stdio"]
2024-07-25T15:15:51.845428Z [INFO] Language server with id 1 sent unhandled notification window/logMessage:
{
  "type": 3,
  "message": "Pyright language server 1.1.373 starting"
}
2024-07-25T15:15:51.845678Z [INFO] Language server with id 1 sent unhandled notification window/logMessage:
{
  "type": 3,
  "message": "Server root directory: file:///Users/pjv/Library/Application%20Support/Zed/languages/pyright/node_modules/pyright/dist"
}
2024-07-25T15:15:51.850694Z [INFO] Language server with id 1 sent unhandled notification window/logMessage:
{
  "type": 3,
  "message": "Starting service instance \"\""
}
2024-07-25T15:15:51.86047Z [INFO] starting language servers for Python: pyright, ruff
2024-07-25T15:15:51.860689Z [INFO] starting language server "ruff", path: "/Users/pjv/development/test/", id: 2
2024-07-25T15:15:52.576506Z [INFO] language server 1: unregistered workspace/DidChangeWatchedFiles capability with id ca09d3f7-3c80-41e4-aa17-fed11fc1d56a
2024-07-25T15:15:52.63946Z [INFO] starting language server. binary path: "/usr/local/bin/ruff", working directory: "/Users/pjv/development/test/", args: ["--config=/Users/pjv/.config/ruff.toml"]
2024-07-25T15:15:52.649143Z [ERROR] cannot read LSP message headers
2024-07-25T15:15:52.649421Z [ERROR] failed to start language server "ruff": oneshot canceled
2024-07-25T15:15:52.649854Z [ERROR] server stderr: Some("error: `ruff <path>` has been removed. Use `ruff check <path>` instead.\n")
2024-07-25T15:15:52.650225Z [INFO] retrying installation of language server "ruff" in 1s
2024-07-25T15:15:52.650521Z [ERROR] Broken pipe (os error 32)
2024-07-25T15:15:52.650814Z [ERROR] server shut down
2024-07-25T15:15:53.126396Z [INFO] language server 1: unregistered workspace/DidChangeWatchedFiles capability with id 495e427f-84c6-4cad-ace6-1087f66d0c63
2024-07-25T15:15:53.698204Z [INFO] About to spawn test binary
2024-07-25T15:15:53.698448Z [WARN] test binary failed to launch
2024-07-25T15:15:53.69864Z [WARN] test binary check failed
2024-07-25T15:15:53.698819Z [INFO] beginning to reinstall server
2024-07-25T15:15:53.699021Z [INFO] deleting server container
2024-07-25T15:15:53.699336Z [ERROR] server container removal

Caused by:
    No such file or directory (os error 2)
2024-07-25T15:15:53.699615Z [INFO] starting language server "ruff", path: "/Users/pjv/development/test/", id: 3
2024-07-25T15:15:54.291517Z [INFO] starting language server. binary path: "/usr/local/bin/ruff", working directory: "/Users/pjv/development/test/", args: ["--config=/Users/pjv/.config/ruff.toml"]
2024-07-25T15:15:54.300332Z [ERROR] cannot read LSP message headers
2024-07-25T15:15:54.300629Z [ERROR] Broken pipe (os error 32)
2024-07-25T15:15:54.301012Z [ERROR] server shut down
2024-07-25T15:15:54.301254Z [ERROR] failed to start language server "ruff": oneshot canceled
2024-07-25T15:15:54.301525Z [ERROR] server stderr: Some("error: `ruff <path>` has been removed. Use `ruff check <path>` instead.\n")
2024-07-25T15:15:54.301783Z [INFO] retrying installation of language server "ruff" in 1s
2024-07-25T15:15:55.351791Z [INFO] About to spawn test binary
2024-07-25T15:15:55.352062Z [WARN] test binary failed to launch
2024-07-25T15:15:55.35235Z [WARN] test binary check failed
2024-07-25T15:15:55.352544Z [INFO] beginning to reinstall server
2024-07-25T15:15:55.352754Z [INFO] deleting server container
2024-07-25T15:15:55.353079Z [ERROR] server container removal

Caused by:
    No such file or directory (os error 2)
2024-07-25T15:15:55.353355Z [INFO] starting language server "ruff", path: "/Users/pjv/development/test/", id: 4
2024-07-25T15:15:55.959758Z [INFO] starting language server. binary path: "/usr/local/bin/ruff", working directory: "/Users/pjv/development/test/", args: ["--config=/Users/pjv/.config/ruff.toml"]
2024-07-25T15:15:55.96879Z [ERROR] cannot read LSP message headers
2024-07-25T15:15:55.969036Z [ERROR] Broken pipe (os error 32)
2024-07-25T15:15:55.969374Z [ERROR] failed to start language server "ruff": oneshot canceled
2024-07-25T15:15:55.969584Z [ERROR] server stderr: Some("error: `ruff <path>` has been removed. Use `ruff check <path>` instead.\n")
2024-07-25T15:15:55.969789Z [INFO] retrying installation of language server "ruff" in 1s
2024-07-25T15:15:55.969979Z [ERROR] server shut down
2024-07-25T15:15:57.019178Z [INFO] About to spawn test binary
2024-07-25T15:15:57.019382Z [WARN] test binary failed to launch
2024-07-25T15:15:57.019527Z [WARN] test binary check failed
2024-07-25T15:15:57.019667Z [INFO] beginning to reinstall server
2024-07-25T15:15:57.019832Z [INFO] deleting server container
2024-07-25T15:15:57.020117Z [ERROR] server container removal

Caused by:
    No such file or directory (os error 2)
2024-07-25T15:15:57.0204Z [INFO] starting language server "ruff", path: "/Users/pjv/development/test/", id: 5
2024-07-25T15:15:57.622554Z [INFO] starting language server. binary path: "/usr/local/bin/ruff", working directory: "/Users/pjv/development/test/", args: ["--config=/Users/pjv/.config/ruff.toml"]
2024-07-25T15:15:57.632004Z [ERROR] cannot read LSP message headers
2024-07-25T15:15:57.632262Z [ERROR] Broken pipe (os error 32)
2024-07-25T15:15:57.632575Z [ERROR] failed to start language server "ruff": oneshot canceled
2024-07-25T15:15:57.632791Z [ERROR] server stderr: Some("error: `ruff <path>` has been removed. Use `ruff check <path>` instead.\n")
2024-07-25T15:15:57.633001Z [INFO] retrying installation of language server "ruff" in 1s
2024-07-25T15:15:57.633197Z [ERROR] server shut down

It looks like the ruff extension is finding and running my global ruff install (/usr/local/bin/ruff)?

…and then maybe sending it a malformed query?

If I start up Zed in the same test python project without the above LSP config, it logs like this (and ruff is working, but without my settings):

2024-07-25T15:27:39.041549Z [INFO] ========== starting zed ==========
2024-07-25T15:27:39.043141Z [INFO] Opening main db
2024-07-25T15:27:39.0478Z [INFO] Using git binary path: Some("/Applications/Zed Preview.app/Contents/MacOS/git")
2024-07-25T15:27:39.286944Z [ERROR] theme not found: Ayu Dark Italic
2024-07-25T15:27:39.289023Z [INFO] extensions updated. loading 12, reloading 0, unloading 0
2024-07-25T15:27:39.402538Z [INFO] Opening main db
2024-07-25T15:27:39.438436Z [WARN] Theme "Ayu Dark Italic" is using a deprecated style property: scrollbar_thumb.background. Use `scrollbar.thumb.background` instead.
2024-07-25T15:27:39.438704Z [WARN] Theme "Ayu Light Italic" is using a deprecated style property: scrollbar_thumb.background. Use `scrollbar.thumb.background` instead.
2024-07-25T15:27:39.438925Z [WARN] Theme "Ayu Mirage Italic" is using a deprecated style property: scrollbar_thumb.background. Use `scrollbar.thumb.background` instead.
2024-07-25T15:27:39.497734Z [INFO] Opening main db
2024-07-25T15:27:39.502195Z [INFO] Opening main db
2024-07-25T15:27:39.57229Z [ERROR] No path or contents found for buffer
2024-07-25T15:27:39.572485Z [ERROR] No worktree for path: "/Users/pjv/.config/zed/settings.json"
2024-07-25T15:27:39.686042Z [WARN] no language server found matching 'ruff'
2024-07-25T15:27:39.686248Z [INFO] starting language servers for Python: pyright
2024-07-25T15:27:39.686425Z [INFO] starting language server "pyright", path: "/Users/pjv/development/test/", id: 1
2024-07-25T15:27:39.687001Z [WARN] no language server found matching 'ruff'
2024-07-25T15:27:39.687236Z [INFO] starting language servers for Python: pyright
2024-07-25T15:27:39.809644Z [INFO] fetching latest version of language server "pyright"
2024-07-25T15:27:39.809909Z [INFO] Node runtime install_if_needed
2024-07-25T15:27:40.004577Z [INFO] Node runtime install_if_needed
2024-07-25T15:27:40.218893Z [INFO] starting language server. binary path: "/Users/pjv/Library/Application Support/Zed/node/node-v22.5.1-darwin-x64/bin/node", working directory: "/", args: ["/Users/pjv/Library/Application Support/Zed/copilot/copilot-v0.5.0/dist/agent.js", "--stdio"]
2024-07-25T15:27:40.680796Z [INFO] Language server with id 0 sent unhandled notification LogMessage:
{
  "level": 0,
  "message": "[DEBUG] [agent] [2024-07-25T15:27:40.675Z] Agent service starting",
  "metadataStr": "[DEBUG] [agent] [2024-07-25T15:27:40.675Z]",
  "extra": [
    "Agent service starting"
  ]
}
2024-07-25T15:27:40.683052Z [INFO] Language server with id 0 sent unhandled notification client/registerCapability:
{
  "registrations": [
    {
      "id": "5b696af3-0dc4-4e5e-be2a-60ad6a3af487",
      "method": "workspace/didChangeWorkspaceFolders",
      "registerOptions": {}
    }
  ]
}
2024-07-25T15:27:40.736567Z [INFO] Language server with id 0 sent unhandled notification LogMessage:
{
  "level": 0,
  "message": "[DEBUG] [agent] [2024-07-25T15:27:40.690Z] Telemetry initialized",
  "metadataStr": "[DEBUG] [agent] [2024-07-25T15:27:40.690Z]",
  "extra": [
    "Telemetry initialized"
  ]
}
2024-07-25T15:27:41.129886Z [INFO] downloading language server "pyright"
2024-07-25T15:27:41.130518Z [INFO] Node runtime install_if_needed
2024-07-25T15:27:41.209793Z [INFO] starting language servers for Python: pyright, ruff
2024-07-25T15:27:41.210012Z [INFO] starting language server "ruff", path: "/Users/pjv/development/test/", id: 2
2024-07-25T15:27:41.315287Z [INFO] starting language server. binary path: "/Users/pjv/Library/Application Support/Zed/node/node-v22.5.1-darwin-x64/bin/node", working directory: "/Users/pjv/development/test/", args: ["/Users/pjv/Library/Application Support/Zed/languages/pyright/node_modules/pyright/langserver.index.js", "--stdio"]
2024-07-25T15:27:41.557579Z [INFO] Language server with id 1 sent unhandled notification window/logMessage:
{
  "type": 3,
  "message": "Pyright language server 1.1.373 starting"
}
2024-07-25T15:27:41.558007Z [INFO] Language server with id 1 sent unhandled notification window/logMessage:
{
  "type": 3,
  "message": "Server root directory: file:///Users/pjv/Library/Application%20Support/Zed/languages/pyright/node_modules/pyright/dist"
}
2024-07-25T15:27:41.56482Z [INFO] Language server with id 1 sent unhandled notification window/logMessage:
{
  "type": 3,
  "message": "Starting service instance \"\""
}
2024-07-25T15:27:41.85144Z [INFO] starting language server. binary path: "/usr/local/bin/ruff", working directory: "/Users/pjv/development/test/", args: ["server"]
2024-07-25T15:27:42.113978Z [INFO] language server 1: unregistered workspace/DidChangeWatchedFiles capability with id 6b7a66a9-4713-4a46-ad35-57b20bbbb36c

@osiewicz
Copy link
Contributor

@pjv can you try with:

"lsp": {
  "Ruff": {
    "binary": {
      "arguments": ["server", "--config=/Users/pjv/.config/ruff.toml"]
    }
  }
}

instead? My previous example is erroneous in that it should still contain server as the first argument.

@pjv
Copy link

pjv commented Jul 25, 2024

@osiewicz thank you. So that makes the LSP work again, but it is ignoring my config (it’s formatting with 4 spaces where my config tells ruff to use 2 spaces)

@osiewicz
Copy link
Contributor

osiewicz commented Jul 25, 2024

Hmm, are you able to grab a capture of the LSP request?

Open your command palette -> search for debug: open language server logs. In the upper left hand corner you'll see a clickable list of the language servers (click on the "Server logs" bit); in the list, tick RPC messages checkbox under ruff section.
Perform "erroneous" format operation; then go back to the log view and click on the "RPC messages" string itself (and not on the checkbox). There you'll have a full list of messages exchanged with ruff language server.

My hunch is that when we ask Ruff for formatting, we also pass a bunch of settings related to the formatting from Zed:
https://docs.rs/lsp-types/latest/lsp_types/struct.FormattingOptions.html

One of the options is the tab size. By default it's set to 4 spaces, which may take precedence over the config file you've passed in. If so, I'd say that's a bug on Ruff side.

@pjv
Copy link

pjv commented Jul 25, 2024

Interesting. Here’s the RPC messages:

// Send:
{"jsonrpc":"2.0","id":6,"method":"textDocument/formatting","params":{"textDocument":{"uri":"file:///Users/pjv/development/test/test.py"},"options":{"tabSize":2,"insertSpaces":true,"trimTrailingWhitespace":true,"insertFinalNewline":true,"trimFinalNewlines":true}}}
// Receive:
{"jsonrpc":"2.0","id":6,"result":null}

It does have tabSize: 2, but the test file is being indented at 4 spaces

SCR-20240725-kcix

@osiewicz
Copy link
Contributor

osiewicz commented Jul 25, 2024

It looks like Ruff ignores the settings we pass in, so it has to be something else.
Could you post your full settings file?

@pjv
Copy link

pjv commented Jul 25, 2024

// 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 the `open default settings` command
// from the command palette or from `Zed` application menu.
{
  "language_models": {
    "ollama": {
      "api_url": "http://pjv-mba:11434",
      "low_speed_timeout_in_seconds": 30
    }
  },
  "features": {
    "copilot": false
  },
  "assistant": {
    "default_model": {
      "provider": "ollama",
      "model": "llama3:8b-instruct-q8_0"
    },
    "version": "2",
    "provider": null
  },
  "base_keymap": "Atom",
  "theme": "Ayu Dark Italic",
  "ui_font_size": 16,
  "buffer_font_size": 15,
  "buffer_font_family": "Operator Mono Lig Light",
  "terminal": {
    "line_height": "standard",
    "copy_on_select": true
  },
  "tab_size": 2,
  "telemetry": {
    "diagnostics": false,
    "metrics": false
  },
  "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": [".env", "env", ".venv", "venv", ".direnv"],
      // Can also be 'csh', 'fish', and `nushell`
      "activate_script": "default"
    }
  },
  "languages": {
    // "Python": {
    //   "format_on_save": "on",
    //   "formatter": {
    //     "external": {
    //       "command": "bash",
    //       "arguments": [
    //         "-c",
    //         "ruff format --config=/Users/pjv/.config/ruff.toml --stdin-filename {buffer_path}"
    //       ]
    //     }
    //   }
    // },
    "Python": {
      "format_on_save": { "language_server": { "name": "ruff" } },
      "formatter": { "language_server": { "name": "ruff" } },
      "language_servers": ["pyright", "ruff", "..."]
    },
    "PHP": {
      "language_servers": [
        "intelephense",
        "!phpactor",
        "!tailwindcss-language-server",
        "..."
      ],
      "prettier": {
        "allowed": true,
        "plugins": ["@prettier/plugin-php"],
        "parser": "php",
        "phpVersion": "8.0",
        "braceStyle": "1tbs",
        "tabWidth": 2,
        "experimentalTernaries": true
      }
    }
  },
  "lsp": {
    "Ruff": {
      "binary": {
        "arguments": ["server", "--config=/Users/pjv/.config/ruff.toml"]
      }
    },
    "intelephense": {
      "settings": {
        "environment": {
          "includePaths": [
            // "/Users/pjv/development/projects/local_wp/wordpress",
            "/Users/pjv/development/projects/local_wp/woocommerce"
          ]
        },
        "stubs": [
          "apache",
          "bcmath",
          "bz2",
          "calendar",
          "com_dotnet",
          "Core",
          "ctype",
          "curl",
          "date",
          "dba",
          "dom",
          "enchant",
          "exif",
          "FFI",
          "fileinfo",
          "filter",
          "fpm",
          "ftp",
          "gd",
          "gettext",
          "gmp",
          "hash",
          "iconv",
          "imap",
          "intl",
          "json",
          "ldap",
          "libxml",
          "mbstring",
          "meta",
          "mysqli",
          "oci8",
          "odbc",
          "openssl",
          "pcntl",
          "pcre",
          "PDO",
          "pdo_ibm",
          "pdo_mysql",
          "pdo_pgsql",
          "pdo_sqlite",
          "pgsql",
          "Phar",
          "posix",
          "pspell",
          "random",
          "readline",
          "Reflection",
          "session",
          "shmop",
          "SimpleXML",
          "snmp",
          "soap",
          "sockets",
          "sodium",
          "SPL",
          "sqlite3",
          "standard",
          "superglobals",
          "sysvmsg",
          "sysvsem",
          "sysvshm",
          "tidy",
          "tokenizer",
          "xml",
          "xmlreader",
          "xmlrpc",
          "xmlwriter",
          "xsl",
          "Zend OPcache",
          "zip",
          "zlib",
          "wordpress"
        ]
      }
    }
  }
}

@osiewicz
Copy link
Contributor

What happens when you set tab_size for Python to 2?

@pjv
Copy link

pjv commented Jul 25, 2024

You mean like this?:

  "languages": {
    "Python": {
      "format_on_save": { "language_server": { "name": "ruff" } },
      "formatter": { "language_server": { "name": "ruff" } },
      "language_servers": ["pyright", "ruff", "..."],
      "tab_size": 2

…no difference.

@pjv
Copy link

pjv commented Jul 26, 2024

@osiewicz If I stick my global ruff.toml file into the test project, then the ruff LSP respects it and formats my test file correctly to my specs (2 space indent). Is there really no way to get the ruff LSP to pay attention to a global config file?

The workaround for me would be to uninstall the ruff extension and instead keep using the callout to my globally installed ruff as an external formatter for python files, but this seems suboptimal.

EDIT: looking around here: https://docs.astral.sh/ruff/editors/settings/ …makes me think that maybe there could be a way to pass the configuration file path along in the format_on_save / formatter options like you showed in another issue for setting up code_actions to organize imports. Not sure what key to supply in there for the configuration file though.

@pjv
Copy link

pjv commented Jul 30, 2024

The solution to getting the ruff extension to respect initialization options looks like this:

"lsp": {
    "ruff": {
      "initialization_options": {
        "settings": {
          "configuration": "/Users/pjv/.config/ruff.toml"
        }
      }
    },

… which I had to arrive at by a long process of trial and error of sticking various combinations and orders of keys into the lsp object. So my question: is there a way that I could have looked at some documentation or even some code somewhere that would have made this not a trial and error but something that would have been obvious through understanding? How and where is this lsp object related to the language server extensions and is there any rhyme or reason to how that code is structured or is it 100% arbitrary in the case of each extension?

@osiewicz
Copy link
Contributor

It's 100% arbitrary for each extension, because we just pass the contents of initialization_options on to the language server. I'm sorry you've had to go through this.

@pjv
Copy link

pjv commented Jul 30, 2024

@osiewicz No worries, thanks for confirming. So the pressure point is on extension authors to provide some minimum documentation. Good to know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants