2

When I run Neovim (NVIM v0.6.1), I get

Error detected while processing /home/ecarroll/.config/nvim/init.lua:
E5113: Error while calling lua chunk: vim.lua:63: /home/ecarroll/.config/nvim/lua/plugins.lua:81: '<eof>' expected near 'local'
stack traceback:
        [C]: in function 'error'
        vim.lua:63: in function <vim.lua:57>
        [C]: in function 'require'
        /home/ecarroll/.config/nvim/init.lua:56: in main chunk

Line 81 has this code which I basically copied from the Packer docs,

local on_attach = function(client, bufnr)
  -- Enable completion triggered by <c-x><c-o>
  vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
  
  -- Mappings.
  -- See `:help vim.lsp.*` for documentation on any of the below functions
  vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Leader>f',  '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD',         '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd',         '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K',          '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi',         '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-k>',      '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Leader>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Leader>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Leader>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Leader>D',  '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Leader>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr',         '<cmd>lua vim.lsp.buf.references()<CR>', opts)

end

How can I solve the error,

Error while calling lua chunk [...] '' expected near 'local'

1 Answer 1

3

In my case this was because I had this in my file,

return require('packer').startup(function()
  -- stuff
end)

And then after that I had

let on_attach = function(client, bufnr)
  ...
end

And that error, which leaves a lot to be desired essentially amounts to "dead code after return not allowed".


I would open an issue on Lua for a more informative error, but they're using mailing lists.

3
  • Could you please mark your question as answered if it resolves your question?
    – TornaxO7
    May 6, 2022 at 12:00
  • 1
    @TornaxO7 done, the network doesn't allow you to mark it as accepted for 2 days. Dec 24, 2022 at 4:47
  • Great! Thank you for not forgetting to do this :)
    – TornaxO7
    Dec 24, 2022 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.