nvim-lua / lsp-status.nvim

Utility functions for getting diagnostic status and progress messages from LSP servers, for use in the Neovim statusline
MIT License
625 stars 41 forks source link

Error executing vim.schedule lua callback #9

Closed Shatur closed 4 years ago

Shatur commented 4 years ago

Thank you for the awesome plugin! It works for me, but I have weird error in echo area:

Error executing vim.schedule lua callback: ...im/pack/plugins/start/lsp-status.nvim/lua/lsp-status.lua:77: attempt to index local 'client' (a nil value)

Here is my configuration:

local nvim_lsp = require'nvim_lsp'
local lsp_status = require'lsp-status'
lsp_status.register_progress()

local apply_settings = function()
  -- Some my shortcuts here
end

nvim_lsp.clangd.setup{
    cmd = {'clangd', '--header-insertion=never', '--suggest-missing-includes', '--background-index', '-j=8', '--cross-file-rename', '--pch-storage=memory', '--clang-tidy', '--clang-tidy-checks=-clang-analyzer-*,bugprone-*,misc-*,-misc-non-private-member-variables-in-classes,performance-*,-performance-no-automatic-move,modernize-use-*,-modernize-use-nodiscard,-modernize-use-trailing-return-type'},
    on_attach = function()
        apply_settings()
        lsp_status.on_attach()
        vim.api.nvim_buf_set_keymap(0, 'n', 'gs', '<Cmd>ClangdSwitchSourceHeader<CR>', {noremap=true, silent=true})
    end,
    on_init = require'clangd_nvim'.on_init,
    callbacks = lsp_status.extensions.clangd.setup(),
    capabilities = {
        capabilities = {
            window = {
                workDoneProgress = true
            }
        },
        textDocument = {
            completion = {
                completionItem = {
                    snippetSupport = true
                }
            },
            semanticHighlightingCapabilities = {
                semanticHighlighting = true
            }
        }
    },
    init_options = {
        clangdFileStatus = true,
        usePlaceholders = true,
        completeUnimported = true
    }
}
Shatur commented 4 years ago

Sorry, I missed than lsp_status.on_attach() requires client parameter:

on_attach = function(client)
    apply_settings()
    lsp_status.on_attach(client)
    vim.api.nvim_buf_set_keymap(0, 'n', 'gs', '<Cmd>ClangdSwitchSourceHeader<CR>', {noremap=true, silent=true})
end
wbthomason commented 4 years ago

Glad to hear you figured it out! If you have suggestions for improvements to the docs to make that more clear, I'd welcome them.

koopa1338 commented 3 years ago

I have a similar issue:

Error executing vim.schedule lua callback: ...ack/packer/start/lsp-status.nvim/lua/lsp-status/util.lua:62: table index is nil

this is my setup:

local nvim_status = require("lsp-status")

local status = {}

status.select_symbol = function(cursor_pos, symbol)
    if symbol.valueRange then
        local value_range = {
            ["start"] = {
                character = 0,
                line = vim.fn.byte2line(symbol.valueRange[1]),
            },
            ["end"] = {
                character = 0,
                line = vim.fn.byte2line(symbol.valueRange[2]),
            },
        }

        return require("lsp-status.util").in_range(cursor_pos, value_range)
    end
end

status.activate = function()
    nvim_status.register_progress()
    nvim_status.config {
        select_symbol = status.select_symbol
    }
end

status.on_attach = function(client)
    nvim_status.on_attach(client)

    vim.cmd [[augroup dev_lsp_status]]
    vim.cmd [[  autocmd CursorHold,BufEnter <buffer> lua require('lsp-status').update_current_function()]]
    vim.cmd [[augroup END]]
end

return status

And here the usage in my lsp configuration:


local nvim_lsp = require('lspconfig')
local status = require("_lsp_status")

status.activate()

-- lsp config
local opts = {silent = true}
local custom_attach = function(client)

    status.on_attach(client)

    -- lsp keymaps below here

end
wbthomason commented 3 years ago

Hi @koopa1338: Please open a new issue for your bug, which appears to be distinct from the original issue in this thread.