local root_markers = { '.git', 'mvnw', 'gradlew' }
local home = os.getenv('HOME')
local root_dir = require('jdtls.setup').find_root(root_markers)
local workspace_dir = home .. '/.local/share/eclipse/' .. vim.fn.fnamemodify(root_dir, ':p:h:t')

local config = {
  cmd = {
    'jdtls',
    '-data', workspace_dir,
  },
  root_dir = require('jdtls.setup').find_root(root_markers),
  settings = {
    java = {},
  },
  init_options = {
    bundles = {
      require('mason-core.path').package_prefix('java-debug-adapter') ..
      '/extension/server/com.microsoft.java.debug.plugin-0.46.0.jar',
    },
  },
  on_attach = function()
    local jdtls = require('jdtls')
    jdtls.setup_dap({ hotcodereplace = 'auto', config_overrides = {} })
  end,
}
require('jdtls').start_or_attach(config)
