From bdd50df8f8fe301d8264151032e20405efb046e9 Mon Sep 17 00:00:00 2001 From: betaboon Date: Sun, 9 Apr 2023 14:21:03 +0200 Subject: [PATCH] feat: support import-sorting during formatting --- README.md | 3 +++ pylsp_ruff/plugin.py | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a900fb2..4705a2e 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,9 @@ There also exists an [AUR package](https://aur.archlinux.org/packages/python-lsp This plugin will disable `flake8`, `pycodestyle`, `pyflakes` and `mccabe` by default. When enabled, all linting diagnostics will be provided by `ruff`. +This plugin will disable `pyls_isort` by default. +When enabled, sorting of imports when formatting will be provided by `ruff`. + # Configuration Configuration options can be passed to the python-language-server. If a `pyproject.toml` diff --git a/pylsp_ruff/plugin.py b/pylsp_ruff/plugin.py index 7a49466..88d1857 100644 --- a/pylsp_ruff/plugin.py +++ b/pylsp_ruff/plugin.py @@ -59,6 +59,7 @@ def pylsp_settings(): "flake8": {"enabled": False}, "mccabe": {"enabled": False}, "pycodestyle": {"enabled": False}, + "pyls_isort": {"enabled": False}, } } return converter.unstructure(settings) @@ -345,11 +346,10 @@ def run_ruff_fix(workspace: Workspace, document: Document) -> str: def run_ruff_format(workspace: Workspace, document: Document) -> str: settings = load_settings(workspace, document) - extra_arguments = [] + fixable_codes = ["I"] if settings.format: - extra_arguments.append(f"--fixable={','.join(settings.format)}") - else: - extra_arguments.append("--unfixable=ALL") + fixable_codes.extend(settings.format) + extra_arguments = [f"--fixable={','.join(fixable_codes)}"] result = run_ruff(workspace, document, fix=True, extra_arguments=extra_arguments) return result