diff --git a/init.lua b/init.lua index 861a3135..ec84bea0 100644 --- a/init.lua +++ b/init.lua @@ -463,18 +463,6 @@ require('lazy').setup({ }, -- LSP Plugins - { - -- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins - -- used for completion, annotations and signatures of Neovim apis - 'folke/lazydev.nvim', - ft = 'lua', - opts = { - library = { - -- Load luvit types when the `vim.uv` word is found - { path = '${3rd}/luv/library', words = { 'vim%.uv' } }, - }, - }, - }, { -- Main LSP Configuration 'neovim/nvim-lspconfig', @@ -669,22 +657,6 @@ require('lazy').setup({ -- -- But for many setups, the LSP (`ts_ls`) will work just fine -- ts_ls = {}, - -- - - lua_ls = { - -- cmd = { ... }, - -- filetypes = { ... }, - -- capabilities = {}, - settings = { - Lua = { - completion = { - callSnippet = 'Replace', - }, - -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings - -- diagnostics = { disable = { 'missing-fields' } }, - }, - }, - }, } -- Ensure the servers and tools above are installed @@ -704,22 +676,58 @@ require('lazy').setup({ vim.list_extend(ensure_installed, { 'stylua', -- Used to format Lua code }) + require('mason-tool-installer').setup { ensure_installed = ensure_installed } require('mason-lspconfig').setup { - ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer) - automatic_installation = false, - handlers = { - function(server_name) - local server = servers[server_name] or {} - -- This handles overriding only values explicitly passed - -- by the server configuration above. Useful when disabling - -- certain features of an LSP (for example, turning off formatting for ts_ls) - server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) - require('lspconfig')[server_name].setup(server) - end, - }, + ensure_installed = { 'lua_ls' }, } + + for name, server in pairs(servers) do + server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) + vim.lsp.config(name, server) + vim.lsp.enable(name) + end + + 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', + }, + }, + -- Make the server aware of Neovim runtime files + 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), + -- + -- Alternatively: + -- library = { + -- vim.env.VIMRUNTIME, + -- -- Depending on the usage, you might want to add additional paths + -- -- here. + -- -- '${3rd}/luv/library', + -- -- '${3rd}/busted/library', + -- }, + }, + }) + end, + settings = { + Lua = {}, + }, + }) end, }, @@ -795,7 +803,6 @@ require('lazy').setup({ }, opts = {}, }, - 'folke/lazydev.nvim', }, --- @module 'blink.cmp' --- @type blink.cmp.Config @@ -841,10 +848,7 @@ require('lazy').setup({ }, sources = { - default = { 'lsp', 'path', 'snippets', 'lazydev' }, - providers = { - lazydev = { module = 'lazydev.integrations.blink', score_offset = 100 }, - }, + default = { 'lsp', 'path', 'snippets' }, }, snippets = { preset = 'luasnip' },