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

Support auto enablement of Ruff server #518

Merged
merged 1 commit into from
Jul 8, 2024
Merged

Conversation

dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Jul 5, 2024

Summary

Superseds #505

This PR updates the nativeServer setting with new values on | off | auto based on the suggestion at #505 (comment).

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

Logic

"on" / true

  • Use the native server
  • Show warning for “deprecated” settings

"off" / false

  • Use ruff-lsp
  • Show warning for “new” settings

"auto"

  • If ruff version is < 0.5.2
    • If any of the “new” settings are set, log at info level for those settings
    • Use ruff-lsp.
  • If ruff version is ≥ 0.5.2
    • If any of the “deprecated” settings are set, log at info level for those settings
      • Use ruff-lsp
    • Otherwise, use ruff server
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

Screen.Recording.2024-07-05.at.10.46.33.mov

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

@dhruvmanila dhruvmanila force-pushed the dhruv/auto-server branch 2 times, most recently from 6cbb64b to a9de921 Compare July 5, 2024 04:43
@dhruvmanila dhruvmanila marked this pull request as ready for review July 5, 2024 05:50
@MichaReiser
Copy link
Member

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.

src/common/server.ts Outdated Show resolved Hide resolved
src/common/server.ts Outdated Show resolved Hide resolved
Comment on lines 335 to 349
let nativeServerSettings = getUserSetNativeServerSettings(serverId, workspace);
if (nativeServerSettings.length > 0) {
traceInfo(`Native server settings found: ${JSON.stringify(nativeServerSettings)}`);
}
useNativeServer = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should at least show a warning in this csae to let users know that one of their settings was ignored.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we provide a warning for the other case as well where the Ruff version supports the stable server but the user has set legacy server settings?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a warning with a suggestion for this case:

2024-07-08 15:59:18.068 [info] Using the Ruff binary: /Users/dhruv/.local/bin/ruff
2024-07-08 15:59:18.075 [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-08 15:59:21.067 [warning] The following settings are not supported with the legacy server (ruff-lsp): ["ruff.configuration"]
2024-07-08 15:59:21.067 [warning] Please remove these settings or set 'nativeServer' to 'on' to use the native server
2024-07-08 15:59:21.067 [info] Resolved 'ruff.nativeServer: auto' to use the legacy (ruff-lsp) server

src/common/settings.ts Show resolved Hide resolved
src/common/server.ts Outdated Show resolved Hide resolved
@dhruvmanila dhruvmanila force-pushed the dhruv/python-version-check-2 branch from af924b0 to e048d71 Compare July 5, 2024 11:36
Base automatically changed from dhruv/python-version-check-2 to main July 5, 2024 11:39
@dhruvmanila dhruvmanila force-pushed the dhruv/auto-server branch 2 times, most recently from 1680e05 to 464ff9b Compare July 5, 2024 11:43
@dhruvmanila
Copy link
Member Author

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.

@dhruvmanila dhruvmanila merged commit 4a54d4d into main Jul 8, 2024
6 checks passed
@dhruvmanila dhruvmanila deleted the dhruv/auto-server branch July 8, 2024 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants