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.
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 Lua
table 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.