@@ -34,12 +34,8 @@ def pylsp_settings() -> Dict[str, Any]:
34
34
35
35
@hookimpl (hookwrapper = True )
36
36
def pylsp_format_document (config : Config , document : Document ) -> Generator :
37
- range = Range (
38
- start = {"line" : 0 , "character" : 0 },
39
- end = {"line" : len (document .lines ), "character" : 0 },
40
- )
41
37
outcome = yield
42
- _format (outcome , config , document , range )
38
+ _format (outcome , config , document )
43
39
44
40
45
41
@hookimpl (hookwrapper = True )
@@ -48,13 +44,21 @@ def pylsp_format_range(config: Config, document: Document, range: Range) -> Gene
48
44
_format (outcome , config , document , range )
49
45
50
46
51
- def _format (outcome , config : Config , document : Document , range : Range ) -> None :
47
+ def _format (
48
+ outcome , config : Config , document : Document , range : Optional [Range ] = None
49
+ ) -> None :
52
50
result = outcome .get_result ()
53
51
if result :
54
52
text = result [0 ]["newText" ]
55
53
range = result [0 ]["range" ]
56
- else :
54
+ elif range :
57
55
text = "" .join (document .lines [range ["start" ]["line" ] : range ["end" ]["line" ]])
56
+ else :
57
+ text = document .source
58
+ range = Range (
59
+ start = {"line" : 0 , "character" : 0 },
60
+ end = {"line" : len (document .lines ), "character" : 0 },
61
+ )
58
62
59
63
IGNORE_KEYS = {"enabled" }
60
64
settings = config .plugin_settings ("isort" , document_path = document .path )
0 commit comments