diff --git a/after/lsp/lua_ls.lua b/after/lsp/lua_ls.lua new file mode 100644 index 00000000..b26fbd0a --- /dev/null +++ b/after/lsp/lua_ls.lua @@ -0,0 +1,38 @@ +return { + 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, + library = { + vim.env.VIMRUNTIME, + }, + -- -- 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 = {}, + }, +} diff --git a/lua/core/globals.lua b/lua/core/globals.lua index 85fb1b60..f412c3f6 100644 --- a/lua/core/globals.lua +++ b/lua/core/globals.lua @@ -11,6 +11,32 @@ vim.g.have_nerd_font = false -- Configs for Programming Languages -- like LSPs, Tree-sitters, Linters, Fromatters, Debuggers, etc. Langs = { + lsp = { + 'bashls', + 'clangd', + 'elmls', + 'gopls', + 'harper_ls', + 'html', + 'intelephense', + 'just', + 'laravel_ls', + 'lua_ls', + 'markdown_oxide', + 'marksman', + 'omnisharp', + 'phpactor', + 'pyrefly', + 'roslyn_ls', + 'stylua', + 'superhtml', + 'svelte', + 'tailwindcss', + 'ts_ls', + 'zls', + -- 'fsautocomplete', + }, + treesitter = { 'bash', 'c', diff --git a/lua/plugins/nvim-lspconfig.lua b/lua/plugins/nvim-lspconfig.lua index a9ec2008..b5cb27cd 100644 --- a/lua/plugins/nvim-lspconfig.lua +++ b/lua/plugins/nvim-lspconfig.lua @@ -11,7 +11,12 @@ return { ---@module 'mason.settings' ---@type MasonSettings ---@diagnostic disable-next-line: missing-fields - opts = {}, + opts = { + registries = { + 'github:Crashdummyy/mason-registry', + 'github:mason-org/mason-registry', + }, + }, }, -- Maps LSP server names between nvim-lspconfig and Mason package names. 'mason-org/mason-lspconfig.nvim', @@ -123,72 +128,51 @@ return { -- 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 = {}, - -- pyright = {}, - -- rust_analyzer = {}, - -- - -- Some languages (like typescript) have entire language plugins that can be useful: - -- https://github.com/pmizio/typescript-tools.nvim - -- - -- 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 + -- local servers = { + -- -- clangd = {}, + -- -- gopls = {}, + -- -- pyright = {}, + -- -- rust_analyzer = {}, + -- -- + -- -- Some languages (like typescript) have entire language plugins that can be useful: + -- -- https://github.com/pmizio/typescript-tools.nvim + -- -- + -- -- But for many setups, the LSP (`ts_ls`) will work just fine + -- -- ts_ls = {}, -- - -- To check the current status of installed tools and/or manually install - -- other tools, you can run - -- :Mason + -- stylua = {}, -- Used to format Lua code -- - -- You can press `g?` for help in this menu. - local ensure_installed = vim.tbl_keys(servers or {}) - vim.list_extend(ensure_installed, { - -- You can add other tools here that you want Mason to install - }) + -- -- Special Lua Config, as recommended by neovim help docs + -- lua_ls = {}, + -- } - require('mason-tool-installer').setup { ensure_installed = ensure_installed } + local servers = Langs.lsp + + -- -- NOTE: I won't be using `mason-tool-installer` to auto-install tools for now. + -- -- + -- -- Ensure the servers and tools above are installed + -- -- + -- -- To check the current status of installed tools and/or manually install + -- -- other tools, you can run + -- -- :Mason + -- -- + -- -- You can press `g?` for help in this menu. + -- local ensure_installed = vim.tbl_keys(servers or {}) + -- vim.list_extend(ensure_installed, { + -- -- You can add other tools here that you want Mason to install + -- }) + -- + -- require('mason-tool-installer').setup { ensure_installed = ensure_installed } for name, server in pairs(servers) do - vim.lsp.config(name, server) - vim.lsp.enable(name) + if string.match(name, '^%d+$') then + -- name is actually an index, and the server doesn't provide any additional config. + vim.lsp.enable(server) + else + -- name is an actual name, and the server provides additional config. + vim.lsp.config(name, server) + vim.lsp.enable(name) + end end end, }