freddiehaddad / feline.nvim

A minimal, stylish and customizable statusline, statuscolumn, and winbar for Neovim
GNU General Public License v3.0
310 stars 10 forks source link

bug: error "(UNKNOWN PLUGIN): Error executing lua: attempt to call a number value" is shown in screen #46

Closed tummetott closed 11 months ago

tummetott commented 11 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.9.4 Build type: Release LuaJIT 2.1.1696795921

Operating system/version

MacOs 13.4.1

Describe the bug

I've encountered a peculiar bug that's a bit challenging to articulate. Essentially, an error message appears at the top of the screen. While this error doesn't impede the functionality of Neovim, its presence can be somewhat bothersome. Reproducing the error is possible in various scenarios, but it consistently involves the usage of feline.

Initially, I suspected catppuccin was the root cause and opened an issue there: link to the issue. However, upon further investigation, I discovered that the error also manifests with a minimal config containing feline, treesitter.

The error itself is truncated so basically no information is shown:

image

Steps To Reproduce

  1. nvim --clean -u repro.lua
  2. :qa<cr>
  3. nvim --clean -u repro.lua newfile.lua
  4. Type a non existing cmd, e.g.: :lkdjflkdjf<cr>

-- > Error is shown

Expected Behavior

No error

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
    vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath })
end
vim.opt.runtimepath:prepend(lazypath)

-- termguicolors must be enabled for feline
vim.opt.termguicolors = true

-- This is needed for reproduction of the error
vim.opt.foldmethod = 'expr'

-- install plugins
local plugins = {
    {
        'freddiehaddad/feline.nvim',
        config = function()
            require('feline').setup()
        end,
    },
    {
        'nvim-treesitter/nvim-treesitter',
        config = function()
            require('nvim-treesitter.configs').setup {
                highlight = { enable = true },
                ensure_installed = { 'lua' },
            }
        end,
    }
}
require 'lazy'.setup(plugins, {
    root = root .. '/plugins',
})
tummetott commented 11 months ago

I looked into the issue by removing different parts of Feline step by step. I found that the problem is caused by the lsp/provider module, specifically when using one of the built-in providers diagnostic_errors, diagnostic_warnings, diagnostic_hints, or diagnostic_info.

so the setup() call of the minimal config can be refined to:

require('feline').setup {
    components = {
        active = { { {
            provider = 'diagnostic_errors',
        } } }
    }
}
tummetott commented 11 months ago

I proceeded by investigating the issue further. In doing so, I modified the feline/providers/lsp.lua file. Initially, I removed all content and replaced it with a stub function to return dummy values. Surprisingly, the error disappeared. However, when I added an apparently unrelated line back in:

local M = {}

-- This unused handle creates the error
local lsp = vim.lsp

function M.diagnostic_errors()
    return 'text', 'icon'
end

return M

The error reappeared. I'm puzzled by this behavior and unsure why it occurs.

tummetott commented 11 months ago

While troubleshooting the problem, I found a temporary fix by loading the feline.providers.lsp module explicitly before setting up feline:

require('feline.providers.lsp')
require('feline).setup( ... )

This made the error disappear. However, I'm determined to uncover the exact cause of the issue. It's puzzling that plugins like treesitter or catppuccin somehow contribute to triggering this error. My goal is to find a more solid and cleaner solution, avoiding the need for such a workaround.

(I split this issue into four parts to show how I traced the bug step by step. It took over a day to simplify my Neovim config and find the problem. This breakdown should help explain the process.)

freddiehaddad commented 11 months ago

Hello, thanks for reporting the issue: Can you try these minimal configs?

I'm not seeing the error with just feline. Want to make sure you're not as well.

NOTICE I'm enabling termguicolors (you will see an error w/o this)

Default Setup

for name, url in pairs({
    feline = "https://github.com/freddiehaddad/feline.nvim",
}) do
    local install_path = vim.fn.fnamemodify("nvim_issue/" .. name, ":p")
    if vim.fn.isdirectory(install_path) == 0 then
        vim.fn.system({ "git", "clone", "--depth=1", url, install_path })
    end
    vim.opt.runtimepath:append(install_path)
end

vim.opt.termguicolors = true
require("feline").setup()

Custom Setup

for name, url in pairs({
    feline = "https://github.com/freddiehaddad/feline.nvim",
}) do
    local install_path = vim.fn.fnamemodify("nvim_issue/" .. name, ":p")
    if vim.fn.isdirectory(install_path) == 0 then
        vim.fn.system({ "git", "clone", "--depth=1", url, install_path })
    end
    vim.opt.runtimepath:append(install_path)
end

vim.opt.termguicolors = true
require("feline").setup({
    components = {
        active = {
            { -- left
                { provider = "diagnostic_errors", },
            },
        },
    },
})
freddiehaddad commented 11 months ago

I proceeded by investigating the issue further. In doing so, I modified the feline/providers/lsp.lua file. Initially, I removed all content and replaced it with a stub function to return dummy values. Surprisingly, the error disappeared. However, when I added an apparently unrelated line back in:

local M = {}

-- This unused handle creates the error
local lsp = vim.lsp

function M.diagnostic_errors()
    return 'text', 'icon'
end

return M

The error reappeared. I'm puzzled by this behavior and unsure why it occurs.

This might be related to missing nvim-web-devicons plugin.

freddiehaddad commented 11 months ago

While troubleshooting the problem, I found a temporary fix by loading the feline.providers.lsp module explicitly before setting up feline:

require('feline.providers.lsp')
require('feline).setup( ... )

This made the error disappear. However, I'm determined to uncover the exact cause of the issue. It's puzzling that plugins like treesitter or catppuccin somehow contribute to triggering this error. My goal is to find a more solid and cleaner solution, avoiding the need for such a workaround.

(I split this issue into four parts to show how I traced the bug step by step. It took over a day to simplify my Neovim config and find the problem. This breakdown should help explain the process.)

In lsp.lua there's a reference to a deprecated function: lsp.buf_get_clients. I'm going to update that to use the replacement.

I'm not seeing how requiring that file would fix anything:

default_components.lua:

    {
        provider = 'diagnostic_errors',
        hl = { fg = 'red' },
    },
freddiehaddad commented 11 months ago

The only way I can reproduce your error is to use a minimal config and not specify an icon value in the provider:

Example:

for name, url in pairs({
    feline = "https://github.com/freddiehaddad/feline.nvim",
}) do
    local install_path = vim.fn.fnamemodify("nvim_issue/" .. name, ":p")
    if vim.fn.isdirectory(install_path) == 0 then
        vim.fn.system({ "git", "clone", "--depth=1", url, install_path })
    end
    vim.opt.runtimepath:append(install_path)
end

vim.opt.termguicolors = true
require("feline").setup({
    components = {
        active = {
            { -- left
                { provider = "file_info", icon = '' },
                { provider = "diagnostic_errors", icon = '' },
            },
        },
    },
})

If I remove the icon = '' portion, then the code attempts to load nvim-web-deviconsand the requirethrows an error. I think I'll add a helpful error message for that particular problem. But we still need to confirm this is your situation.

Waiting for response from you regarding your results with the minimal configs I shared.

tummetott commented 11 months ago

Hello, thanks for reporting the issue: Can you try these minimal configs?

I'm not seeing the error with just feline. Want to make sure you're not as well.

NOTICE I'm enabling termguicolors (you will see an error w/o this)

Default Setup

for name, url in pairs({
  feline = "https://github.com/freddiehaddad/feline.nvim",
}) do
  local install_path = vim.fn.fnamemodify("nvim_issue/" .. name, ":p")
  if vim.fn.isdirectory(install_path) == 0 then
      vim.fn.system({ "git", "clone", "--depth=1", url, install_path })
  end
  vim.opt.runtimepath:append(install_path)
end

vim.opt.termguicolors = true
require("feline").setup()

Custom Setup

for name, url in pairs({
  feline = "https://github.com/freddiehaddad/feline.nvim",
}) do
  local install_path = vim.fn.fnamemodify("nvim_issue/" .. name, ":p")
  if vim.fn.isdirectory(install_path) == 0 then
      vim.fn.system({ "git", "clone", "--depth=1", url, install_path })
  end
  vim.opt.runtimepath:append(install_path)
end

vim.opt.termguicolors = true
require("feline").setup({
  components = {
      active = {
          { -- left
              { provider = "diagnostic_errors", },
          },
      },
  },
})

No, there's no error with just Feline. I've thoroughly tested this.

(I'm also setting termguicolors in my minimal config)

tummetott commented 11 months ago

I proceeded by investigating the issue further. In doing so, I modified the feline/providers/lsp.lua file. Initially, I removed all content and replaced it with a stub function to return dummy values. Surprisingly, the error disappeared. However, when I added an apparently unrelated line back in:

local M = {}

-- This unused handle creates the error
local lsp = vim.lsp

function M.diagnostic_errors()
    return 'text', 'icon'
end

return M

The error reappeared. I'm puzzled by this behavior and unsure why it occurs.

This might be related to missing nvim-web-devicons plugin.

How can this be? I'm not calling any provider which uses icons. I'm just calling a stub method which renders the string text icon to the statusline

tummetott commented 11 months ago

While troubleshooting the problem, I found a temporary fix by loading the feline.providers.lsp module explicitly before setting up feline:

require('feline.providers.lsp')
require('feline).setup( ... )

This made the error disappear. However, I'm determined to uncover the exact cause of the issue. It's puzzling that plugins like treesitter or catppuccin somehow contribute to triggering this error. My goal is to find a more solid and cleaner solution, avoiding the need for such a workaround. (I split this issue into four parts to show how I traced the bug step by step. It took over a day to simplify my Neovim config and find the problem. This breakdown should help explain the process.)

In lsp.lua there's a reference to a deprecated function: lsp.buf_get_clients. I'm going to update that to use the replacement.

I'm not seeing how requiring that file would fix anything:

default_components.lua:

    {
        provider = 'diagnostic_errors',
        hl = { fg = 'red' },
    },

Like I said I removed everything from lsp.lua and replaced it with a stub function (dummy function) which just returns two hard coded values. there is not actuall lsp call in the file. but the error still persists when local lsp = vim.lsp is kept in the file

freddiehaddad commented 11 months ago

After looking at your original post again, I'm now wondering if your problem is this:

-- This is needed for reproduction of the error
vim.opt.foldmethod = 'expr'

See: https://github.com/neovim/neovim/issues/25608

Can you try commenting out that line? I guess you did since you explicitly say it's needed for repro.

And also try with the following:

vim.opt.foldmethod = 'expr'
-- https://github.com/neovim/neovim/issues/25608
vim.opt.foldexpr = 'nvim_treesitter#foldexpr()'

There's a regression I reported in Neovim v0.9.4. Not specific to Feline, it's a Treesitter bug and I think you're hitting that.

tummetott commented 11 months ago

After looking at your original post again, I'm now wondering if your problem is this:

-- This is needed for reproduction of the error
vim.opt.foldmethod = 'expr'

See: neovim/neovim#25608

Can you try commenting out that line?

And also try with the following:

vim.opt.foldmethod = 'expr'
-- https://github.com/neovim/neovim/issues/25608
vim.opt.foldexpr = 'nvim_treesitter#foldexpr()'

Yes you need

vim.opt.foldmethod = 'expr'

in order to reproduce the bug. When i delete that line, no error is shown. I can add

vim.opt.foldexpr = 'nvim_treesitter#foldexpr()'

but this makes not difference. the bug persists.

tummetott commented 11 months ago

can you reproduce the bug when you use my minimal config?

freddiehaddad commented 11 months ago

can you reproduce the bug when you use my minimal config?

I will try again now.

However, the only place where fold expression is used in Feline is for the statuscolumn. If you're only setting up the statusline, there's nothing in Feline that could be impacted by that setting. I'm struggling to find a correlation between that setting and Feline.

It seems more likely to be related to the Issue I shared and/or another Neovim regression.

freddiehaddad commented 11 months ago

Even with all your settings, I'm not getting the error:

for name, url in pairs({
  feline = "https://github.com/freddiehaddad/feline.nvim",
  treesitter = "https://github.com/nvim-treesitter/nvim-treesitter",
}) do
  local install_path = vim.fn.fnamemodify("nvim_issue/" .. name, ":p")
  if vim.fn.isdirectory(install_path) == 0 then
    vim.fn.system({ "git", "clone", "--depth=1", url, install_path })
  end
  vim.opt.runtimepath:append(install_path)
end

vim.opt.termguicolors = true
vim.opt.foldmethod = "expr"

require("feline").setup({
  components = {
    active = {
      { -- left
        -- { provider = "file_info", icon = "" },
        -- { provider = "diagnostic_errors", icon = "" },
        { provider = "diagnostic_errors" },
      },
    },
  },
})

require("nvim-treesitter.configs").setup({
  highlight = { enable = true },
  ensure_installed = { "lua" },
})

See the screenshot.. Opened with nvim --clean -u minimal.lua myfile.lua scrn-2023-11-18-07-59-16

freddiehaddad commented 11 months ago

I proceeded by investigating the issue further. In doing so, I modified the feline/providers/lsp.lua file. Initially, I removed all content and replaced it with a stub function to return dummy values. Surprisingly, the error disappeared. However, when I added an apparently unrelated line back in:

local M = {}

-- This unused handle creates the error
local lsp = vim.lsp

function M.diagnostic_errors()
    return 'text', 'icon'
end

return M

The error reappeared. I'm puzzled by this behavior and unsure why it occurs.

This might be related to missing nvim-web-devicons plugin.

Tried the same and am not able to repro. The local lsp = vim.lsp doesn't create any issues for me.

I'll try on a MBP (work computer) later and see if this is a Mac issue. But I use feline on my MBP now without issue. Neovim is instaled with Homebrew.

tummetott commented 11 months ago

Ok I can confirm that this issue is gone with nvim 0.10 nightly and nvim 0.9.2. So it must be an upstream issue of nvim 0.9.4. Thanks for your help.