Skip to content

Commit 15336a9

Browse files
authored
feat: add option to pass the stylua.toml location (#2)
* feat: add option to pass the stylua.toml location * fix: logic to set path * docs: update * make ci happy
1 parent 47b3434 commit 15336a9

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

doc/stylua.txt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,23 @@ To find out more:
1212
https://github.com/wesleimp/stylua.nvim
1313

1414

15-
stylua.format({bufnr}) *stylua.format*
16-
Format your Lua code. If {bufnr} is not set, the current buffer will be
15+
stylua.format({opts}) *stylua.format*
16+
Format your Lua code. If {opts} is not set, some defaults will be
1717
used to format >
1818
19+
Parameters: ~
20+
{opts} (table) options to pass to the formatter
21+
22+
Options: ~
23+
{bufnr} (number) specify the buffer number where
24+
treesitter should run. (default:
25+
current buffer)
26+
27+
{config_path} (string) specify the config file to use.
28+
(default: .stylua.toml or
29+
stylua.toml defined in the
30+
project)
31+
1932
:lua require("stylua").format()
2033
<
2134
vim:tw=78:ts=8:ft=help:norl:

lua/stylua/init.lua

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,17 @@ local function find_stylua(path)
3838
return M._config[path]
3939
end
4040

41-
function M.format(bufnr)
42-
bufnr = bufnr or vim.api.nvim_get_current_buf()
43-
local filepath = Path:new(vim.api.nvim_buf_get_name(bufnr)):absolute()
44-
local stylua_toml = find_stylua(filepath)
41+
function M.format(opts)
42+
opts = opts or {}
43+
local bufnr = opts.bufnr or vim.api.nvim_get_current_buf()
44+
45+
local stylua_toml
46+
if opts.config_path then
47+
stylua_toml = Path:new(opts.config_path):absolute()
48+
else
49+
local filepath = Path:new(vim.api.nvim_buf_get_name(bufnr)):absolute()
50+
stylua_toml = find_stylua(filepath)
51+
end
4552

4653
local args = {}
4754

0 commit comments

Comments
 (0)