From 1379e8b089cc6d580a400a02a4d76b9e5653d2f8 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Fri, 31 Jan 2025 18:29:28 +0530 Subject: [PATCH 1/2] Add deprecation warning for `ruff-lsp` specific settings --- README.md | 6 ++++++ package.json | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e6b88ed..97ab83b 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/package.json b/package.json index a1e0188..e874bff 100644 --- a/package.json +++ b/package.json @@ -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." }, "ruff.configuration": { "default": null, @@ -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" }, @@ -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" }, @@ -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" }, @@ -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" @@ -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" }, @@ -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", From 8b73e66e36790f004a64a8acfac252a3c101e259 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Thu, 6 Feb 2025 17:29:58 +0530 Subject: [PATCH 2/2] Deprecation warning for Ruff < 0.3.5 --- src/common/server.ts | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/common/server.ts b/src/common/server.ts index 69eb0e9..865c591 100644 --- a/src/common/server.ts +++ b/src/common/server.ts @@ -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.", @@ -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": @@ -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( @@ -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); @@ -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)"