From 15336a99c599ff10b04d324310bc1295f5203acb Mon Sep 17 00:00:00 2001 From: Weslei Juan Novaes Pereira <42675056+wesleimp@users.noreply.github.com> Date: Mon, 25 Jul 2022 15:11:28 -0300 Subject: [PATCH] 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 --- doc/stylua.txt | 17 +++++++++++++++-- lua/stylua/init.lua | 15 +++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/doc/stylua.txt b/doc/stylua.txt index 12bfca8..91b24cc 100644 --- a/doc/stylua.txt +++ b/doc/stylua.txt @@ -12,10 +12,23 @@ To find out more: https://github.com/wesleimp/stylua.nvim -stylua.format({bufnr}) *stylua.format* - Format your Lua code. If {bufnr} is not set, the current buffer will be +stylua.format({opts}) *stylua.format* + Format your Lua code. If {opts} is not set, some defaults will be used to format > + Parameters: ~ + {opts} (table) options to pass to the formatter + + Options: ~ + {bufnr} (number) specify the buffer number where + treesitter should run. (default: + current buffer) + + {config_path} (string) specify the config file to use. + (default: .stylua.toml or + stylua.toml defined in the + project) + :lua require("stylua").format() < vim:tw=78:ts=8:ft=help:norl: diff --git a/lua/stylua/init.lua b/lua/stylua/init.lua index c1ccd32..f10b6e3 100644 --- a/lua/stylua/init.lua +++ b/lua/stylua/init.lua @@ -38,10 +38,17 @@ local function find_stylua(path) return M._config[path] end -function M.format(bufnr) - bufnr = bufnr or vim.api.nvim_get_current_buf() - local filepath = Path:new(vim.api.nvim_buf_get_name(bufnr)):absolute() - local stylua_toml = find_stylua(filepath) +function M.format(opts) + opts = opts or {} + local bufnr = opts.bufnr or vim.api.nvim_get_current_buf() + + local stylua_toml + if opts.config_path then + stylua_toml = Path:new(opts.config_path):absolute() + else + local filepath = Path:new(vim.api.nvim_buf_get_name(bufnr)):absolute() + stylua_toml = find_stylua(filepath) + end local args = {}