Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error executing vim.schedule lua callback #9

Closed
Shatur opened this issue Jul 3, 2020 · 4 comments
Closed

Error executing vim.schedule lua callback #9

Shatur opened this issue Jul 3, 2020 · 4 comments

Comments

@Shatur
Copy link
Contributor

Shatur commented Jul 3, 2020

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
Copy link
Contributor Author

Shatur commented Jul 3, 2020

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

@Shatur Shatur closed this as completed Jul 3, 2020
@wbthomason
Copy link
Collaborator

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
Copy link

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants