put jdtls config in separate lua file

This commit is contained in:
Charlotte 🦝 Delenk 2022-08-10 09:05:05 +01:00
parent 0b1f88c6c0
commit cd72423782
Signed by: darkkirb
GPG key ID: AB2BD8DAF2E37122
2 changed files with 64 additions and 54 deletions

View file

@ -3,62 +3,15 @@
lib, lib,
... ...
}: }:
with lib; { with builtins;
with lib;
let
jdtls-lua = replaceStrings ["@jdt-language-server@" "@openjdk@"] ["${pkgs.jdt-language-server}" "${pkgs.openjdk}" ] (readFile ../lua/jdtls.lua);
in
{
output.config_file = '' output.config_file = ''
lua << EOF lua << EOF
vim.api.nvim_create_autocmd({"FileType"}, { ${jdtls-lua}
local jdtls = require('jdtls')
local root_markers = {'gradlew', '.git'}
local root_dir = require('jdtls.setup').find_root(root_markers)
local home = os.getenv('HOME')
local workspace_folder = home .. "/.cache/nvim/java/" .. vim.fn.fnamemodify(root_dir, ":p:h:t")
local config = {
cmd = {
'${pkgs.jdt-language-server}/bin/jdt-language-server',
'-data', workspace_folder
},
java = {
signatureHelp = { enabled = true },
contentProvider = { preferred = 'fernflower' },
codeGeneration = {
toString = {
template = "''${object.className}{''${member.name()}=''${member.value}, ''${otherMembers}}"
},
hashCodeEquals = {
useJava7Objects = true,
},
useBlocks = true,
},
configuration = {
runtimes = {
{
name = "JavaSE-17",
path = "${pkgs.openjdk}",
},
}
}
},
onAttach = function(client, bufnr)
require('me.lsp.conf').on_attach(client, bufnr, {
server_side_fuzzy_completion = true,
})
jdtls.setup_dap({hotcodereplace = 'auto'})
jdtls.setup.add_commands()
local opts = { silent = true, buffer = bufnr }
vim.keymap.set('n', "<A-o>", jdtls.organize_imports, opts)
vim.keymap.set('n', "<leader>df", jdtls.test_class, opts)
vim.keymap.set('n', "<leader>dn", jdtls.test_nearest_method, opts)
vim.keymap.set('n', "crv", jdtls.extract_variable, opts)
vim.keymap.set('v', 'crm', [[<ESC><CMD>lua require('jdtls').extract_method(true)<CR>]], opts)
vim.keymap.set('n', "crc", jdtls.extract_constant, opts)
local create_command = vim.api.nvim_buf_create_user_command
create_command(bufnr, 'W', require('me.lsp.ext').remove_unused_imports, {
nargs = 0,
})
end
}
})
EOF EOF
''; '';
} }

View file

@ -0,0 +1,57 @@
vim.api.nvim_create_autocmd({ "FileType" }, {
pattern = { "java" },
callback = function()
local jdtls = require("jdtls")
local root_markers = { "gradlew", ".git" }
local root_dir = require("jdtls.setup").find_root(root_markers)
local home = os.getenv("HOME")
local workspace_folder = home .. "/.cache/nvim/java/" .. vim.fn.fnamemodify(root_dir, ":p:h:t")
local config = {
cmd = {
"@jdt-language-server@/bin/jdt-language-server",
"-data",
workspace_folder,
},
java = {
signatureHelp = { enabled = true },
contentProvider = { preferred = "fernflower" },
codeGeneration = {
toString = {
template = "${object.className}{${member.name()}=${member.value}, ${otherMembers}}",
},
hashCodeEquals = {
useJava7Objects = true,
},
useBlocks = true,
},
configuration = {
runtimes = {
{
name = "JavaSE-17",
path = "@openjdk@",
},
},
},
},
onAttach = function(client, bufnr)
require("me.lsp.conf").on_attach(client, bufnr, {
server_side_fuzzy_completion = true,
})
jdtls.setup_dap({ hotcodereplace = "auto" })
jdtls.setup.add_commands()
local opts = { silent = true, buffer = bufnr }
vim.keymap.set("n", "<A-o>", jdtls.organize_imports, opts)
vim.keymap.set("n", "<leader>df", jdtls.test_class, opts)
vim.keymap.set("n", "<leader>dn", jdtls.test_nearest_method, opts)
vim.keymap.set("n", "crv", jdtls.extract_variable, opts)
vim.keymap.set("v", "crm", [[<ESC><CMD>lua require('jdtls').extract_method(true)<CR>]], opts)
vim.keymap.set("n", "crc", jdtls.extract_constant, opts)
local create_command = vim.api.nvim_buf_create_user_command
create_command(bufnr, "W", require("me.lsp.ext").remove_unused_imports, {
nargs = 0,
})
end,
}
end,
})