Skip to content

Commit

Permalink
feat: add option to pass the stylua.toml location (#2)
Browse files Browse the repository at this point in the history
* feat: add option to pass the stylua.toml location

* fix: logic to set path

* docs: update

* make ci happy
  • Loading branch information
wesleimp authored Jul 25, 2022
1 parent 47b3434 commit 15336a9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
17 changes: 15 additions & 2 deletions doc/stylua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:
15 changes: 11 additions & 4 deletions lua/stylua/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down

0 comments on commit 15336a9

Please sign in to comment.