neodev.nvim icon indicating copy to clipboard operation
neodev.nvim copied to clipboard

bug: neodev not working with mason-lspconfig

Open ej-shafran opened this issue 1 year ago • 7 comments

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

  1. Copy the repro below into ~/.config/nvim/repro.lua
  2. Run nvim -u ~/.config/nvim/repro.lua ~/.config/nvim/repro.lua
  3. Wait for Lazy to finish installing the plugins
  4. Wait for Mason to finish installing lua-language-server (use :Mason to see the progress)
  5. Close Neovim
  6. Do step 5 again
  7. Enter insert mode
  8. Exit insert mode
  9. 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 {}

ej-shafran avatar Jan 30 '24 21:01 ej-shafran

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.

refarb avatar Jan 31 '24 13:01 refarb

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.

Could you share how to set Luajit:)

xzbdmw avatar Jan 31 '24 19:01 xzbdmw

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.

refarb avatar Jan 31 '24 20:01 refarb

I've had the same issue recently and the above .luarc.json worked perfectly.

natemaia avatar Feb 10 '24 18:02 natemaia

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.

maciejzj avatar Mar 12 '24 09:03 maciejzj

I have this exact issue, however the .luarc.json doesnt seem to be making a difference

Rimann91 avatar May 07 '24 04:05 Rimann91

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

daniele821 avatar May 19 '24 22:05 daniele821

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.

dg1234uk avatar May 27 '24 18:05 dg1234uk