From b9f3965282ae2a3c746ee24efb6dcd6962e8e742 Mon Sep 17 00:00:00 2001 From: Ori Perry Date: Fri, 27 Feb 2026 20:12:40 +0200 Subject: [PATCH] Clean up the lua_ls config --- init.lua | 61 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/init.lua b/init.lua index 4246703..aacc847 100644 --- a/init.lua +++ b/init.lua @@ -594,6 +594,7 @@ require('lazy').setup({ -- Enable the following language servers -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. -- See `:help lsp-config` for information about keys and how to configure + ---@type table local servers = { -- clangd = {}, -- gopls = {}, @@ -605,6 +606,37 @@ require('lazy').setup({ -- -- But for many setups, the LSP (`ts_ls`) will work just fine -- ts_ls = {}, + + stylua = {}, -- Used to format Lua code + + -- Special Lua Config, as recommended by neovim help docs + lua_ls = { + on_init = function(client) + if client.workspace_folders then + local path = client.workspace_folders[1].name + if path ~= vim.fn.stdpath 'config' and (vim.uv.fs_stat(path .. '/.luarc.json') or vim.uv.fs_stat(path .. '/.luarc.jsonc')) then return end + end + + client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, { + runtime = { + version = 'LuaJIT', + path = { 'lua/?.lua', 'lua/?/init.lua' }, + }, + workspace = { + checkThirdParty = false, + -- NOTE: this is a lot slower and will cause issues when working on your own configuration. + -- See https://github.com/neovim/nvim-lspconfig/issues/3189 + library = vim.tbl_extend('force', vim.api.nvim_get_runtime_file('', true), { + '${3rd}/luv/library', + '${3rd}/busted/library', + }), + }, + }) + end, + settings = { + Lua = {}, + }, + }, } -- Ensure the servers and tools above are installed @@ -616,8 +648,6 @@ require('lazy').setup({ -- You can press `g?` for help in this menu. local ensure_installed = vim.tbl_keys(servers or {}) vim.list_extend(ensure_installed, { - 'lua_ls', -- Lua Language server - 'stylua', -- Used to format Lua code -- You can add other tools here that you want Mason to install }) @@ -628,33 +658,6 @@ require('lazy').setup({ vim.lsp.config(name, server) vim.lsp.enable(name) end - - -- Special Lua Config, as recommended by neovim help docs - vim.lsp.config('lua_ls', { - on_init = function(client) - if client.workspace_folders then - local path = client.workspace_folders[1].name - if path ~= vim.fn.stdpath 'config' and (vim.uv.fs_stat(path .. '/.luarc.json') or vim.uv.fs_stat(path .. '/.luarc.jsonc')) then return end - end - - client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, { - runtime = { - version = 'LuaJIT', - path = { 'lua/?.lua', 'lua/?/init.lua' }, - }, - workspace = { - checkThirdParty = false, - -- NOTE: this is a lot slower and will cause issues when working on your own configuration. - -- See https://github.com/neovim/nvim-lspconfig/issues/3189 - library = vim.api.nvim_get_runtime_file('', true), - }, - }) - end, - settings = { - Lua = {}, - }, - }) - vim.lsp.enable 'lua_ls' end, },