luukvbaal / statuscol.nvim

Status column plugin that provides a configurable 'statuscolumn' and click handlers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Attempt to index field wtext

petobens opened this issue · comments

Consider the following minimal init.lua file:

local root = '/tmp/nvim-minimal'

-- Set stdpaths to use root dir
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',
        '--single-branch',
        'https://github.com/folke/lazy.nvim.git',
        lazypath,
    })
end
vim.opt.runtimepath:prepend(lazypath)

-- Options
vim.opt.number = true
vim.opt.signcolumn = 'number'
vim.diagnostic.config({ signs = true })

-- Plugins
local plugins = {
    {
        'mfussenegger/nvim-lint',
        config = function()
            local lint = require('lint')
            vim.api.nvim_create_autocmd(
                { 'BufEnter', 'BufWritePost', 'TextChanged', 'InsertLeave' },
                {
                    group = vim.api.nvim_create_augroup('nvim_lint', { clear = true }),
                    callback = function()
                        vim.defer_fn(function()
                            lint.try_lint(nil, { ignore_errors = true })
                        end, 1)
                    end,
                }
            )
            lint.linters_by_ft = {
                python = { 'ruff' },
            }
        end,
    },
    {
        'luukvbaal/statuscol.nvim',
        branch = '0.10',
        config = function()
            local builtin = require('statuscol.builtin')
            require('statuscol').setup({
                relculright = true,
                segments = {
                    {
                        sign = {
                            name = { 'Diagnostic' },
                            maxwidth = 1,
                            auto = true,
                        },
                    },
                    {
                        text = {
                            builtin.lnumfunc,
                            ' ',
                        },
                    },
                },
            })
        end,
    },
}
require('lazy').setup(plugins, {
    root = root .. '/plugins',
})

Now, as in the GIF,

  1. Open nvim with this file
  2. Open a foo.py file with """Foo."""
  3. Erase one of the leading quotes

After 3. I get

E5108: Error executing lua /tmp/nvim-minimal/plugins/statuscol.nvim/lua/statuscol.lua:63: attempt to index field 'wtext' (a nil value)
stack traceback:
        /tmp/nvim-minimal/plugins/statuscol.nvim/lua/statuscol.lua:63: in function 'sign_assign_segment'
        /tmp/nvim-minimal/plugins/statuscol.nvim/lua/statuscol.lua:90: in function 'sign_cache_add'
        /tmp/nvim-minimal/plugins/statuscol.nvim/lua/statuscol.lua:172: in function 'place_signs'
        /tmp/nvim-minimal/plugins/statuscol.nvim/lua/statuscol.lua:218: in function 'update_callargs'
        /tmp/nvim-minimal/plugins/statuscol.nvim/lua/statuscol.lua:253: in function </tmp/nvim-minimal/plugins/statuscol.nvim/lua/statuscol.lua:231>

stat

Thanks, the bug was unbeknownst to me but I had already fixed it in a refactor commit locally. I'll push it soon.

The error did indeed go away but I have one minor thing. One the following config:

local builtin = require('statuscol.builtin')

require('statuscol').setup({
    ft_ignore = { 'NvimTree' },
    relculright = true,
    segments = {
        {
            sign = {
                name = { 'Diagnostic' },
                maxwidth = 1,
                auto = true,
            },
        },
        {
            sign = {
                namespace = { 'gitsign' },
                auto = true,
            },
        },
        {
            text = {
                function()
                    return '%='
                end,
                builtin.foldfunc,
            },
            click = 'v:lua.ScFa',
            auto = true,
        },
        {
            text = {
                function(args)
                    return (args.relnum == 0) and ' ' or ''
                end,
            },
        },
        {
            text = {
                builtin.lnumfunc,
                ' ',
            },
        },
    },
})

I want to have both line numbers and diagnostics signs displayed at the same time. However as it can bee seen in the image below this is not the case (in the foo.py file on the right only the Info diagnostic sign is displayed). Do I need to change my config?

Screenshot_2023-12-17_16:09:43

This should only happen if you have set 'signcolumn' to "number". If that's not the issue, I'll check it out later.

Hi! Thanks for the quick reply. I have indeed set sign column to number. I tried setting it to auto but then the diagnostics sign is not shown at all.

This plugin will set 'signcolumn' to "no" (unless it is set to "number"), so there is no need to set it to anything in your config. Your diagnostic signs are probably not showing up because on the latest nightly, diagnostic signs were moved from the legacy sign api to the extmark api. You now need a sign = { namespace = "diagnostic" } segment.

That made the trick. Thanks!