f-person / git-blame.nvim

Git Blame plugin for Neovim written in Lua
GNU General Public License v3.0
839 stars 41 forks source link

init error when update to a36b2 #100

Closed wangxuw closed 9 months ago

wangxuw commented 9 months ago

The latest commit adds init.lua:308 and this error encountered.

I am not familiar with lua, but I wonder if this error is related to the '#'?

f-person commented 9 months ago

What Neovim version are you on? nvim_get_hl was introduced in 0.9

f-person commented 9 months ago

Should we implement backward compatibility or mention the minimum version in README instead? @dhananjaylatkar any thoughts on this?

dhananjaylatkar commented 9 months ago

0.8.0 was released one year ago (Sept 2022). Any reason people are not upgrading?

If this is the only thing not compatible with 0.8.0 then it makes sense to change it.

dhananjaylatkar commented 9 months ago

There are 2 ways I can see -

  1. Don't check if group is set or not. i.e do nvim_set_hl() all the time. Con: Too many calls to nvim_set_set()
  2. Set hl group in plugin/gitblame.vim and then overwrite it in require("gitblame").setup(). This will give priority to lua config which should be okay since people won't be doing config using vimscript and lua.
dhananjaylatkar commented 9 months ago

2nd option is not working. Overwrite is not happening.

We can go with 1 or following workaround -

diff --git a/lua/gitblame/init.lua b/lua/gitblame/init.lua
index c73e8a4..a6ed38d 100644
--- a/lua/gitblame/init.lua
+++ b/lua/gitblame/init.lua
@@ -305,14 +305,10 @@ local function update_blame_text(blame_text)

     local should_display_virtual_text = vim.g.gitblame_display_virtual_text == 1

-    if #vim.api.nvim_get_hl(0, { name = "gitblame" }) == 0 then
-        vim.api.nvim_set_hl(0, "gitblame", { link = vim.g.gitblame_highlight_group })
-    end
-
     if should_display_virtual_text then
         local options = {
             id = 1,
-            virt_text = { { blame_text, "gitblame" } },
+            virt_text = { { blame_text, vim.g.gitblame_highlight_group } },
             virt_text_win_col = virt_text_column,
         }
         local user_options = vim.g.gitblame_set_extmark_options or {}
f-person commented 9 months ago

@dhananjaylatkar I actually like this 🤔 Let me use that instead