-- 1. Setup Mason first
require("mason").setup()
require("mason-lspconfig").setup({
    -- Remove "jdtls" from here to prevent the 'enable' (nil value) crash
    ensure_installed = {
        "pyright",
        "ts_ls",
        "marksman",
        "kotlin_language_server",
        "svelte",
        "gopls",
    },
})

-- 2. Global LSP Attach (The modern way to handle keymaps)
vim.api.nvim_create_autocmd('LspAttach', {
    group = vim.api.nvim_create_augroup('UserLspConfig', {}),
    callback = function(ev)
        local opts = { buffer = ev.buf }
        vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
        vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
        vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
        vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
    end,
})

-- 3. Load your modernized server configs
-- These files should now use vim.lsp.config and vim.lsp.enable
require("user.lsp_servers.pyright")
require("user.lsp_servers.ts_ls")
require("user.lsp_servers.jdtls")
require("user.lsp_servers.marksman")
require("user.lsp_servers.kotlin_ls")
require("user.lsp_servers.dartls")
require("user.lsp_servers.svelte")
require("user.lsp_servers.golang")
