astral-sh / ruff-vscode

A Visual Studio Code extension with support for the Ruff linter.
Other
1.06k stars 53 forks source link

Support `auto` enablement of Ruff server #518

Closed dhruvmanila closed 2 months ago

dhruvmanila commented 3 months ago

Summary

Superseds #505

This PR updates the nativeServer setting with new values on | off | auto based on the suggestion at https://github.com/astral-sh/ruff-vscode/pull/505#discussion_r1659606353.

For backwards compatibility, on and off are equivalent to true and false respectively.

Logic

"on" / true

"off" / false

"auto"

Settings reference: #### Global Here, the scope represents the following: * "both": setting is supported by both native server and `ruff-lsp` * "new": setting is only supported by the native server * "deprecated": setting is deprecated and isn't supported by the native server * "server deprecated": setting is deprecated only in the native server but it's still accepted and use by the VS Code extension Settings | Scope -- | -- `enable` | both `fixAll` | both `organizeImports` | both `importStrategy` | both `showNotifications` | both `showSyntaxErrors` | both `configuration` | new `configurationPreference` | new `exclude` | new `lineLength` | new `logLevel` | new `logFile` | new `path` | server deprecated `interpreter` | server deprecated `ignoreStandardLibrary` | deprecated #### `codeAction` Settings | Scope -- | -- `disableRuleComment.enable` | both `fixViolation.enable` | both #### `lint` Settings | Scope -- | -- `enable` | both `preview` | new `select` | new `extendSelect` | new `ignore` | new `extendIgnore` | new `args` | deprecated `run` | deprecated #### `format` Settings |  Scope -- | -- `preview` | new `args` | deprecated

Settings Preview

Preview of how the description of nativeServer setting renders:

Auto-completion

Screenshot 2024-07-05 at 10 33 07

Hover on "auto"

Screenshot 2024-07-05 at 10 33 45

Hover on "on"

Screenshot 2024-07-05 at 10 34 24

Hover on "off"

Screenshot 2024-07-05 at 10 34 37

Dropdown

https://github.com/astral-sh/ruff-vscode/assets/67177269/c09bb85c-e82b-4460-8ee5-960d29854389

Test Plan

Native server on with a unsupported settings

{
  "ruff.nativeServer": "on",
  // Deprecated
  "ruff.lint.args": ["--ignore=E501"],
}

Logs:

2024-07-05 10:51:30.360 [warning] Following settings are not supported with the native server: ["ruff.lint.args"]
2024-07-05 10:51:30.398 [info] Using the Ruff binary: /Users/dhruv/.local/bin/ruff
2024-07-05 10:51:30.407 [info] Found Ruff 0.5.0 at /Users/dhruv/.local/bin/ruff
2024-07-05 10:51:30.407 [info] Server run command: /Users/dhruv/.local/bin/ruff server --preview

Notification Preview:

Screenshot 2024-07-05 at 10 51 12

Native server off with unsupported settings

{
  "ruff.nativeServer": "off",
  // Native server only
  "ruff.configuration": "~/playground/ruff/pyproject.toml",
  "ruff.lineLength": 70
}

Logs:

2024-07-05 10:52:56.653 [warning] Following settings are not supported with the legacy server (ruff-lsp): ["ruff.configuration","ruff.lineLength"]
2024-07-05 10:52:56.656 [info] Server run command: /Users/dhruv/work/astral/ruff-vscode/.venv/bin/python /Users/dhruv/work/astral/ruff-vscode/bundled/tool/server.py

Notification Preview:

Screenshot 2024-07-05 at 10 52 49

Native server "auto" with non-stable version:

{
  "ruff.nativeServer": "auto"
}

Logs:

2024-07-05 10:57:53.003 [info] Using the Ruff binary: /Users/dhruv/.local/bin/ruff
2024-07-05 10:57:53.010 [info] Stable version of the native server requires Ruff 0.5.0, but found 0.4.10 at /Users/dhruv/.local/bin/ruff instead
2024-07-05 10:57:53.010 [info] Resolved 'ruff.nativeServer: auto' to use legacy (ruff-lsp) server
2024-07-05 10:57:53.011 [info] Server run command: /Users/dhruv/work/astral/ruff-vscode/.venv/bin/python /Users/dhruv/work/astral/ruff-vscode/bundled/tool/server.py

Native server "auto" with non-stable version and native server settings:

{
  "ruff.nativeServer": "auto",
  // Native server only
  "ruff.configuration": "~/playground/ruff/pyproject.toml",
  "ruff.lineLength": 70
}

Logs:

2024-07-05 11:17:53.976 [info] Using the Ruff binary: /Users/dhruv/.local/bin/ruff
2024-07-05 11:17:53.987 [info] Stable version of the native server requires Ruff 0.5.0, but found 0.4.10 at /Users/dhruv/.local/bin/ruff instead
2024-07-05 11:17:53.987 [info] Native server settings found: ["ruff.configuration","ruff.lineLength"]
2024-07-05 11:17:53.987 [info] Resolved 'ruff.nativeServer: auto' to use legacy (ruff-lsp) server
2024-07-05 11:17:53.991 [info] Server run command: /Users/dhruv/work/astral/ruff-vscode/.venv/bin/python /Users/dhruv/work/astral/ruff-vscode/bundled/tool/server.py

Native server "auto" with stable version and using native server settings:

{
  "ruff.nativeServer": "auto",
  // Native server only
  "ruff.configuration": "~/playground/ruff/pyproject.toml",
  "ruff.lineLength": 70
}

Logs:

2024-07-05 11:02:15.113 [info] Using the Ruff binary: /Users/dhruv/.local/bin/ruff
2024-07-05 11:02:15.316 [info] Resolved 'ruff.nativeServer: auto' to use native server
2024-07-05 11:02:15.316 [info] Found Ruff 0.5.0 at /Users/dhruv/.local/bin/ruff
2024-07-05 11:02:15.316 [info] Server run command: /Users/dhruv/.local/bin/ruff server --preview

Native server "auto" with stable version and using legacy server settings:

{
  "ruff.nativeServer": "auto",
  // Deprecated
  "ruff.ignoreStandardLibrary": true,
  "ruff.lint.args": ["--ignore=E501"]
}

Logs:

2024-07-05 11:06:22.133 [info] Using the Ruff binary: /Users/dhruv/.local/bin/ruff
2024-07-05 11:06:22.136 [info] Legacy server settings found: ["ruff.ignoreStandardLibrary","ruff.lint.args"]
2024-07-05 11:06:22.136 [info] Resolved 'ruff.nativeServer: auto' to use legacy (ruff-lsp) server
2024-07-05 11:06:22.140 [info] Server run command: /Users/dhruv/work/astral/ruff-vscode/.venv/bin/python /Users/dhruv/work/astral/ruff-vscode/bundled/tool/server.py

Native server "auto" with stable version and using both native and legacy server settings:

{
  "ruff.nativeServer": "auto",
  // Native server only
  "ruff.configuration": "~/playground/ruff/pyproject.toml",
  "ruff.lineLength": 70,
  // Deprecated
  "ruff.ignoreStandardLibrary": true,
  "ruff.lint.args": ["--ignore=E501"]
}

Logs:

2024-07-05 11:19:12.425 [info] Using the Ruff binary: /Users/dhruv/.local/bin/ruff
2024-07-05 11:19:12.619 [info] Legacy server settings found: ["ruff.ignoreStandardLibrary","ruff.lint.args"]
2024-07-05 11:19:12.619 [info] Resolved 'ruff.nativeServer: auto' to use legacy (ruff-lsp) server
2024-07-05 11:19:12.620 [info] Server run command: /Users/dhruv/work/astral/ruff-vscode/.venv/bin/python /Users/dhruv/work/astral/ruff-vscode/bundled/tool/server.py
MichaReiser commented 3 months ago

I'm a bit confused about what the values of the new settings are. The PR summary describes that the values are yes and no but the screenshots show off and on.

dhruvmanila commented 2 months ago

I'm a bit confused about what the values of the new settings are. The PR summary describes that the values are yes and no but the screenshots show off and on.

Sorry, this was copy-pasted from my notes where I initially started off with yes/no but a lot of existing VS Code settings use on/off so I'm using that. The final values are on/off/auto/true/false.