nvimdev / galaxyline.nvim

neovim statusline plugin written in lua
MIT License
867 stars 113 forks source link

Error: luaeval Invalid expression on component GitBranch when opening help in neovim #141

Closed mnabila closed 3 years ago

mnabila commented 3 years ago

Everytime i open help from plugins with.git folder, i got this error from galaxyline

...ite/pack/packer/start/galaxyline.nvim/lua/galaxyline.lua:33: bad argument #2 to 'cmd' (no value)
E15: Invalid expression: luaeval('require("galaxyline").component_decorator')("GitBranch")

idk how to fix this, but i think from helper galaxyline.provider_vcs.get_git_branch got empty result. I was try change provider from default provider (provider='GitBranch') in my configuration but its still not working, in some file i got empty result. but if i use example galaxyline theme(evilline) this problem is gone.

this part of my configuration for git sections

....
    {
        GitBranch = {
            provider = function() return string.format('%s ', vcs.get_git_branch()) end,
            condition = function() return condition.check_git_workspace() and condition.hide_in_width() end,
            highlight = {colors.black, colors.bblack}
        }
    },
....

and this full configuration for galaxyline galaxyline.lua

image

lakshya-sky commented 3 years ago

@mnabila did you find any workaround for the issue. I am having the same problem.

mnabila commented 3 years ago

@dash2507 sadly no :(

horseinthesky commented 3 years ago

Also happens when you don't have branches but tags.

How to reproduce:

git clone --branch v0.38.0 git@github.com:nvm-sh/nvm.git

And opening any file in the repo raises:

/home/horseinthesky/.config/nvim/lua/statusline.lua:225: attempt to concatenate a nil value
E15: Invalid expression: luaeval('require("galaxyline").component_decorator')("GitBranch")
mnabila commented 3 years ago

@dash2507 @horseinthesky

i have solutions for this issue, add function for check result from vcs.get_git_branch() to condition in GitBranch module.

why we get this error ? because vcs.get_git_branch() will return nil if galaxyline can't found .git directory

    {
        GitBranch = {
            provider = function() return string.format('%s ', vcs.get_git_branch()) end,
            condition = function()
                local function is_empty()
                    return vcs.get_git_branch() ~= nil
                end
                return condition.check_git_workspace() and condition.hide_in_width() and is_empty()
            end,
            highlight = {colors.black, colors.bblack}
        }
    },
horseinthesky commented 3 years ago

@mnabila I did a similar thing straight away:

gls.left[6] = {                            
  GitBranch = {                            
    provider = function()                  
      if in_vcs() and wide_enough(85) then 
        local branch = vcs.get_git_branch()

        if branch ~= nil then              
          return branch .. " "             
        end                                
        return ""                          
      end                                  
      return ""                            
    end,                                   
    highlight = {colors.fg2, colors.bg1}   
  }                                        
}                                          

But it is a workaround. A good solution would be to return the tag name if the branch in nil.

mnabila commented 3 years ago

A good solution would be to return the tag name if the branch in nil.

@horseinthesky but how about repository without tag and only have branch like master or main ?

horseinthesky commented 3 years ago

A good solution would be to return the tag name if the branch in nil.

@horseinthesky but how about repository without tag and only have branch like master or main ?

This is the default behavior - return branch name - master on main. If no branch then tag.

mnabila commented 3 years ago

A good solution would be to return the tag name if the branch in nil.

@horseinthesky but how about repository without tag and only have branch like master or main ?

This is the default behavior - return branch name - master on main. If no branch then tag.

+1 for this idea