Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: neodev not working with mason-lspconfig #180

Open
3 tasks done
ej-shafran opened this issue Jan 30, 2024 · 7 comments
Open
3 tasks done

bug: neodev not working with mason-lspconfig #180

ej-shafran opened this issue Jan 30, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@ej-shafran
Copy link

Did you check docs and existing issues?

  • I have read all the neodev.nvim docs
  • I have searched the existing issues of neodev.nvim
  • 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 ej-shafran added the bug Something isn't working label Jan 30, 2024
@ej-shafran ej-shafran changed the title bug: bug: neodev not working with mason-lspconfig Jan 30, 2024
@refarb
Copy link

refarb commented Jan 31, 2024

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.

@xzbdmw
Copy link

xzbdmw commented Jan 31, 2024

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:)

@refarb
Copy link

refarb commented Jan 31, 2024

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.

@natemaia
Copy link

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

@maciejzj
Copy link

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.

@Rimann91
Copy link

Rimann91 commented May 7, 2024

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

@daniele821
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants