fix(format): add config defaults and proper type hints
This commit is contained in:
+13
-13
@@ -88,22 +88,22 @@ end
|
||||
---| '"in_place"'
|
||||
|
||||
---@class ow.FormatOptions
|
||||
---@field buf integer Buffer to apply formatting to
|
||||
---@field buf? integer Buffer to apply formatting to
|
||||
---@field cmd string[] Command to run. The following keywords get replaces by the specified values:
|
||||
--- * %file% - path to the current file
|
||||
--- * %filename% - name of the current file
|
||||
--- * %file% - path to the file for `buf`
|
||||
--- * %filename% - name of the file for `buf`
|
||||
--- * %row_start% - first row of selection
|
||||
--- * %row_end% - last row of selection
|
||||
--- * %col_start% - first column position of selection
|
||||
--- * %col_end% - last column position of selection
|
||||
--- * %byte_start% - byte count of first cell in selection
|
||||
--- * %byte_end% - byte count of last cell in selection
|
||||
---@field output OutputStream What stream to use as the result. May be one of `stdout`, `stderr` or `in_place`.
|
||||
---@field auto_indent boolean Perform auto indent on formatted range
|
||||
---@field only_selection boolean Only send the selected lines to `stdin`
|
||||
---@field ignore_ret boolean Ignore non-zero return codes
|
||||
---@field ignore_stderr boolean Ignore stderr output when not using stderr for output
|
||||
---@field env table<string, string> Map of environment variables
|
||||
---@field output? OutputStream What stream to use as the result. May be one of `stdout`, `stderr` or `in_place`.
|
||||
---@field auto_indent? boolean Perform auto indent on formatted range
|
||||
---@field only_selection? boolean Only send the selected lines to `stdin`
|
||||
---@field ignore_ret? boolean Ignore non-zero return codes
|
||||
---@field ignore_stderr? boolean Ignore stderr output when not using stderr for output
|
||||
---@field env? table<string, string> Map of environment variables
|
||||
local FormatOptions = {}
|
||||
FormatOptions.__index = FormatOptions
|
||||
|
||||
@@ -111,17 +111,17 @@ function FormatOptions.from_opts(opts)
|
||||
return setmetatable({
|
||||
buf = opts.buf or vim.api.nvim_get_current_buf(),
|
||||
cmd = opts.cmd,
|
||||
output = opts.output,
|
||||
output = opts.output or "stdout",
|
||||
auto_indent = opts.auto_indent or false,
|
||||
only_selection = opts.only_selection or false,
|
||||
ignore_ret = opts.ignore_ret,
|
||||
ignore_stderr = opts.ignore_stderr,
|
||||
ignore_ret = opts.ignore_ret or false,
|
||||
ignore_stderr = opts.ignore_stderr or false,
|
||||
env = opts.env,
|
||||
}, FormatOptions)
|
||||
end
|
||||
|
||||
--- Format buffer
|
||||
---@param opts table
|
||||
---@param opts ow.FormatOptions
|
||||
function Util.format(opts)
|
||||
opts = FormatOptions.from_opts(opts)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user