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

Add deprecation warning for ruff-lsp specific settings #677

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,12 @@ Finally, to use a common Ruff configuration across all projects, consider creati

#### Python-based language server (`ruff-lsp`)

> [!WARNING]
>
> [`ruff-lsp`](https://github.com/astral-sh/ruff-lsp) is deprecated and will be
> removed in a future release. Please switch to the Rust-based language server
> (`ruff server`) instead.

If you're using the default Python-based language server, you can use the `ruff.lint.args` and
`ruff.format.args` settings in `settings.json` to pass command-line arguments to Ruff.

Expand Down
16 changes: 14 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@
"Automatically select between the native language server and [`ruff-lsp`](https://github.com/astral-sh/ruff-lsp) based on the following conditions:\n1. If the Ruff version is >= `0.5.3`, use the native language server unless any deprecated settings are detected. In that case, show a warning and use [`ruff-lsp`](https://github.com/astral-sh/ruff-lsp) instead.\n2. If the Ruff version is < `0.5.3`, use [`ruff-lsp`](https://github.com/astral-sh/ruff-lsp). A warning will be displayed if settings specific to the native server are detected.",
"Same as `on`.",
"Same as `off`."
]
],
"markdownDeprecationMessage": "**Deprecated**: This setting has been deprecated with the deprecation of [`ruff-lsp`](https://github.com/astral-sh/ruff-lsp). It was mainly used to provide a way to switch between the native language server and [`ruff-lsp`](https://github.com/astral-sh/ruff-lsp) during the transition period. Refer to the [migration guide](https://docs.astral.sh/ruff/editors/migration) for more information.",
"deprecationMessage": "Deprecated: This setting has been deprecated with the deprecation of ruff-lsp. It was mainly used to provide a way to switch between the native language server and ruff-lsp during the transition period."
MichaReiser marked this conversation as resolved.
Show resolved Hide resolved
},
"ruff.configuration": {
"default": null,
Expand All @@ -120,6 +122,8 @@
"ruff.lint.args": {
"default": [],
"markdownDescription": "Additional command-line arguments to pass to `ruff check`, e.g., `\"args\": [\"--config=/path/to/pyproject.toml\"]`. Supports a subset of Ruff's command-line arguments, ignoring those that are required to operate the LSP, like `--force-exclude` and `--verbose`.\n\n**This setting is not supported by the native server.**",
"markdownDeprecationMessage": "**Deprecated**: This setting is only used by [`ruff-lsp`](https://github.com/astral-sh/ruff-lsp) which is deprecated in favor of the native language server. Refer to the [migration guide](https://docs.astral.sh/ruff/editors/migration) for more information.",
"deprecationMessage": "Deprecated: This setting is only used by ruff-lsp which is deprecated in favor of the native language server.",
"items": {
"type": "string"
},
Expand Down Expand Up @@ -194,6 +198,8 @@
"Run Ruff on every keystroke.",
"Run Ruff on save."
],
"markdownDeprecationMessage": "**Deprecated**: This setting is only used by [`ruff-lsp`](https://github.com/astral-sh/ruff-lsp) which is deprecated in favor of the native language server. Refer to the [migration guide](https://docs.astral.sh/ruff/editors/migration) for more information.",
"deprecationMessage": "Deprecated: This setting is only used by ruff-lsp which is deprecated in favor of the native language server.",
"scope": "window",
"type": "string"
},
Expand All @@ -206,6 +212,8 @@
"ruff.format.args": {
"default": [],
"markdownDescription": "Additional command-line arguments to pass to `ruff format`, e.g., `\"args\": [\"--config=/path/to/pyproject.toml\"]`. Supports a subset of Ruff's command-line arguments, ignoring those that are required to operate the LSP, like `--force-exclude` and `--verbose`.\n\n**This setting is not supported by the native server.**",
"markdownDeprecationMessage": "**Deprecated**: This setting is only used by [`ruff-lsp`](https://github.com/astral-sh/ruff-lsp) which is deprecated in favor of the native language server. Refer to the [migration guide](https://docs.astral.sh/ruff/editors/migration) for more information.",
"deprecationMessage": "Deprecated: This setting is only used by ruff-lsp which is deprecated in favor of the native language server.",
"items": {
"type": "string"
},
Expand Down Expand Up @@ -243,7 +251,7 @@
},
"ruff.interpreter": {
"default": [],
"markdownDescription": "Path to a Python interpreter to use to run the LSP server.",
"markdownDescription": "Path to a Python interpreter to use to find the `ruff` executable.",
"scope": "resource",
"items": {
"type": "string"
Expand Down Expand Up @@ -309,6 +317,8 @@
"ruff.ignoreStandardLibrary": {
"default": true,
"markdownDescription": "Whether to ignore files that are inferred to be part of the Python standard library.",
"markdownDeprecationMessage": "**Deprecated**: This setting is only used by [`ruff-lsp`](https://github.com/astral-sh/ruff-lsp) which is deprecated in favor of the native language server. Refer to the [migration guide](https://docs.astral.sh/ruff/editors/migration) for more information.",
"deprecationMessage": "Deprecated: This setting is only used by ruff-lsp which is deprecated in favor of the native language server.",
"scope": "window",
"type": "boolean"
},
Expand Down Expand Up @@ -344,6 +354,8 @@
"ruff.showNotifications": {
"default": "off",
"markdownDescription": "Controls when notifications are shown by this extension.",
"markdownDeprecationMessage": "**Deprecated**: This setting is only used by [`ruff-lsp`](https://github.com/astral-sh/ruff-lsp) which is deprecated in favor of the native language server. Refer to the [migration guide](https://docs.astral.sh/ruff/editors/migration) for more information.",
"deprecationMessage": "Deprecated: This setting is only used by ruff-lsp which is deprecated in favor of the native language server.",
"enum": [
"off",
"onError",
Expand Down
36 changes: 33 additions & 3 deletions src/common/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,19 @@ function showWarningMessageWithLogs(message: string) {
});
}

function legacyServerDeprecationWarning(ruffVersion: VersionInfo) {
const message =
"`ruff-lsp` is deprecated:\r\n" +
`[Option 1] Upgrade the Ruff version to >= 0.3.5 (found ${versionToString(ruffVersion)})\r\n` +
"[Option 2] [Pin the extension version](https://stackoverflow.com/questions/42626065/vs-code-how-to-rollback-extension-install-specific-extension-version) to 2025.4.0 to keep using ruff-lsp\r\n" +
"Refer to the [setup guide](https://docs.astral.sh/ruff/editors/setup/) on " +
"how to set up the native language server and the " +
"[migration guide](https://docs.astral.sh/ruff/editors/migration/) on how to migrate the settings. " +
"Feel free to comment on the [GitHub discussion](https://github.com/astral-sh/ruff/discussions/15991) to ask questions or share feedback.";
showWarningMessageWithLogs(message);
logger.warn(message);
}

function legacyServerSettingsWarning(settings: string[]) {
showWarningMessageWithLogs(
"Unsupported settings used with the native server. Refer to the logs for more details.",
Expand Down Expand Up @@ -306,6 +319,8 @@ async function resolveNativeServerSetting(
): Promise<{ useNativeServer: boolean; executable: RuffExecutable | undefined }> {
let useNativeServer: boolean;
let executable: RuffExecutable | undefined;
let ruffBinaryPath: string;
let ruffVersion: VersionInfo;

switch (settings.nativeServer) {
case "on":
Expand All @@ -325,11 +340,19 @@ async function resolveNativeServerSetting(
return { useNativeServer: true, executable };
}

ruffBinaryPath = await findRuffBinaryPath(settings);
ruffVersion = await getRuffVersion(ruffBinaryPath);

// For versions >= 0.3.5, `ruff-lsp` will show the deprecation warning.
if (!supportsNativeServer(ruffVersion)) {
legacyServerDeprecationWarning(ruffVersion);
}

let nativeServerSettings = getUserSetNativeServerSettings(serverId, workspace);
if (nativeServerSettings.length > 0) {
nativeServerSettingsWarning(nativeServerSettings);
}
return { useNativeServer: false, executable };
return { useNativeServer: false, executable: { path: ruffBinaryPath, version: ruffVersion } };
case "auto":
if (!vscode.workspace.isTrusted) {
logger.info(
Expand All @@ -338,8 +361,8 @@ async function resolveNativeServerSetting(
return { useNativeServer: true, executable };
}

const ruffBinaryPath = await findRuffBinaryPath(settings);
const ruffVersion = await getRuffVersion(ruffBinaryPath);
ruffBinaryPath = await findRuffBinaryPath(settings);
ruffVersion = await getRuffVersion(ruffBinaryPath);

if (supportsStableNativeServer(ruffVersion)) {
const legacyServerSettings = getUserSetLegacyServerSettings(serverId, workspace);
Expand All @@ -365,6 +388,13 @@ async function resolveNativeServerSetting(
useNativeServer = false;
}

if (!useNativeServer) {
// For versions >= 0.3.5, `ruff-lsp` will show the deprecation warning.
if (!supportsNativeServer(ruffVersion)) {
legacyServerDeprecationWarning(ruffVersion);
}
}

logger.info(
`Resolved '${serverId}.nativeServer: auto' to use the ${
useNativeServer ? "native" : "legacy (ruff-lsp)"
Expand Down