summaryrefslogtreecommitdiff
path: root/ftplugin/java.lua
diff options
context:
space:
mode:
Diffstat (limited to 'ftplugin/java.lua')
-rw-r--r--ftplugin/java.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/ftplugin/java.lua b/ftplugin/java.lua
index 2f42a78f..7db90f0e 100644
--- a/ftplugin/java.lua
+++ b/ftplugin/java.lua
@@ -1,3 +1,28 @@
+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