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

Document updating component upon user events #179

Open
gbroques opened this issue Dec 21, 2023 · 2 comments
Open

Document updating component upon user events #179

gbroques opened this issue Dec 21, 2023 · 2 comments

Comments

@gbroques
Copy link

gbroques commented Dec 21, 2023

As a beginner new to Neovim autocommands, configuring heirline.nvim with a plugin that requires updatin a component upon a user event was a challenge.

For example, I created an LspMessages component with heirline.nvim that relies on linrongbin16/lsp-progress.nvim for the provider and needs to be updated when the LspProgressStatusUpdated user event is emitted:

local LspMessages = {
  provider = require('lsp-progress').progress,
  update = {
    'User',
    pattern = 'LspProgressStatusUpdated',
    callback = vim.schedule_wrap(function()
      vim.cmd('redrawstatus')
    end),
  }
}

The only example of update with a pattern in the cookbook is a builtin event for refreshing a cmoponent when the mode changes:

update = {
    "ModeChanged",
    pattern = "*:*",
    callback = vim.schedule_wrap(function()
        vim.cmd("redrawstatus")
    end),
},

The mistake I made was extrapolating the builtin event example for the user event:

local LspMessages = {
  provider = require('lsp-progress').progress,
  update = {
    'LspProgressStatusUpdated', -- ❌ Needs to be 'User'
    pattern = '*:*', -- ❌ Needs to be 'LspProgressStatusUpdated'
    callback = vim.schedule_wrap(function()
      vim.cmd('redrawstatus')
    end),
  }
}

The error you get with the above is "Invalid 'event': 'LspProgressStatusUpdated'".

I'm sure those more familiar with autocommands in Neovim wouldn't make this mistake, but for beginners an example for user events might be helpful!


Thank you again. heirline.nvim is very cool for building a customized statusline! 😎

@gbroques gbroques changed the title Add example or mention how to update component for user events Document how to update component for user events Dec 21, 2023
@gbroques gbroques changed the title Document how to update component for user events Document updating component for user events Dec 21, 2023
@gbroques gbroques changed the title Document updating component for user events Document updating component upon user events Dec 21, 2023
@linrongbin16
Copy link

linrongbin16 commented Jan 4, 2024

hi @gbroques, also please pay attention that default 'lsp-progress' will handle the escaping of '%' char, e.g. double the '%'.

see: https://github.com/linrongbin16/lsp-progress.nvim/blob/cabf7fde50cc0dad367a03a1542d9670d1118bd0/lua/lsp-progress/defaults.lua#L83

and: https://github.com/linrongbin16/lsp-progress.nvim/blob/cabf7fde50cc0dad367a03a1542d9670d1118bd0/lua/lsp-progress/defaults.lua#L88

these two lines will transfer '%' to '%%'. also see related discuss why I am doing it: linrongbin16/lsp-progress.nvim#98

heirline could have different behavior from lualine.

also it's super welcome if you could submit PR to give people a sample, share how you integrate lsp-progress with heirline.

@gbroques
Copy link
Author

gbroques commented Jan 5, 2024

hi @gbroques, also please pay attention that default 'lsp-progress' will handle the escaping of '%' char, e.g. double the '%'.

see: https://github.com/linrongbin16/lsp-progress.nvim/blob/cabf7fde50cc0dad367a03a1542d9670d1118bd0/lua/lsp-progress/defaults.lua#L83

and: https://github.com/linrongbin16/lsp-progress.nvim/blob/cabf7fde50cc0dad367a03a1542d9670d1118bd0/lua/lsp-progress/defaults.lua#L88

these two lines will transfer '%' to '%%'. also see related discuss why I am doing it: linrongbin16/lsp-progress.nvim#98

heirline could have different behavior from lualine.

Thank you for note about the % escaping behavior!

also it's super welcome if you could submit PR to give people a sample, share how you integrate lsp-progress with heirline.

Sure! I'll consider submitting a PR for that then. Thanks again! :)

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

2 participants