Skip to content

Commit

Permalink
Add deprecation warning (#520)
Browse files Browse the repository at this point in the history
## Summary

This PR adds a deprecation warning during the initialization request if
the `ruff` executable found is `>= 0.3.5`.

Refer to
#520 (comment)
for the discussion.

### Preview

**VS Code**

It'll provide a warning notification along with logging the message:

<img width="2560" alt="Screenshot 2025-02-03 at 11 21 29 AM"
src="https://github.com/user-attachments/assets/3745399a-ea7c-4f74-9d6f-689ecbd435b5"
/>

**Neovim**

It seems like Neovim has already deprecated `ruff_lsp` if the user is
using [`nvim-lspconfig`](https://github.com/neovim/nvim-lspconfig)
(which should be most of the users):

<img width="546" alt="Screenshot 2025-02-03 at 11 31 50 AM"
src="https://github.com/user-attachments/assets/59f70e2b-a95e-4022-be61-d87a276a1a93"
/>

But, regardless, the users should receive the warning if they've
configured it to do so:

<img width="1280" alt="Screenshot 2025-02-03 at 11 30 54 AM"
src="https://github.com/user-attachments/assets/c824ee80-f836-4dba-8515-694f8b4b6048"
/>
  • Loading branch information
dhruvmanila authored Feb 6, 2025
1 parent 78a4ab5 commit c973b94
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
> [!WARNING]
>
> **`ruff-lsp` is deprecated. Please switch to the native language server
> (`ruff server`). 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.**
# ruff-lsp

[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
Expand Down
27 changes: 27 additions & 0 deletions ruff_lsp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ class VersionModified(NamedTuple):
VERSION_REQUIREMENT_OUTPUT_FORMAT = SpecifierSet(">=0.0.291")
# Version requirement after which Ruff avoids writing empty output for excluded files.
VERSION_REQUIREMENT_EMPTY_OUTPUT = SpecifierSet(">=0.1.6")
# Version requirement to display the deprecation warning for `ruff-lsp` and start
# recommending `ruff server` instead.
VERSION_REQUIREMENT_NATIVE_SERVER = SpecifierSet(">=0.3.5")

# Arguments provided to every Ruff invocation.
CHECK_ARGS = [
Expand Down Expand Up @@ -1613,6 +1616,24 @@ def initialize(params: InitializeParams) -> None:

_update_workspace_settings(settings)

# Use the Ruff executable from the first workspace to determine when to show the
# deprecation warning.
executable = _find_ruff_binary(
next(iter(WORKSPACE_SETTINGS.values())), version_requirement=None
)

if VERSION_REQUIREMENT_NATIVE_SERVER.contains(executable.version, prereleases=True):
show_warning(
"`ruff-lsp` is deprecated. Please switch to the native language server "
"(`ruff server`). 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."
)


def _supports_code_action_resolve(capabilities: ClientCapabilities) -> bool:
"""Returns True if the client supports codeAction/resolve request for edits."""
Expand Down Expand Up @@ -1995,6 +2016,12 @@ def show_error(message: str) -> None:
LSP_SERVER.show_message(message, MessageType.Error)


def show_warning(message: str) -> None:
"""Show a pop-up with a warning."""
LSP_SERVER.show_message_log(message, MessageType.Warning)
LSP_SERVER.show_message(message, MessageType.Warning)


def log_warning(message: str) -> None:
LSP_SERVER.show_message_log(message, MessageType.Warning)
if os.getenv("LS_SHOW_NOTIFICATION", "off") in ["onWarning", "always"]:
Expand Down

0 comments on commit c973b94

Please sign in to comment.