chore: resolve undefined-field

This commit is contained in:
Alexander Courtis 2024-11-02 17:16:35 +11:00
parent 82c868fbab
commit 1e1a273b36

View File

@ -1,7 +1,12 @@
local M = {
config = nil,
path = nil,
}
---@alias LogTypes "all" | "config" | "copy_paste" | "dev" | "diagnostics" | "git" | "profile" | "watcher"
---@type table<LogTypes, boolean>
local types = {}
---@type string
local file_path
local M = {}
--- Write to log file
---@param typ string as per log.types config
@ -13,7 +18,7 @@ function M.raw(typ, fmt, ...)
end
local line = string.format(fmt, ...)
local file = io.open(M.path, "a")
local file = io.open(file_path, "a")
if file then
io.output(file)
io.write(line)
@ -22,7 +27,7 @@ function M.raw(typ, fmt, ...)
end
--- Write to a new file
---@param typ string as per log.types config
---@param typ LogTypes as per log.types config
---@param path string absolute path
---@param fmt string for string.format
---@param ... any arguments for string.format
@ -71,7 +76,7 @@ end
--- Write to log file
--- time and typ are prefixed and a trailing newline is added
---@param typ string as per log.types config
---@param typ LogTypes as per log.types config
---@param fmt string for string.format
---@param ... any arguments for string.format
function M.line(typ, fmt, ...)
@ -88,7 +93,7 @@ function M.set_inspect_opts(opts)
end
--- Write to log file the inspection of a node
---@param typ string as per log.types config
---@param typ LogTypes as per log.types config
---@param node Node node to be inspected
---@param fmt string for string.format
---@param ... any arguments for string.format
@ -99,20 +104,20 @@ function M.node(typ, node, fmt, ...)
end
--- Logging is enabled for typ or all
---@param typ string as per log.types config
---@param typ LogTypes as per log.types config
---@return boolean
function M.enabled(typ)
return M.path ~= nil and (M.config.types[typ] or M.config.types.all)
return file_path ~= nil and (types[typ] or types.all)
end
function M.setup(opts)
M.config = opts.log
if M.config and M.config.enable and M.config.types then
M.path = string.format("%s/nvim-tree.log", vim.fn.stdpath("log"), os.date("%H:%M:%S"), vim.env.USER)
if M.config.truncate then
os.remove(M.path)
if opts.log and opts.log.enable and opts.log.types then
types = opts.log.types
file_path = string.format("%s/nvim-tree.log", vim.fn.stdpath("log"), os.date("%H:%M:%S"), vim.env.USER)
if opts.log.truncate then
os.remove(file_path)
end
require("nvim-tree.notify").debug("nvim-tree.lua logging to " .. M.path)
require("nvim-tree.notify").debug("nvim-tree.lua logging to " .. file_path)
end
end