return { "neovim/nvim-lspconfig", event = { "BufReadPre", "BufNewFile" }, dependencies = { "folke/neoconf.nvim", "hrsh7th/cmp-nvim-lsp", }, config = function() local capabilities = require("cmp_nvim_lsp").default_capabilities() local util = require("lspconfig.util") local function on_attach(_, bufnr) local map = function(mode, lhs, rhs, desc) vim.keymap.set(mode, lhs, rhs, { buffer = bufnr, silent = true, noremap = true, desc = desc }) end map('n', 'gd', vim.lsp.buf.definition, 'LSP: Go to definition') map('n', 'gr', vim.lsp.buf.references, 'LSP: References') map('n', 'gD', vim.lsp.buf.declaration, 'LSP: Go to declaration') map('n', 'gI', vim.lsp.buf.implementation, 'LSP: Go to implementation') map('n', 'K', vim.lsp.buf.hover, 'LSP: Hover') end local function setup(server, opts) local ok, mod = pcall(require, "lspconfig." .. server) if not ok or type(mod.setup) ~= "function" then return end mod.setup(vim.tbl_deep_extend("force", { capabilities = capabilities, on_attach = on_attach, root_dir = util.root_pattern( ".neoconf.json", ".git", "composer.json", "package.json" ), }, opts or {})) end setup("lua_ls", { settings = { Lua = { diagnostics = { globals = { "vim" } }, }, }, }) setup("ts_ls") setup("html") setup("cssls") setup("jsonls") setup("bashls") setup("marksman") -- TODO(r): Root detection can pick a parent repo in nested setups. -- Workaround noted in MIGRATION_PLAN.md: create an empty `.git` (or `.nvimroot`) -- in the intended workspace root to pin LSP root until we refine root_dir further. setup("intelephense", { single_file_support = false, root_dir = util.root_pattern( ".neoconf.json", "composer.json", ".nvimroot", ".git" ), }) end, }