Skip to content

Commit 9860d8a

Browse files
committed
Fix jdtls
1 parent 8654291 commit 9860d8a

File tree

5 files changed

+86
-27
lines changed

5 files changed

+86
-27
lines changed

default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ let
4949
luasnip
5050
no-neck-pain-nvim
5151
nvim-lspconfig
52+
nvim-jdtls
5253
nvim-treesitter.withAllGrammars
5354
nvim-web-devicons
5455
oil-nvim

flake.lock

Lines changed: 21 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lua/config/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ local plugin_modules = {
1818
"ftplugin",
1919
"git",
2020
"indent",
21+
"java",
2122
"lsp",
2223
"snacks",
2324
"snippets",

lua/config/java.lua

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
local M = {}
2+
3+
function M.setup()
4+
vim.api.nvim_create_autocmd("FileType", {
5+
pattern = "java",
6+
callback = function()
7+
local jdtls = require("jdtls")
8+
9+
local root_dir = require("jdtls.setup").find_root({
10+
".classpath",
11+
".project",
12+
"pom.xml",
13+
"build.gradle",
14+
"gradlew",
15+
".git",
16+
})
17+
if not root_dir then
18+
root_dir = vim.fn.getcwd()
19+
end
20+
local project_name = vim.fn.fnamemodify(root_dir, ":p:h:t")
21+
local workspace_dir = vim.fn.stdpath("cache") .. "/jdtls/" .. project_name
22+
23+
-- Bemol workspace folders — added on_attach after jdtls initializes
24+
local bemol_dir = vim.fs.find({ ".bemol" }, { path = root_dir, upward = true, type = "directory" })[1]
25+
26+
local config = {
27+
cmd = { "jdtls", "-data", workspace_dir },
28+
root_dir = root_dir,
29+
capabilities = require("blink.cmp").get_lsp_capabilities(vim.lsp.protocol.make_client_capabilities()),
30+
settings = {
31+
java = {
32+
signatureHelp = { enabled = true },
33+
import = { enabled = true },
34+
rename = { enabled = true },
35+
},
36+
},
37+
on_attach = function(_, bufnr)
38+
if bemol_dir then
39+
local file = io.open(bemol_dir .. "/ws_root_folders", "r")
40+
if file then
41+
for line in file:lines() do
42+
if not vim.tbl_contains(vim.lsp.buf.list_workspace_folders(), line) then
43+
vim.lsp.buf.add_workspace_folder(line)
44+
end
45+
end
46+
file:close()
47+
end
48+
end
49+
50+
local opts = { buffer = bufnr }
51+
vim.keymap.set("n", "<leader>jo", jdtls.organize_imports, opts)
52+
vim.keymap.set("n", "<leader>jev", jdtls.extract_variable, opts)
53+
vim.keymap.set("v", "<leader>jem", jdtls.extract_method, opts)
54+
end,
55+
}
56+
57+
jdtls.start_or_attach(config)
58+
end,
59+
})
60+
end
61+
62+
return M

lua/config/lsp.lua

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ function M.setup()
6565
filetypes = { "brazil-config" },
6666
},
6767

68-
jdtls = {
69-
root_markers = { ".bemol" },
70-
on_attach = bemol,
71-
},
72-
7368
lua_ls = {
7469
server_capabilities = {
7570
semanticTokensProvider = vim.NIL,
@@ -188,7 +183,7 @@ function M.setup()
188183

189184
local settings = servers[client.name] or {}
190185

191-
local bemol_clients = { jdtls = true, ruff = true, ty = true }
186+
local bemol_clients = { ruff = true, ty = true }
192187
if bemol_clients[client.name] then
193188
bemol()
194189
end

0 commit comments

Comments
 (0)