diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 5a5a228d..95db18d2 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -19,6 +19,7 @@ This server can be configured using the `workspace/didChangeConfiguration` metho | `pylsp.plugins.flake8.indentSize` | `integer` | Set indentation spaces. | `null` | | `pylsp.plugins.flake8.perFileIgnores` | `array` of `string` items | A pairing of filenames and violation codes that defines which violations to ignore in a particular file, for example: `["file_path.py:W305,W304"]`). | `[]` | | `pylsp.plugins.flake8.select` | `array` of unique `string` items | List of errors and warnings to enable. | `null` | +| `pylsp.plugins.jedi.enabled` | `boolean` | Enable the built-in Jedi plugins. Individual plugins can be disabled separately. | `true` | | `pylsp.plugins.jedi.auto_import_modules` | `array` of `string` items | List of module names for jedi.settings.auto_import_modules. | `["numpy"]` | | `pylsp.plugins.jedi.extra_paths` | `array` of `string` items | Define extra paths for jedi.Script. | `[]` | | `pylsp.plugins.jedi.prioritize_extra_paths` | `boolean` | Whether to place extra_paths at the beginning (true) or end (false) of `sys.path` | `false` | diff --git a/README.md b/README.md index 6f6cb19b..ed2a29de 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,8 @@ Please file an issue if you require assistance writing a plugin. Like all language servers, configuration can be passed from the client that talks to this server (i.e. your editor/IDE or other tool that has the same purpose). The details of how this is done depend on the editor or plugin that you are using to communicate with `python-lsp-server`. The configuration options available at that level are documented in [`CONFIGURATION.md`](https://github.com/python-lsp/python-lsp-server/blob/develop/CONFIGURATION.md). +If another language server provides completion and navigation, set `pylsp.plugins.jedi.enabled` to `false` to disable the built-in Jedi plugins together. You can continue to use formatting plugins such as Black and isort. + `python-lsp-server` depends on other tools, like flake8 and pycodestyle. These tools can be configured via settings passed from the client (as above), or alternatively from other configuration sources. The following sources are available: - `pycodestyle`: discovered in `~/.config/pycodestyle`, `setup.cfg`, `tox.ini` and `pycodestyle.cfg`. diff --git a/pylsp/config/config.py b/pylsp/config/config.py index 7b201824..f13db2bd 100644 --- a/pylsp/config/config.py +++ b/pylsp/config/config.py @@ -25,6 +25,18 @@ # Sources of config, first source overrides next source DEFAULT_CONFIG_SOURCES = ["pycodestyle"] +JEDI_PLUGINS = { + "jedi_completion", + "jedi_definition", + "jedi_highlight", + "jedi_hover", + "jedi_references", + "jedi_rename", + "jedi_signature_help", + "jedi_symbols", + "jedi_type_definition", +} + class PluginManager(pluggy.PluginManager): def _hookexec( @@ -195,9 +207,12 @@ def update(self, settings) -> None: def _update_disabled_plugins(self) -> None: # All plugins default to enabled + settings = self.settings().get("plugins", {}) + disable_jedi = not settings.get("jedi", {}).get("enabled", True) self._disabled_plugins = [ plugin for name, plugin in self.plugin_manager.list_name_plugin() - if not self.settings().get("plugins", {}).get(name, {}).get("enabled", True) + if not settings.get(name, {}).get("enabled", True) + or (disable_jedi and name in JEDI_PLUGINS) ] log.info("Disabled plugins: %s", self._disabled_plugins) diff --git a/pylsp/config/schema.json b/pylsp/config/schema.json index e14daa20..6d8c4d8c 100644 --- a/pylsp/config/schema.json +++ b/pylsp/config/schema.json @@ -136,6 +136,11 @@ "uniqueItems": true, "description": "List of errors and warnings to enable." }, + "pylsp.plugins.jedi.enabled": { + "type": "boolean", + "default": true, + "description": "Enable the built-in Jedi plugins. Individual plugins can be disabled separately." + }, "pylsp.plugins.jedi.auto_import_modules": { "type": "array", "default": [ diff --git a/test/test_configuration.py b/test/test_configuration.py index e6b40121..6fbd510c 100644 --- a/test/test_configuration.py +++ b/test/test_configuration.py @@ -1,10 +1,12 @@ # Copyright 2021- Python Language Server Contributors. +from importlib.metadata import distribution from unittest.mock import patch import pytest from pylsp import IS_WIN +from pylsp.config.config import Config from test.test_notebook_document import wait_for_condition from test.test_utils import send_initialize_request @@ -19,6 +21,36 @@ } +def test_disable_jedi_plugins(tmp_path) -> None: + disabled = { + "plugins": {"jedi": {"enabled": False}, "jedi_completion": {"enabled": True}} + } + config = Config(tmp_path.as_uri(), {"pylsp": disabled}, 0, {}) + manager = config.plugin_manager + jedi_plugins = { + manager.get_plugin(entry.name) + for entry in distribution("python-lsp-server").entry_points + if entry.group == "pylsp" and entry.name.startswith("jedi_") + } + assert None not in jedi_plugins + assert manager.get_plugin("jedi_completion") in jedi_plugins + assert jedi_plugins.issubset(config.disabled_plugins) + assert manager.get_plugin("folding") not in config.disabled_plugins + + extra_plugin = object() + manager.register(extra_plugin, "jedi_extra") + config.update(disabled) + assert extra_plugin not in config.disabled_plugins + + config.update( + {"plugins": {"jedi": {"enabled": True}, "jedi_hover": {"enabled": False}}} + ) + assert manager.get_plugin("jedi_hover") in config.disabled_plugins + assert (jedi_plugins - {manager.get_plugin("jedi_hover")}).isdisjoint( + config.disabled_plugins + ) + + @pytest.mark.skipif(IS_WIN, reason="Flaky on Windows") def test_set_flake8_using_init_opts(client_server_pair) -> None: client, server = client_server_pair