From b6e44bb644aa4cf78d296d2b5329174a96c731e6 Mon Sep 17 00:00:00 2001 From: Oscar Wallberg Date: Sat, 28 Feb 2026 09:48:13 +0100 Subject: [PATCH] fix(format): add config defaults and proper type hints --- lua/util.lua | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lua/util.lua b/lua/util.lua index 6bda49b..b2dcc1b 100644 --- a/lua/util.lua +++ b/lua/util.lua @@ -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 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 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)