3

I have searched for a solution but nothing I have found worked.

I have lazy.nvim as plugin manager.

I installed the following plugins

return { "mason-org/mason-lspconfig.nvim", opts = {}, dependencies = { { "mason-org/mason.nvim", opts = {} }, "neovim/nvim-lspconfig", }, } 

Then, in my after folder, I created a lua file that contains the following setup

require("mason-lspconfig").setup({ ensure_installed = { "lua_ls", "ts_ls", "rust_analyzer", }, handlers = { function(server_name, test) ■ Unused local `test`. local capabilities = require('cmp_nvim_lsp').default_capabilities() require('lspconfig')[server_name].setup { capabilities = capabilities, } end, ["lua_ls"] = function() local lspconfig = require("lspconfig") local capabilities = require('cmp_nvim_lsp').default_capabilities() lspconfig.lua_ls.setup { capabilities = capabilities, settings = { Lua = { workspace = { checkThirdParty = false, library = vim.api.nvim_get_runtime_file("", true) }, ■ Undefined global `vim`. runtime = { version = 'LuaJIT' }, telemetry = { enable = false }, diagnostics = { globals = { "vim" }, }, }, }, } end, } }) vim.diagnostic.config({ ■ Undefined global `vim`. virtual_text = true, signs = false, underline = false, update_in_insert = false, severity_sort = true, }) 

(Ignore the test variable, I created it to see if diagnostic worked)

My problem is that I cannot get rid of the Undefined global `vim` warning.

1
  • In nvim v0.11+, the config for LSP changed slightly. Here is a link to help with an example configuration you can use: neovim.io/doc/user/lsp.html#_quickstart Commented Jun 19 at 19:06

1 Answer 1

10

I believe you are following old guides. It's simpler with neovim v0.11. You can now configure language servers using the builtin vim.lsp.config interface. Minimal example below:

vim.lsp.config("lua_ls", { settings = { Lua = { diagnostics = { globals = { "vim" }}}}}) 

I believe you have tried to do something similar in your code, and you can probably reuse everything you have in your Luatable as well. But most of the surrounding boilerplate is unnecessary with v.0.11, and it would probably be preferable to find up-to-date info about how to configure lsp for v.0.11 instead of reading old guides that do lots of complicated wizardry.

Sign up to request clarification or add additional context in comments.

2 Comments

According to documentation, you might also consider adding vim.lsp.enable('lua_ls') to enable the configuration.
user has mason-lspconfig plugin so it is done by the plugin and not need to enable it

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.