Skip to content

Read skip options from plugin settings #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2023
Merged
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ the valid configuration keys:
configuration files, which should be preferred for multi-user projects.
- `pylsp.plugins.black.preview`: a boolean to enable or disable [black's `--preview`
setting](https://black.readthedocs.io/en/stable/the_black_code_style/future_style.html#preview-style).
- `pylsp.plugins.black.skip_string_normalization`: a boolean to enable or disable black's `--skip-string-normalization` setting. `false` by default.
- `pylsp.plugins.black.skip_magic_trailing_comma`: a boolean to enable or disable black's `skip-magic-trailing-comma` setting. `false` by default.

# Development

Expand Down
4 changes: 2 additions & 2 deletions pylsp_black/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ def _load_config(filename: str, client_config: Config) -> Dict:
"line_length": settings.get("line_length", 88),
"fast": False,
"pyi": filename.endswith(".pyi"),
"skip_string_normalization": False,
"skip_magic_trailing_comma": False,
"skip_string_normalization": settings.get("skip_string_normalization", False),
"skip_magic_trailing_comma": settings.get("skip_magic_trailing_comma", False),
"target_version": set(),
"preview": settings.get("preview", False),
}
Expand Down
33 changes: 33 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ def config(workspace):
return cfg


@pytest.fixture
def config_with_skip_options(workspace):
"""Return a config object."""
cfg = Config(workspace.root_uri, {}, 0, {})
cfg._plugin_settings = {
"plugins": {
"black": {
"line_length": 88,
"cache_config": False,
"skip_string_normalization": True,
"skip_magic_trailing_comma": True,
}
}
}
return cfg


@pytest.fixture
def unformatted_document(workspace):
path = fixtures_dir / "unformatted.txt"
Expand Down Expand Up @@ -271,6 +288,22 @@ def test_load_config_defaults(config):
}


def test_load_config_with_skip_options(config_with_skip_options):
config = load_config(
str(fixtures_dir / "skip_options" / "example.py"), config_with_skip_options
)

assert config == {
"line_length": 88,
"target_version": set(),
"pyi": False,
"fast": False,
"skip_magic_trailing_comma": True,
"skip_string_normalization": True,
"preview": False,
}


def test_entry_point():
distribution = pkg_resources.get_distribution("python-lsp-black")
entry_point = distribution.get_entry_info("pylsp", "pylsp_black")
Expand Down