Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional component is not evaluated #168

Open
Subjective opened this issue Sep 12, 2023 · 0 comments
Open

Conditional component is not evaluated #168

Subjective opened this issue Sep 12, 2023 · 0 comments

Comments

@Subjective
Copy link

This is a somewhat trivial issue, I was just curious as to why the two seemingly equivalent components below don't behave the same.

They both display the grapple tag number of a file if it exists, but only the first one behaves as I would expect (see below demo for more info). The only difference between the two is that in the 1st one the condition require("grapple").exists() is checked directly inside the provider function, while in the 2nd one the condition is provided as a table entry. I'm not sure why this would cause them to behave differently.

-- 1
Grapple = {
  provider = function()
    -- condition check done inside provider
    if require("grapple").exists() then return string.format(" %s ", require("grapple").key()) end
  end,
  update = { "User", pattern = "GrappleStateUpdate", callback = vim.schedule_wrap(function() vim.cmd.redrawstatus() end) },
  init = require("astronvim.utils.status.init").update_events { "BufEnter" },
}
-- 2
Grapple = {
  provider = function() return string.format(" %s ", require("grapple").key()) end,
  -- condition provided to table
  condition = require("grapple").exists,
  update = { "User", pattern = "GrappleStateUpdate", callback = vim.schedule_wrap(function() vim.cmd.redrawstatus() end) },
  init = require("astronvim.utils.status.init").update_events { "BufEnter" },
}

Demo
Below is a simple test for the 2nd component, which for some reason doesn't display the Grapple tag initially when toggled even though the condition is met and the update autocmd event is emitted. After some time (usually when I toggle the tag while other components in the statusline are updating), the component finally shows and updates as I would expect it to do when toggling a tag. (btw, this happens when I first start neovim, after the component finally shows, the issue disappears completely)

Test Autocmd
vim.api.nvim_create_autocmd({ "User" }, {
  pattern = "GrappleStateUpdate",
  callback = function()
    local exists = require("grapple").exists()
    local key = require("grapple").key()
    print(string.format("exists: %s, tag #: %s", exists, key))
  end,
})

Screen Recording 2023-09-11 at 7 54 42 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant