rcarriga / nvim-notify

A fancy, configurable, notification manager for NeoVim
MIT License
3k stars 80 forks source link

Bug Report: attempt to index local config (a nil value) #107

Closed zhang-stephen closed 2 years ago

zhang-stephen commented 2 years ago

I met this issue when I try LSP status sample given in wiki.

environment:

configuration for nvim-notify:

function()
    local notify = require('notify')
    local notify_renderers = require('notify.render')

    notify.setup({
        stages = 'slide',
        timeout = 2000, -- 2.0s
        background_color = 'Normal',
        render = function(bufnr, notif, highlights)
            if notif.title[1] == '' then
                return notify_renderers.minimal(bufnr, notif, highlights)
            else
                return notify_renderers.default(bufnr, notif, highlights)
            end
        end,
    })

    vim.notify = notify
end

LSP status code($/progress method):

vim.lsp.handlers["$/progress"] = function(_, result, ctx)
    local client_id = ctx.client_id
    local val = result.value

    if not val.kind then
        return
    end

    local notif_data = get_notif_data(client_id, result.token)

    if val.kind == "begin" then
        local message = format_message(val.message, val.percentage)

        -- ERROR here!!!
        notif_data.notification = vim.notify(message, "info", {
            title = format_title(val.title, vim.lsp.get_client_by_id(client_id).name),
            icon = spinner_frames[1],
            timeout = false,
            hide_from_history = false,
        })

        notif_data.spinner = 1
        update_spinner(client_id, result.token)
    elseif val.kind == "report" and notif_data then
        notif_data.notification = vim.notify(format_message(val.message, val.percentage), "info", {
            replace = notif_data.notification,
            hide_from_history = false,
        })
    elseif val.kind == "end" and notif_data then
        notif_data.notification = vim.notify(val.message and format_message(val.message) or "Complete", "info", {
            icon = "",
            replace = notif_data.notification,
            timeout = 3000,
        })

        notif_data.spinner = nil
    end
end

screenshot: image

and when I ran :Telescope notify, I have met similar error as #102.

what happened in my configuration?

rcarriga commented 2 years ago

The render function now takes a fourth argument so you need to pass that as well You can do

render = function(bufnr, notif, ...)
  if notif.title[1] == "" then
    return notify_renderers.minimal(bufnr, notif, ...)
  else
    return notify_renderers.default(bufnr, notif, ...)
  end
end
zhang-stephen commented 2 years ago

OK, it works fine, thank you.