LunarVim/ftplugin/java.lua

97 lines
3 KiB
Lua
Raw Normal View History

2021-07-14 02:57:58 +02:00
vim.cmd "let proj = FindRootDirectory()"
local root_dir = vim.api.nvim_get_var "proj"
-- use the global prettier if you didn't find the local one
local prettier_instance = root_dir .. "/node_modules/.bin/prettier"
if vim.fn.executable(prettier_instance) ~= 1 then
prettier_instance = O.lang.tsserver.formatter.exe
end
O.formatters.filetype["java"] = {
function()
return {
exe = prettier_instance,
-- TODO: allow user to override this
args = { "--stdin-filepath", vim.api.nvim_buf_get_name(0) },
stdin = true,
}
end,
}
require("formatter.config").set_defaults {
logging = false,
filetype = O.formatters.filetype,
}
if require("lv-utils").check_lsp_client_active "jdtls" then
return
end
2021-07-09 07:37:03 +02:00
if O.lang.java.java_tools.active then
-- find_root looks for parent directories relative to the current buffer containing one of the given arguments.
if vim.fn.has "mac" == 1 then
WORKSPACE_PATH = "/Users/" .. USER .. "/workspace/"
elseif vim.fn.has "unix" == 1 then
WORKSPACE_PATH = "/home/" .. USER .. "/workspace/"
else
print "Unsupported system"
end
2021-07-09 17:33:19 +02:00
JAVA_LS_EXECUTABLE = CONFIG_PATH .. "/utils/bin/jdtls"
2021-07-09 07:37:03 +02:00
require("jdtls").start_or_attach {
2021-07-09 08:09:45 +02:00
on_attach = require("lsp").common_on_attach,
2021-07-09 07:37:03 +02:00
cmd = { JAVA_LS_EXECUTABLE, WORKSPACE_PATH .. vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t") },
}
2021-07-09 08:09:45 +02:00
2021-07-10 06:09:33 +02:00
vim.api.nvim_set_keymap(
"n",
"<leader>la",
":lua require('jdtls').code_action()<CR>",
{ noremap = true, silent = true }
)
vim.api.nvim_set_keymap(
"n",
"<leader>lR",
":lua require('jdtls').code_action(false, 'refactor')<CR>",
{ noremap = true, silent = true }
)
2021-07-09 08:09:45 +02:00
vim.cmd "command! -buffer JdtCompile lua require('jdtls').compile()"
vim.cmd "command! -buffer JdtUpdateConfig lua require('jdtls').update_project_config()"
2021-07-10 06:09:33 +02:00
-- vim.cmd "command! -buffer JdtJol lua require('jdtls').jol()"
2021-07-09 08:09:45 +02:00
vim.cmd "command! -buffer JdtBytecode lua require('jdtls').javap()"
2021-07-10 06:09:33 +02:00
-- vim.cmd "command! -buffer JdtJshell lua require('jdtls').jshell()"
2021-07-09 07:37:03 +02:00
else
local util = require "lspconfig/util"
require("lspconfig").jdtls.setup {
on_attach = require("lsp").common_on_attach,
cmd = { DATA_PATH .. "/lspinstall/java/jdtls.sh" },
filetypes = { "java" },
root_dir = util.root_pattern { ".git", "build.gradle", "pom.xml" },
-- init_options = {bundles = bundles}
-- on_attach = require'lsp'.common_on_attach
}
end
2021-03-23 03:10:39 +01:00
-- local bundles = {
-- vim.fn.glob(
-- CONFIG_PATH.."/.debuggers/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-*.jar")
-- };
2021-03-23 03:10:39 +01:00
-- require('jdtls').start_or_attach({
-- on_attach = on_attach,
-- cmd = {DATA_PATH .. "/lspinstall/java/jdtls.sh"},
-- root_dir = require('jdtls.setup').find_root({'build.gradle', 'pom.xml', '.git'}),
-- init_options = {bundles = bundles}
-- })
2021-07-01 00:45:40 +02:00
-- TODO: setup autoformat stuff later
2021-07-05 03:14:01 +02:00
-- _java = {
-- -- {'FileType', 'java', 'luafile '..CONFIG_PATH..'/lua/lsp/java-ls.lua'},
-- {
-- 'FileType', 'java',
-- 'nnoremap ca <Cmd>lua require(\'jdtls\').code_action()<CR>'
-- }
-- }