Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
17 changes: 16 additions & 1 deletion pylsp/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
5 changes: 5 additions & 0 deletions pylsp/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
32 changes: 32 additions & 0 deletions test/test_configuration.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down