Merge pull request #1640 from snoweuph/fix/java/dap
Some checks are pending
Set up binary cache / cachix (default) (push) Waiting to run
Set up binary cache / cachix (maximal) (push) Waiting to run
Set up binary cache / cachix (nix) (push) Waiting to run
Treewide Checks / Validate flake (push) Waiting to run
Treewide Checks / Check formatting (push) Waiting to run
Treewide Checks / Check source tree for typos (push) Waiting to run
Treewide Checks / Validate documentation builds (push) Waiting to run
Treewide Checks / Validate documentation builds-1 (push) Waiting to run
Treewide Checks / Validate documentation builds-2 (push) Waiting to run
Treewide Checks / Validate documentation builds-3 (push) Waiting to run
Treewide Checks / Validate hyperlinks in documentation sources (push) Waiting to run
Treewide Checks / Validate Editorconfig conformance (push) Waiting to run
Build and deploy documentation / Check latest commit (push) Waiting to run
Build and deploy documentation / publish (push) Blocked by required conditions

languages/java: fix dap running glob on nvim startup
This commit is contained in:
Snoweuph 2026-06-13 03:01:07 +02:00 committed by GitHub
commit 5ee7fb1986
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -32,10 +32,44 @@
{
type = "jls",
request = "attach",
name = "Attach",
name = "Attach Auto",
hostName = "localhost",
port = 5005,
sourceRoots = vim.fn.glob("**/src/main/java", true, true),
sourceRoots = function()
local matches = {}
-- only look max 3 deep, due to performance reasons
for _, pattern in ipairs({
"src/main/java",
"*/src/main/java",
"*/*/src/main/java",
"*/*/*/src/main/java",
}) do
vim.list_extend(matches, vim.fn.glob(pattern, true, true))
end
return matches
end,
},
{
type = "jls",
request = "attach",
name = "Attach Manual",
hostName = "localhost",
port = 5005,
sourceRoots = function()
local path = vim.fn.input(
"Path to src/main/java: ",
vim.fn.getcwd() .. "/",
"dir"
)
if path == "" then
return {}
end
return { vim.fn.fnamemodify(path, ":p") }
end,
},
}
'';
@ -97,20 +131,7 @@ in {
You can change this by modifying `vim.debugger.nvim-dap.sources.java-debugger`.
```nix
vim.debugger.nvim-dap.sources.java-debugger = /* lua */ '''
dap.adapters.jls= {
type = 'executable',
command = ''\'''${getExe' inputs.self.packages.''${pkgs.stdenv.hostPlatform.system}.jls "jls-dap"}',
}
dap.configurations.java = {
{
type = "jls",
request = "attach",
name = "Attach",
hostName = "localhost",
port = 6969, -- your custom port
sourceRoots = vim.fn.glob("**/src/main/java", true, true),
},
}
${debuggers.jls.config}
''';
```