commit 73fe5f45f62be458428dfc09d7970d7562a535ee
parent 5433f338fc204d15cb1f80cd2354b3d065e2e2d8
Author: Alex Balgavy <alex@balgavy.eu>
Date: Sun, 8 Oct 2023 15:07:33 +0200
nvim: fix lua_ls vim builtin
Diffstat:
1 file changed, 33 insertions(+), 14 deletions(-)
diff --git a/nvim/lua/config/mason-lspconfig.lua b/nvim/lua/config/mason-lspconfig.lua
@@ -5,6 +5,7 @@ local mason_lspconfig = require 'mason-lspconfig'
-- Add any additional override configuration in the following tables. They will be passed to
-- the `settings` field of the server config. You must look up that documentation yourself.
local servers = {
+ lua_ls = {},
rust_analyzer = {
['rust-analyzer'] = {
cargo = {
@@ -36,20 +37,6 @@ local servers = {
-- texlab = {},
-- clangd = {},
-- perlnavigator = {},
- lua_ls = {
- Lua = {
- runtime = {
- -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
- version = 'LuaJIT',
- },
- workspace = { checkThirdParty = false },
- telemetry = { enable = false },
- diagnostics = {
- -- Get the language server to recognize the `vim` global
- globals = {'vim'},
- }
- },
- },
},
}
@@ -113,3 +100,35 @@ mason_lspconfig.setup_handlers {
end,
}
+-- Lua needs special treatment to make it aware of Neovim builtins
+require'lspconfig'.lua_ls.setup {
+ on_init = function(client)
+ local path = client.workspace_folders[1].name
+ if not vim.loop.fs_stat(path..'/.luarc.json') and not vim.loop.fs_stat(path..'/.luarc.jsonc') then
+ client.config.settings = vim.tbl_deep_extend('force', client.config.settings, {
+ Lua = {
+ runtime = {
+ -- Tell the language server which version of Lua you're using
+ -- (most likely LuaJIT in the case of Neovim)
+ version = 'LuaJIT'
+ },
+ -- Make the server aware of Neovim runtime files
+ workspace = {
+ checkThirdParty = false,
+ library = {
+ vim.env.VIMRUNTIME
+ -- "${3rd}/luv/library"
+ -- "${3rd}/busted/library",
+ }
+ -- or pull in all of 'runtimepath'. NOTE: this is a lot slower
+ -- library = vim.api.nvim_get_runtime_file("", true)
+ },
+ telemetry = { enable = false },
+ }
+ })
+
+ client.notify("workspace/didChangeConfiguration", { settings = client.config.settings })
+ end
+ return true
+ end
+}