fix(emmylua): configure workspace library only in neovim project

This commit is contained in:
2026-04-25 06:07:16 +02:00
parent 3fd28bc59a
commit a95d549da8
2 changed files with 34 additions and 13 deletions
+7
View File
@@ -0,0 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/EmmyLuaLs/emmylua-analyzer-rust/refs/heads/main/crates/emmylua_code_analysis/resources/schema.json",
"runtime": {
"version": "LuaJIT",
"requirePattern": ["lua/?.lua", "lua/?/init.lua"]
}
}
+27 -13
View File
@@ -1,6 +1,3 @@
local lua_library_paths = { vim.env.VIMRUNTIME }
vim.list_extend(lua_library_paths, require("pack").get_paths())
---@type vim.lsp.Config
return {
settings = {
@@ -16,21 +13,38 @@ return {
-- Re-enable once luafmt is integrated in server
-- useDiff = true,
},
runtime = {
version = "LuaJIT",
requirePattern = {
"lua/?.lua",
"lua/?/init.lua",
},
},
workspace = {
library = lua_library_paths,
},
hint = {
enable = false,
},
},
},
---@param config vim.lsp.ClientConfig
before_init = function(_, config)
---@param path string|string[]
---@return string?
local function realpath(path)
---@type string?
local p
if type(path) == "table" then
p = path[1]
else
p = path
end
return p and vim.uv.fs_realpath(p) or p
end
local config_root = realpath(vim.fn.stdpath("config"))
local folder = config.workspace_folders and config.workspace_folders[1]
local root = config.root_dir or (folder and folder.name)
if root and realpath(root) == config_root then
local lib = { vim.env.VIMRUNTIME }
vim.list_extend(lib, require("pack").get_paths())
---@cast config.settings table
config.settings.emmylua =
vim.tbl_deep_extend("force", config.settings.emmylua or {}, {
workspace = { library = lib },
})
end
end,
on_attach = function(_, bufnr)
local util = require("util")