diff --git a/pylsp_ruff/plugin.py b/pylsp_ruff/plugin.py index 4a05017..699acb2 100644 --- a/pylsp_ruff/plugin.py +++ b/pylsp_ruff/plugin.py @@ -655,6 +655,9 @@ def build_check_arguments( continue args.append(f"--ignore={','.join(errors)}") + if settings.isolated: + args.append("--isolated") + if extra_arguments: args.extend(extra_arguments) @@ -709,6 +712,9 @@ def build_format_arguments( if settings.target_version: args.append(f"--target-version={settings.target_version}") + if settings.isolated: + args.append("--isolated") + if extra_arguments: args.extend(extra_arguments) diff --git a/pylsp_ruff/settings.py b/pylsp_ruff/settings.py index c274dac..bc14fba 100644 --- a/pylsp_ruff/settings.py +++ b/pylsp_ruff/settings.py @@ -33,6 +33,9 @@ class PluginSettings: target_version: Optional[str] = None + # For testing only + isolated: bool = False + def to_camel_case(snake_str: str) -> str: components = snake_str.split("_") diff --git a/pyproject.toml b/pyproject.toml index 1290059..3b12afe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ name = "python-lsp-ruff" authors = [ {name = "Julian Hossbach", email = "julian.hossbach@gmx.de"} ] -version = "2.3.3" +version = "2.3.4" description = "Ruff linting plugin for pylsp" readme = "README.md" requires-python = ">=3.8" diff --git a/tests/test_code_actions.py b/tests/test_code_actions.py index 9d97d58..84b82a1 100644 --- a/tests/test_code_actions.py +++ b/tests/test_code_actions.py @@ -24,6 +24,7 @@ def workspace(tmp_path): """Return a workspace.""" ws = Workspace(tmp_path.absolute().as_uri(), Mock()) ws._config = Config(ws.root_uri, {}, 0, {}) + ws._config.update({"plugins": {"ruff": {"isolated": True}}}) return ws @@ -79,7 +80,7 @@ def test_ruff_code_actions(workspace): _, doc = temp_document(codeaction_str, workspace) workspace._config.update( - {"plugins": {"ruff": {"select": ["F"], "unsafeFixes": True}}} + {"plugins": {"ruff": {"isolated": True, "select": ["F"], "unsafeFixes": True}}} ) diags = ruff_lint.pylsp_lint(workspace, doc) range_ = cattrs.unstructure( @@ -97,7 +98,11 @@ def test_ruff_code_actions_unfixable(workspace): _, doc = temp_document(codeaction_str, workspace) workspace._config.update( - {"plugins": {"ruff": {"select": ["F"], "unfixable": ["F841"]}}} + { + "plugins": { + "ruff": {"isolated": True, "select": ["F"], "unfixable": ["F841"]} + } + } ) diags = ruff_lint.pylsp_lint(workspace, doc) range_ = cattrs.unstructure( @@ -116,6 +121,7 @@ def test_import_action(workspace): { "plugins": { "ruff": { + "isolated": True, "extendSelect": ["I"], "extendIgnore": ["F"], } @@ -153,6 +159,7 @@ def f(): { "plugins": { "ruff": { + "isolated": True, "unsafeFixes": True, } } @@ -167,6 +174,7 @@ def f(): { "plugins": { "ruff": { + "isolated": True, "unsafeFixes": False, } } diff --git a/tests/test_ruff_format.py b/tests/test_ruff_format.py index 3d7ef85..03f278a 100644 --- a/tests/test_ruff_format.py +++ b/tests/test_ruff_format.py @@ -52,6 +52,7 @@ def workspace(tmp_path): """Return a workspace.""" ws = Workspace(tmp_path.absolute().as_uri(), Mock()) ws._config = Config(ws.root_uri, {}, 0, {}) + ws._config.update({"plugins": {"ruff": {"isolated": True}}}) return ws @@ -100,7 +101,11 @@ def test_ruff_format_only(workspace): def test_ruff_format_disabled(workspace): _, doc = temp_document(_UNFORMATTED_CODE, workspace) workspace._config.update( - {"plugins": {"ruff": {"format": ["I001"], "formatEnabled": False}}} + { + "plugins": { + "ruff": {"isolated": True, "format": ["I001"], "formatEnabled": False} + } + } ) got = run_plugin_format(workspace, doc) assert got == "" @@ -114,6 +119,7 @@ def test_ruff_format_and_sort_imports(workspace): { "plugins": { "ruff": { + "isolated": True, "format": ["I001"], } } diff --git a/tests/test_ruff_lint.py b/tests/test_ruff_lint.py index aaca79b..81c1de6 100644 --- a/tests/test_ruff_lint.py +++ b/tests/test_ruff_lint.py @@ -34,6 +34,7 @@ def workspace(tmp_path): """Return a workspace.""" ws = Workspace(tmp_path.absolute().as_uri(), Mock()) ws._config = Config(ws.root_uri, {}, 0, {}) + ws._config.update({"plugins": {"ruff": {"isolated": True}}}) return ws