@@ -3,15 +3,6 @@ local Path = require("plenary.path")
33
44local lspconfig_util = require (" lspconfig.util" )
55
6- local DEFAULT_OPTS = {
7- column_width = 120 ,
8- line_endings = " Unix" ,
9- indent_type = " Tabs" ,
10- indent_width = 4 ,
11- quote_style = " AutoPreferDouble" ,
12- call_parentheses = " Always" ,
13- }
14-
156local M = {}
167M ._config = {}
178
@@ -31,13 +22,13 @@ local function find_stylua(path)
3122 break
3223 end
3324
34- local stylua_path = Path :new { dir , " stylua.toml" }
25+ local stylua_path = Path :new ( { dir , " stylua.toml" })
3526 if stylua_path :exists () then
3627 M ._config [path ] = stylua_path :absolute ()
3728 break
3829 end
3930
40- stylua_path = Path :new { dir , " .stylua.toml" }
31+ stylua_path = Path :new ( { dir , " .stylua.toml" })
4132 if stylua_path :exists () then
4233 M ._config [path ] = stylua_path :absolute ()
4334 break
@@ -47,34 +38,15 @@ local function find_stylua(path)
4738
4839 return M ._config [path ]
4940end
50- function M .setup (opts )
51- local conf = vim .tbl_deep_extend (" force" , DEFAULT_OPTS , opts or {})
52-
53- M ._config .column_width = conf .column_width
54- M ._config .line_endings = conf .line_endings
55- M ._config .indent_type = conf .indent_type
56- M ._config .indent_width = conf .indent_width
57- M ._config .quote_style = conf .quote_style
58- M ._config .call_parentheses = conf .call_parentheses
59- end
6041
6142function M .format (bufnr )
6243 bufnr = bufnr or vim .api .nvim_get_current_buf ()
6344 local filepath = Path :new (vim .api .nvim_buf_get_name (bufnr )):absolute ()
6445 local stylua_toml = find_stylua (filepath )
6546
66- local args
47+ local args = {}
6748 if stylua_toml then
68- args = { " --config-path" , stylua_toml }
69- else
70- args = {
71- " --column-width" , M ._config .column_width ,
72- " --line-endings" , M ._config .line_endings ,
73- " --indent-type" , M ._config .indent_type ,
74- " --indent-width" , M ._config .indent_width ,
75- " --quote-style" , M ._config .quote_style ,
76- " --call-parentheses" , M ._config .call_parentheses ,
77- }
49+ args = { " --config-path" , stylua_toml }
7850 end
7951
8052 table.insert (args , " -" )
@@ -84,15 +56,20 @@ function M.format(bufnr)
8456 command = " stylua" ,
8557 args = args ,
8658 writer = vim .api .nvim_buf_get_lines (0 , 0 , - 1 , false ),
87- on_stderr = function (_ , data )
59+ on_stderr = function (_ , data )
8860 table.insert (errors , data )
89- end
61+ end ,
9062 })
9163
9264 local output = job :sync ()
9365 if job .code ~= 0 then
9466 vim .schedule (function ()
95- error (string.format (" [stylua] %s" , errors [0 ] or " Failed to format due to errors" ))
67+ error (
68+ string.format (
69+ " [stylua] %s" ,
70+ errors [1 ] or " Failed to format due to errors"
71+ )
72+ )
9673 end )
9774
9875 return
0 commit comments