feat: allow passing of format_fn to set what is logged
@PatschD, I created a draft PR to allow for passing of a format_fn.
The format_fn by default is what you have right now, which is passed as the args of the print_function:
format_fn = function(t)
return '"'
.. "file: "
.. t.filename
.. "~"
.. "line: "
.. t.line_nr
.. t.breadcrumbs
.. "~"
.. t.current_text
.. '", '
.. t.current_text
end,
But, using a custom format_fn I can get nice log messages:
use({
"/Users/dolevh/code/personal/github.com/PatschD/zippy.nvim",
config = function()
require("zippy").setup({
["typescriptreact"] = {
format_fn = function(t)
local filename = t.filename
local line_nr = t.line_nr
local breadcrumbs = t.breadcrumbs
local current_text = t.current_text
local t = '"%c[🐛 DEBUG]%c[📂 %s #%s]%c %s", "color: #9ece6a", "color: #a9b1d6", '
.. '"'
.. filename
.. '", '
.. '"'
.. line_nr
.. '", "color: white", '
.. '"'
.. current_text
.. '", '
.. current_text
print(t)
return t
end,
},
})
end,
})
Which results in:

The code is just a POC, so just wanted to pass it by you to see if this direction is good.
One can argue the right solution is to replace the print_function entirely and have it receive the args.
Let me know what you think!
P.S my lua formatter kinda muddied the PR.
hey, this looks really interesting, and in general, I am very open to merging your suggestions.
I think what would still need to be addressed:
-
at the moment, the
print_functionoption is just the language-specific print function, like console.log() for js, and print() for python. You changed it to console.log() for python, but that doesn't work. -
The current format_fn is language specific now. So we need a global default function as a fallback if no custom format function is provided. I assume that could be something like:
M.default_format_fn = function (t)
...
end
-- in M.insert_print
local format_fn = M.language_keys["options"]["format_fn"] or M.default_format_fn
Yeah sure, I'll make the changes!