Closed dedukun closed 7 months ago
This is a bit off topic, but in the example that I gave I'm using print
in the setup
function instead of ya.err
because init.lua
is executed before the logs are initialized.
Do you want me to make a PR to fix this?
Thank you for the report, this is a known issue, and I am still considering how to address it.
You can use state("your-plugin-name")
as a workaround for now:
return {
setup = function(self, opts)
local st = state("your-plugin-name")
st.foo = "bar"
end
}
Needs https://github.com/sxyazi/yazi/commit/0cb572a83787a88c8e6ef30aec148d509902a659
This is a bit off topic, but in the example that I gave I'm using
setup
function instead ofya.err
becauseinit.lua
is executed before the logs are initialized.Do you want me to make a PR to fix this?
Yeah, please raise a PR for it!
Thank you for the report, this is a known issue, and I am still considering how to address it.
You can use
state("your-plugin-name")
as a workaround for now:return { setup = function(self, opts) local st = state("your-plugin-name") st.foo = "bar" end }
Needs 0cb572a
Cool, thanks for the quick workaround, I'll use it in the mean time.
Hi, I made a PR trying to fix it, https://github.com/sxyazi/yazi/pull/710, let me know if it works for you!
I'm going to lock this issue because it has been closed for 30 days. ⏳ This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
What system are you running Yazi on?
Linux Wayland
What terminal are you running Yazi in?
wezterm 20240123-102946-02bdd7ed
Yazi version
yazi 0.2.3 (8efafd6 2024-02-19)
Did you try the latest main branch to see if the problem got fixed?
Tried, but the problem still
Describe the bug
Yazi panics when trying to access the
state
variable inside asetup
function as demonstrated in https://yazi-rs.github.io/docs/plugins/overview#sync-vs-async.Expected Behavior
It should be possible to set variables in the
state
so that the plugins can have custom configurations.To Reproduce
I've created a new branch in bookmarks.yazi which has a simple
setup
function that tries to set a table in thestate
variable.To recreate the issue, simply call the
setup
method ininit.lua
Configuration
No response
Anything else?
I've looked a bit into the lua API and I think that the issue is because the
require
just runs the lua code without the context ofYAZI_PLUGIN_NAME
.A possible solution might be to have a custom
require
that does something similar to entry.