Skip to content

Commit 0e3bda6

Browse files
committed
Add client side config options
Also, use those options to get the line length used by Black.
1 parent c814fad commit 0e3bda6

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

pylsp_black/plugin.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import toml
99
from pylsp import hookimpl
1010
from pylsp._utils import get_eol_chars
11+
from pylsp.config.config import Config
1112

1213
logger = logging.getLogger(__name__)
1314

@@ -28,19 +29,19 @@
2829

2930

3031
@hookimpl(tryfirst=True)
31-
def pylsp_format_document(document):
32-
return format_document(document)
32+
def pylsp_format_document(config, document):
33+
return format_document(config, document)
3334

3435

3536
@hookimpl(tryfirst=True)
36-
def pylsp_format_range(document, range):
37+
def pylsp_format_range(config, document, range):
3738
range["start"]["character"] = 0
3839
range["end"]["line"] += 1
3940
range["end"]["character"] = 0
40-
return format_document(document, range)
41+
return format_document(config, document, range)
4142

4243

43-
def format_document(document, range=None):
44+
def format_document(client_config, document, range=None):
4445
if range:
4546
start = range["start"]["line"]
4647
end = range["end"]["line"]
@@ -52,7 +53,7 @@ def format_document(document, range=None):
5253
"end": {"line": len(document.lines), "character": 0},
5354
}
5455

55-
config = load_config(document.path)
56+
config = load_config(document.path, client_config)
5657

5758
try:
5859
formatted_text = format_text(text=text, config=config)
@@ -105,9 +106,11 @@ def format_text(*, text, config):
105106

106107

107108
@lru_cache(100)
108-
def load_config(filename: str) -> Dict:
109+
def load_config(filename: str, client_config: Config) -> Dict:
110+
settings = client_config.plugin_settings("black")
111+
109112
defaults = {
110-
"line_length": 88,
113+
"line_length": settings.get("line_length", 88),
111114
"fast": False,
112115
"pyi": filename.endswith(".pyi"),
113116
"skip_string_normalization": False,

0 commit comments

Comments
 (0)