8
8
import toml
9
9
from pylsp import hookimpl
10
10
from pylsp ._utils import get_eol_chars
11
+ from pylsp .config .config import Config
11
12
12
13
logger = logging .getLogger (__name__ )
13
14
28
29
29
30
30
31
@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 )
33
34
34
35
35
36
@hookimpl (tryfirst = True )
36
- def pylsp_format_range (document , range ):
37
+ def pylsp_format_range (config , document , range ):
37
38
range ["start" ]["character" ] = 0
38
39
range ["end" ]["line" ] += 1
39
40
range ["end" ]["character" ] = 0
40
- return format_document (document , range )
41
+ return format_document (config , document , range )
41
42
42
43
43
- def format_document (document , range = None ):
44
+ def format_document (client_config , document , range = None ):
44
45
if range :
45
46
start = range ["start" ]["line" ]
46
47
end = range ["end" ]["line" ]
@@ -52,7 +53,7 @@ def format_document(document, range=None):
52
53
"end" : {"line" : len (document .lines ), "character" : 0 },
53
54
}
54
55
55
- config = load_config (document .path )
56
+ config = load_config (document .path , client_config )
56
57
57
58
try :
58
59
formatted_text = format_text (text = text , config = config )
@@ -105,9 +106,11 @@ def format_text(*, text, config):
105
106
106
107
107
108
@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
+
109
112
defaults = {
110
- "line_length" : 88 ,
113
+ "line_length" : settings . get ( "line_length" , 88 ) ,
111
114
"fast" : False ,
112
115
"pyi" : filename .endswith (".pyi" ),
113
116
"skip_string_normalization" : False ,
0 commit comments