|
1 | 1 | # Copyright 2021- Python Language Server Contributors. |
2 | 2 |
|
| 3 | +from importlib.metadata import distribution |
3 | 4 | from unittest.mock import patch |
4 | 5 |
|
5 | 6 | import pytest |
6 | 7 |
|
7 | 8 | from pylsp import IS_WIN |
| 9 | +from pylsp.config.config import Config |
8 | 10 | from test.test_notebook_document import wait_for_condition |
9 | 11 | from test.test_utils import send_initialize_request |
10 | 12 |
|
|
19 | 21 | } |
20 | 22 |
|
21 | 23 |
|
| 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 | + |
22 | 54 | @pytest.mark.skipif(IS_WIN, reason="Flaky on Windows") |
23 | 55 | def test_set_flake8_using_init_opts(client_server_pair) -> None: |
24 | 56 | client, server = client_server_pair |
|
0 commit comments