From d94ddfbd1eca43da99831559ba9febd879a0f7ae Mon Sep 17 00:00:00 2001 From: Jack Cherng Date: Mon, 22 Jul 2024 22:46:19 +0800 Subject: [PATCH] refactor: use ruff as the server (#58) --- LSP-ruff.sublime-settings | 36 ++++++++------ README.md | 2 +- plugin.py | 2 +- pyproject.toml | 6 ++- requirements.txt | 2 +- sublime-package.json | 99 ++++++++++++++++++++++++++------------- 6 files changed, 95 insertions(+), 52 deletions(-) diff --git a/LSP-ruff.sublime-settings b/LSP-ruff.sublime-settings index ef06bfd..b7f9741 100644 --- a/LSP-ruff.sublime-settings +++ b/LSP-ruff.sublime-settings @@ -3,22 +3,31 @@ "settings": { // same as globalSettings }, + // See https://docs.astral.sh/ruff/editors/settings/ "globalSettings": { - // Custom arguments passed to ruff. - // See ruff documentation at https://github.com/charliermarsh/ruff/blob/main/README.md#configuration - "lint.args": [], - // Run Ruff on every keystroke (onType) or on save (onSave). - "lint.run": "onType", + // Path to a ruff.toml or pyproject.toml file to use for configuration. + // By default, Ruff will discover configuration for each project from the filesystem, mirroring the behavior of the Ruff CLI. + "configuration": null, + // The strategy to use when resolving settings across editor and the filesystem. By default, editor configuration is prioritized over ruff.toml and pyproject.toml files. + "configurationPreference": "editorFirst", + // A list of file patterns to exclude from linting and formatting. See the documentation for more details. + "exclude": null, + // Whether to enable Ruff's preview mode when formatting. + "format.preview": null, + // The line length to use for the linter and formatter. + "lineLength": null, // Whether to enable linting. Set to false to use Ruff exclusively as a formatter. "lint.enable": true, - // Additional command-line arguments to pass to `ruff format`. - "format.args": [], + // Rules to enable by default. See the documentation. + "lint.select": null, + // Rules to enable in addition to those in lint.select. + "lint.extendSelect": null, + // Rules to disable by default. See the documentation. + "lint.ignore": null, + // Whether to enable Ruff's preview mode when linting. + "lint.preview": null, // Sets the tracing level for the extension. "logLevel": "error", - // Setting to provide custom ruff executables, to try in order. - "path": [], - // Path to a Python interpreter to use to run the linter server. - "interpreter": [], // Setting to control when a notification is shown. "showNotification": "off", // Whether to register Ruff as capable of handling source.organizeImports actions. @@ -29,12 +38,11 @@ "codeAction.fixViolation.enable": true, // Whether to display Quick Fix actions to disable rules via noqa suppression comments. "codeAction.disableRuleComment.enable": true, - // Whether to ignore files that are inferred to be part of the Python standard library. - "ignoreStandardLibrary": true, }, }, "command": [ - "$server_path" + "$server_path", + "server" ], "schemes": [ "file", // regular files diff --git a/README.md b/README.md index d416b05..1094bfb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # LSP-ruff -This is a helper package that automatically installs and updates [ruff-lsp](https://github.com/charliermarsh/ruff-lsp) for you. Ruff is an extremely fast Python linter and code transformation tool, written in Rust. +This is a helper package that automatically installs and updates [ruff](https://github.com/astral-sh/ruff) for you. Ruff is an extremely fast Python linter and code transformation tool, written in Rust. ## Requirements diff --git a/plugin.py b/plugin.py index 61c7028..af9d217 100644 --- a/plugin.py +++ b/plugin.py @@ -4,7 +4,7 @@ class RuffLsp(PipClientHandler): package_name = __package__ requirements_txt_path = "requirements.txt" - server_filename = "ruff-lsp" + server_filename = "ruff" def plugin_loaded() -> None: diff --git a/pyproject.toml b/pyproject.toml index 57ee3cc..650f007 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,10 @@ [tool.ruff] -ignore = [] line-length = 88 + +[tool.ruff.lint] +ignore = [] select = [ "E", "F", "W", -] \ No newline at end of file +] diff --git a/requirements.txt b/requirements.txt index 806f070..e1d1ab1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -ruff-lsp==0.0.54 +ruff==0.5.4 diff --git a/sublime-package.json b/sublime-package.json index bc8bcb4..92690b5 100644 --- a/sublime-package.json +++ b/sublime-package.json @@ -11,29 +11,77 @@ "LspRuffSettings": { "additionalProperties": false, "properties": { - "lint.args": { - "type": "array", - "default": [], - "markdownDescription": "Custom arguments passed to ruff. See [ruff documentation](https://github.com/charliermarsh/ruff/blob/main/README.md#configuration)." + "configuration": { + "type": ["string", "null"], + "default": null, + "markdownDescription": "Path to a `ruff.toml` or `pyproject.toml` file to use for configuration. By default, Ruff will discover configuration for each project from the filesystem, mirroring the behavior of the Ruff CLI." + }, + "configurationPreference": { + "type": "string", + "default": "editorFirst", + "enum": [ + "editorFirst", + "filesystemFirst", + "editorOnly" + ], + "enumDescriptions": [ + "Editor settings take priority over configuration files present in the workspace.", + "Configuration files present in the workspace takes priority over editor settings.", + "Ignore configuration files entirely i.e., only use editor settings." + ], + "markdownDescription": "The strategy to use when resolving settings across editor and the filesystem. By default, editor configuration is prioritized over `ruff.toml` and `pyproject.toml` files." + }, + "exclude": { + "type": ["array", "null"], + "default": null, + "items": { + "type": "string" + }, + "description": "A list of file patterns to exclude from linting and formatting. See the documentation for more details." + }, + "format.preview": { + "type": ["null", "boolean"], + "default": null, + "description": "Whether to enable Ruff's preview mode when formatting." }, "lint.enable": { "type": "boolean", "default": true, "markdownDescription": "Whether to enable linting. Set to false to use Ruff exclusively as a formatter." }, - "lint.run": { - "type": "string", - "default": "onType", - "enum": [ - "onType", - "onSave" - ], - "description": "Run Ruff on every keystroke (onType) or on save (onSave)." + "lineLength": { + "type": ["null", "integer"], + "default": null, + "description": "The line length to use for the linter and formatter." + }, + "lint.select": { + "type": ["array", "null"], + "default": null, + "items": { + "type": "string" + }, + "description": "Rules to enable by default. See the documentation." + }, + "lint.extendSelect": { + "type": ["array", "null"], + "default": null, + "items": { + "type": "string" + }, + "markdownDescription": "Rules to enable in addition to those in `lint.select`." }, - "format.args": { - "type": "array", - "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`." + "lint.ignore": { + "type": ["array", "null"], + "default": null, + "items": { + "type": "string" + }, + "description": "Rules to disable by default. See the documentation." + }, + "lint.preview": { + "type": ["null", "boolean"], + "default": null, + "description": "Whether to enable Ruff's preview mode when linting." }, "logLevel": { "type": "string", @@ -47,16 +95,6 @@ ], "description": "Sets the tracing level for the extension." }, - "path": { - "type": "array", - "default": [], - "description": "Setting to provide custom ruff executables, to try in order." - }, - "interpreter": { - "type": "array", - "default": [], - "description": "Path to a Python interpreter to use to run the linter server." - }, "showNotification": { "type": "string", "default": "off", @@ -65,12 +103,12 @@ "organizeImports": { "type": "boolean", "default": true, - "description": "Whether to register Ruff as capable of handling source.organizeImports actions." + "markdownDescription": "Whether to register Ruff as capable of handling `source.organizeImports` actions." }, "fixAll": { "type": "boolean", "default": true, - "description": "Whether to register Ruff as capable of handling source.fixAll actions." + "markdownDescription": "Whether to register Ruff as capable of handling `source.fixAll` actions." }, "codeAction.fixViolation.enable": { "type": "boolean", @@ -81,11 +119,6 @@ "type": "boolean", "default": true, "description": "Whether to display Quick Fix actions to disable rules via noqa suppression comments." - }, - "ignoreStandardLibrary": { - "type": "boolean", - "default": true, - "description": "Whether to ignore files that are inferred to be part of the Python standard library." } }, },