rebelot/heirline.nvim

Document updating component upon user events

Opened this issue · 2 comments

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! 😎

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.

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! :)