neodev.nvim
neodev.nvim copied to clipboard
bug: neodev not working with mason-lspconfig
Did you check docs and existing issues?
- [X] I have read all the neodev.nvim docs
- [X] I have searched the existing issues of neodev.nvim
- [X] I have searched the existing issues of plugins related to this issue
Neovim version (nvim -v)
NVIM v0.9.5
Operating system/version
macOS 14
Describe the bug
I cannot seem to get neodev
working in my config directory, even with a super minimal config that installs lua_ls
with mason-lspconfig
... I get Undefined global "vim"
warnings whenever I try to use the vim
object...
Steps To Reproduce
- Copy the repro below into
~/.config/nvim/repro.lua
- Run
nvim -u ~/.config/nvim/repro.lua ~/.config/nvim/repro.lua
- Wait for Lazy to finish installing the plugins
- Wait for Mason to finish installing
lua-language-server
(use:Mason
to see the progress) - Close Neovim
- Do step 5 again
- Enter insert mode
- Exit insert mode
- See warnings...
Expected Behavior
This simple config to work with Neodev.
Repro
-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")
-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end
-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)
-- install plugins
local plugins = {
"folke/tokyonight.nvim",
"folke/neodev.nvim",
"neovim/nvim-lspconfig",
"williamboman/mason-lspconfig.nvim",
"williamboman/mason.nvim",
}
require("lazy").setup(plugins, {
root = root .. "/plugins",
})
vim.cmd.colorscheme("tokyonight")
require("mason").setup()
require("mason-lspconfig").setup {
ensure_installed = { "lua_ls" }
}
require("neodev").setup()
require("lspconfig").lua_ls.setup {}
I also recently (aka up until just now) had the same/a similar problem.
In my case the lua language server incorrectly set the project root to / which obviously disables neodev as that is not a neovim config directory.
Creating a barebones .luarc.json
with only the schema (from the lua language server docs) and lua runtime version set to LuaJIT
seems to have fixed my problem.
I also recently (aka up until just now) had the same/a similar problem. In my case the lua language server incorrectly set the project root to / which obviously disables neodev as that is not a neovim config directory. Creating a barebones
.luarc.json
with only the schema (from the lua language server docs) and lua runtime version set toLuaJIT
seems to have fixed my problem.
Could you share how to set Luajit
:)
Sure! All I put into the .luarc.json
file sitting next to my init.lua
was this:
{
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
"runtime.version": "LuaJIT"
}
The "$schema"
came from the official lua language server documentation regarding the config files and the runtime.version
key came from the same page while the value was my best guess at how the server likely stored/referred to the LuaJIT runtime.
I've had the same issue recently and the above .luarc.json
worked perfectly.
Using .luarc.json
does work; however, this issue is even more troublesome when using a symlinked init.lua
(e.g., in a setup where I store my config files in a Git repo and symlink them).
Previously, I managed to make neodev work in a symlinked setup with this trick:
require("neodev").setup({
override = function(root_dir, library)
-- Path-based override activation helps neodev work with symlinked dotfiles setup
if root_dir:find("nvim") or root_dir:find("dotfiles") then
library.enabled = true
library.plugins = true
library.types = true
library.runtime = true
end
end
})
Now, when .luarc.json
has come into play, I cannot make it work, neither when it is placed alongside the symlink inside .config/neovim/init.lua
, nor in my dotfiles repo beside the actual config file.
Has anyone overcome this issue? The best would be to fix this problem altogether and revert to how it used to be when we did not need to provide an extra .luarc.json
with mason config.
I have this exact issue, however the .luarc.json doesnt seem to be making a difference
for me neodev works only if i specify it as a dependency for lspconfig, mason, and mason-lsp
"neovim/nvim-lspconfig",
dependencies = {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
{ "folke/neodev.nvim", opts = {} },
},
if i do anything else, for some reason neodev does not work.
If you want, give it a try
It started working for me after I put neodev.nvim
as a dependency of nvim-lspconfig
and then trigged nvim-lspconfig
on LspAttach
.
However, I subsequently installed the luacheck
linter with Mason and integrated into NeoVim with nvim-lint
which brought the accessing undefined variable 'vim'
back.