Commit d54053d Jose Alvarez
authored
File tree 2 files changed +25
-3
lines changed
lua/null-ls/builtins/formatting
2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -1374,6 +1374,8 @@ local sources = { null_ls.builtins.formatting.uncrustify }
1374
1374
##### About
1375
1375
1376
1376
Formatter for ` python ` files
1377
+ - Supports both ` textDocument/formatting ` and ` textDocument/rangeFormatting ` .
1378
+ - ` textDocument/rangeFormatting ` is line-based.
1377
1379
1378
1380
##### Usage
1379
1381
Original file line number Diff line number Diff line change @@ -2,15 +2,35 @@ local h = require("null-ls.helpers")
2
2
local methods = require (" null-ls.methods" )
3
3
4
4
local FORMATTING = methods .internal .FORMATTING
5
+ local RANGE_FORMATTING = methods .internal .RANGE_FORMATTING
6
+
7
+ local function range_formatting_args_factory (base_args , start_arg )
8
+ vim .validate ({
9
+ base_args = { base_args , " table" },
10
+ start_arg = { start_arg , " string" },
11
+ })
12
+
13
+ return function (params )
14
+ local args = vim .deepcopy (base_args )
15
+ if params .method == FORMATTING then
16
+ return args
17
+ end
18
+
19
+ local range = params .range
20
+ table.insert (args , start_arg )
21
+ table.insert (args , range .row .. " -" .. range .end_row ) -- range of lines to reformat, one-based
22
+ return args
23
+ end
24
+ end
5
25
6
26
return h .make_builtin ({
7
- method = FORMATTING ,
27
+ method = { FORMATTING , RANGE_FORMATTING } ,
8
28
filetypes = { " python" },
9
29
generator_opts = {
10
30
command = " yapf" ,
11
- args = {
31
+ args = range_formatting_args_factory ( {
12
32
" --quiet" ,
13
- },
33
+ }, " --lines " ),
14
34
to_stdin = true ,
15
35
},
16
36
factory = h .formatter_factory ,
You can’t perform that action at this time.
0 commit comments