Add java extra and configure jdtls

This commit is contained in:
2026-05-09 14:18:19 -04:00
parent 397ec2a484
commit 8ef26ce53a
4 changed files with 163 additions and 70 deletions

View File

@@ -28,3 +28,62 @@ if vim.fn.has("mac") == 1 then
vim.keymap.set("t", "<D-v>", '<C-\\><C-n>"+pi')
vim.keymap.set("t", "<D-s-v>", '<C-\\><C-n>"+pi')
end
local function oxlint_cmd(bufnr)
local file = vim.api.nvim_buf_get_name(bufnr)
if file == "" then
return nil
end
local root = vim.fs.dirname(vim.fs.find({ "package.json", ".oxlintrc.json", "oxlint.config.ts" }, {
path = file,
upward = true,
})[1] or "")
local local_bin = root ~= "" and vim.fs.joinpath(root, "node_modules", ".bin", "oxlint") or nil
return local_bin and vim.fn.executable(local_bin) == 1 and local_bin or "oxlint"
end
local function oxlint_fix()
local bufnr = vim.api.nvim_get_current_buf()
local file = vim.api.nvim_buf_get_name(bufnr)
if file == "" then
vim.notify("Oxlint fix requires a file-backed buffer", vim.log.levels.WARN)
return
end
if vim.bo[bufnr].modified then
vim.cmd.update()
end
local cmd = oxlint_cmd(bufnr)
if not cmd or vim.fn.executable(cmd) ~= 1 then
vim.notify("oxlint executable not found", vim.log.levels.ERROR)
return
end
local cwd = vim.fs.dirname(vim.fs.find({ "package.json", ".oxlintrc.json", "oxlint.config.ts" }, {
path = file,
upward = true,
})[1] or file)
vim.system({ cmd, "--fix", "--type-aware", file }, { cwd = cwd, text = true }, function(result)
vim.schedule(function()
if result.code == 0 or result.code == 1 then
vim.cmd.checktime()
pcall(require("lint").try_lint, "oxlint")
local level = result.code == 0 and vim.log.levels.INFO or vim.log.levels.WARN
local msg = result.code == 0 and "Oxlint fix completed" or "Oxlint fix completed with remaining diagnostics"
vim.notify(msg, level)
else
local output = table.concat(vim.tbl_filter(function(v)
return v and v ~= ""
end, { result.stdout, result.stderr }), "\n")
vim.notify(output ~= "" and output or "Oxlint fix failed", vim.log.levels.ERROR)
end
end)
end)
end
vim.api.nvim_create_user_command("OxlintFix", oxlint_fix, { desc = "Fix current file with oxlint" })
vim.keymap.set("n", "<leader>cx", oxlint_fix, { desc = "Oxlint Fix" })

33
lua/plugins/java.lua Normal file
View File

@@ -0,0 +1,33 @@
return {
{
"mfussenegger/nvim-jdtls",
opts = function(_, opts)
local corretto8 = "/Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home"
local temurin21 = "/Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/Home"
opts.cmd = opts.cmd or {}
table.insert(opts.cmd, "--java-executable")
table.insert(opts.cmd, temurin21 .. "/bin/java")
local project_jdk = vim.env.JAVA_HOME or temurin21
opts.settings = vim.tbl_deep_extend("force", opts.settings or {}, {
java = {
import = {
gradle = {
java = { home = project_jdk },
},
},
configuration = {
runtimes = {
{ name = "JavaSE-1.8", path = corretto8 },
{ name = "JavaSE-21", path = temurin21 },
},
},
},
})
return opts
end,
},
}