Skip to content

Commit 1552856

Browse files
committed
Add a setting to disable the built-in Jedi plugins together
1 parent a362006 commit 1552856

5 files changed

Lines changed: 56 additions & 1 deletion

File tree

‎CONFIGURATION.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This server can be configured using the `workspace/didChangeConfiguration` metho
1919
| `pylsp.plugins.flake8.indentSize` | `integer` | Set indentation spaces. | `null` |
2020
| `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"]`). | `[]` |
2121
| `pylsp.plugins.flake8.select` | `array` of unique `string` items | List of errors and warnings to enable. | `null` |
22+
| `pylsp.plugins.jedi.enabled` | `boolean` | Enable the built-in Jedi plugins. Individual plugins can be disabled separately. | `true` |
2223
| `pylsp.plugins.jedi.auto_import_modules` | `array` of `string` items | List of module names for jedi.settings.auto_import_modules. | `["numpy"]` |
2324
| `pylsp.plugins.jedi.extra_paths` | `array` of `string` items | Define extra paths for jedi.Script. | `[]` |
2425
| `pylsp.plugins.jedi.prioritize_extra_paths` | `boolean` | Whether to place extra_paths at the beginning (true) or end (false) of `sys.path` | `false` |

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ Please file an issue if you require assistance writing a plugin.
9797

9898
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).
9999

100+
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.
101+
100102
`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:
101103

102104
- `pycodestyle`: discovered in `~/.config/pycodestyle`, `setup.cfg`, `tox.ini` and `pycodestyle.cfg`.

‎pylsp/config/config.py‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
# Sources of config, first source overrides next source
2626
DEFAULT_CONFIG_SOURCES = ["pycodestyle"]
2727

28+
JEDI_PLUGINS = {
29+
"jedi_completion",
30+
"jedi_definition",
31+
"jedi_highlight",
32+
"jedi_hover",
33+
"jedi_references",
34+
"jedi_rename",
35+
"jedi_signature_help",
36+
"jedi_symbols",
37+
"jedi_type_definition",
38+
}
39+
2840

2941
class PluginManager(pluggy.PluginManager):
3042
def _hookexec(
@@ -195,9 +207,12 @@ def update(self, settings) -> None:
195207

196208
def _update_disabled_plugins(self) -> None:
197209
# All plugins default to enabled
210+
settings = self.settings().get("plugins", {})
211+
disable_jedi = not settings.get("jedi", {}).get("enabled", True)
198212
self._disabled_plugins = [
199213
plugin
200214
for name, plugin in self.plugin_manager.list_name_plugin()
201-
if not self.settings().get("plugins", {}).get(name, {}).get("enabled", True)
215+
if not settings.get(name, {}).get("enabled", True)
216+
or (disable_jedi and name in JEDI_PLUGINS)
202217
]
203218
log.info("Disabled plugins: %s", self._disabled_plugins)

‎pylsp/config/schema.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@
136136
"uniqueItems": true,
137137
"description": "List of errors and warnings to enable."
138138
},
139+
"pylsp.plugins.jedi.enabled": {
140+
"type": "boolean",
141+
"default": true,
142+
"description": "Enable the built-in Jedi plugins. Individual plugins can be disabled separately."
143+
},
139144
"pylsp.plugins.jedi.auto_import_modules": {
140145
"type": "array",
141146
"default": [

‎test/test_configuration.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Copyright 2021- Python Language Server Contributors.
22

3+
from importlib.metadata import distribution
34
from unittest.mock import patch
45

56
import pytest
67

78
from pylsp import IS_WIN
9+
from pylsp.config.config import Config
810
from test.test_notebook_document import wait_for_condition
911
from test.test_utils import send_initialize_request
1012

@@ -19,6 +21,36 @@
1921
}
2022

2123

24+
def test_disable_jedi_plugins(tmp_path) -> None:
25+
disabled = {
26+
"plugins": {"jedi": {"enabled": False}, "jedi_completion": {"enabled": True}}
27+
}
28+
config = Config(tmp_path.as_uri(), {"pylsp": disabled}, 0, {})
29+
manager = config.plugin_manager
30+
jedi_plugins = {
31+
manager.get_plugin(entry.name)
32+
for entry in distribution("python-lsp-server").entry_points
33+
if entry.group == "pylsp" and entry.name.startswith("jedi_")
34+
}
35+
assert None not in jedi_plugins
36+
assert manager.get_plugin("jedi_completion") in jedi_plugins
37+
assert jedi_plugins.issubset(config.disabled_plugins)
38+
assert manager.get_plugin("folding") not in config.disabled_plugins
39+
40+
extra_plugin = object()
41+
manager.register(extra_plugin, "jedi_extra")
42+
config.update(disabled)
43+
assert extra_plugin not in config.disabled_plugins
44+
45+
config.update(
46+
{"plugins": {"jedi": {"enabled": True}, "jedi_hover": {"enabled": False}}}
47+
)
48+
assert manager.get_plugin("jedi_hover") in config.disabled_plugins
49+
assert (jedi_plugins - {manager.get_plugin("jedi_hover")}).isdisjoint(
50+
config.disabled_plugins
51+
)
52+
53+
2254
@pytest.mark.skipif(IS_WIN, reason="Flaky on Windows")
2355
def test_set_flake8_using_init_opts(client_server_pair) -> None:
2456
client, server = client_server_pair

0 commit comments

Comments
 (0)