local status_ok, jdtls = pcall(require, 'jdtls')
if not status_ok then
    vim.notify("nvim-jdtls not found — run :PackerSync", vim.log.levels.WARN)
    return
end

vim.api.nvim_create_autocmd("FileType", {
  pattern = "java",
  callback = function()
    local root_dir = require('jdtls.setup').find_root({
      '.git',
      'mvnw',
      'gradlew',
      'pom.xml',
      'build.gradle'
    })

    if root_dir == nil then return end

    local lombok_path = vim.fn.expand("~/.local/share/nvim/mason/packages/jdtls/lombok.jar")

    local config = {
      cmd = {
        "jdtls",
        "--java-executable=/usr/lib/jvm/java-21-openjdk-amd64/bin/java",
        "--jvm-arg=-javaagent:" .. lombok_path,
      },
      root_dir = root_dir,
    }

    jdtls.start_or_attach(config)
  end,
})
