File tree 2 files changed +39
-3
lines changed 2 files changed +39
-3
lines changed Original file line number Diff line number Diff line change 1
1
local options = require (" prettier.options" )
2
2
local null_ls = require (" prettier.null-ls" )
3
3
4
- local M = {}
4
+ local M = {
5
+ __ = {},
6
+ }
5
7
6
8
function M .setup (user_options )
7
9
options .setup (user_options )
@@ -14,4 +16,38 @@ function M.format(method)
14
16
null_ls .format (method )
15
17
end
16
18
19
+ function M .create_formatter (opts )
20
+ local command = opts .command
21
+
22
+ M .__ [command ] = {
23
+ _fn = function (method )
24
+ if M .__ [command ].fn then
25
+ return M .__ [command ].fn (method )
26
+ end
27
+ end ,
28
+ cmd = function (range )
29
+ if range > 0 then
30
+ M .__ [command ]._fn (" textDocument/rangeFormatting" )
31
+ else
32
+ M .__ [command ]._fn (" textDocument/formatting" )
33
+ end
34
+ end ,
35
+ }
36
+
37
+ vim .schedule (function ()
38
+ local format = null_ls .create_formatter ({
39
+ bin = opts .bin ,
40
+ bin_preference = opts .bin_preference ,
41
+ cli_options = opts .cli_options ,
42
+ [" null-ls" ] = opts [" null-ls" ],
43
+ })
44
+
45
+ M .__ [command ].fn = format
46
+
47
+ vim .cmd (string.format ([[ command! -range=%% %s :lua require("prettier").__["%s"].cmd(<range>)]] , command , command ))
48
+ end )
49
+
50
+ return M .__ [command ]._fn
51
+ end
52
+
17
53
return M
Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ local function create_generator(opts)
71
71
})
72
72
end
73
73
74
- local function create_formatter (opts )
74
+ function M . create_formatter (opts )
75
75
if not ok then
76
76
return noop
77
77
end
@@ -161,7 +161,7 @@ local function create_formatter(opts)
161
161
end
162
162
163
163
function M .setup ()
164
- M .format = create_formatter ({
164
+ M .format = M . create_formatter ({
165
165
bin = options .get (" bin" ),
166
166
cli_options = options .get (" cli_options" ),
167
167
[" null-ls" ] = {
You can’t perform that action at this time.
0 commit comments