From 2d1579c9691bbc27c2a290cae5b028aa90f71fb9 Mon Sep 17 00:00:00 2001 From: "asep.komarudin" Date: Tue, 25 Jun 2024 16:58:01 +0700 Subject: [PATCH] enc: migrate java from nvim-jdtls to lsp jdtls --- ftplugin/java.lua | 286 +++++++++++++++--------------- lazy-lock.json | 17 +- lua/custom/default.lua | 8 +- lua/plugins/java.lua | 60 +++---- lua/plugins/themes/_globalvar.lua | 5 +- lua/user/lsp/settings/jdtls.lua | 15 ++ 6 files changed, 200 insertions(+), 191 deletions(-) create mode 100644 lua/user/lsp/settings/jdtls.lua diff --git a/ftplugin/java.lua b/ftplugin/java.lua index 9e8fa02..bddcc35 100644 --- a/ftplugin/java.lua +++ b/ftplugin/java.lua @@ -1,145 +1,145 @@ -- more space in the neovim command line for displaying messages -- use this function notation to build some variables -vim.opt_local.shiftwidth = 4 -vim.opt_local.tabstop = 4 -vim.opt_local.softtabstop = 4 -vim.opt_local.ts = 4 -vim.opt_local.expandtab = true - -local status, jdtls = pcall(require, "jdtls") -if not status then - return -end - -local function capabilities() - local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") - if status_ok then - return cmp_nvim_lsp.default_capabilities() - end - - local CAPABILITIES = vim.lsp.protocol.make_client_capabilities() - CAPABILITIES.textDocument.completion.completionItem.snippetSupport = true - CAPABILITIES.textDocument.completion.completionItem.resolveSupport = { - properties = { - "documentation", - "detail", - "additionalTextEdits", - }, - } - - return CAPABILITIES -end - -local function directory_exists(path) - local f = io.popen("cd " .. path) - local ff = f:read("*all") - - if ff:find("ItemNotFoundException") then - return false - else - return true - end -end - -local root_markers = { ".git", "mvnw", "gradlew", "pom.xml", "build.gradle" } -local root_dir = require("jdtls.setup").find_root(root_markers) - --- calculate workspace dir -local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t") -local workspace_dir = vim.fn.stdpath("data") .. "/site/java/workspace-root/" .. project_name -if directory_exists(workspace_dir) then -else - os.execute("mkdir " .. workspace_dir) -end --- get the mason install path -local install_path = require("mason-registry").get_package("jdtls"):get_install_path() - --- get the current OS -local os -if vim.fn.has("macunix") then - os = "mac" -elseif vim.fn.has("win32") then - os = "win" -else - os = "linux" -end - -local bundles = {} -local mason_path = vim.fn.glob(vim.fn.stdpath("data") .. "/mason/") -vim.list_extend(bundles, vim.split(vim.fn.glob(mason_path .. "packages/java-test/extension/server/*.jar"), "\n")) -vim.list_extend( - bundles, - vim.split( - vim.fn.glob( - vim.fn.stdpath("data") - .. "/lazy/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-*.jar" - ), - "\n" - ) -) - -local config = { - cmd = { - "java", - "-Declipse.application=org.eclipse.jdt.ls.core.id1", - "-Dosgi.bundles.defaultStartLevel=4", - "-Declipse.product=org.eclipse.jdt.ls.core.product", - "-Dlog.protocol=true", - "-Dlog.level=ALL", - "-javaagent:" .. install_path .. "/lombok.jar", - "-Xms1g", - "--add-modules=ALL-SYSTEM", - "--add-opens", - "java.base/java.util=ALL-UNNAMED", - "--add-opens", - "java.base/java.lang=ALL-UNNAMED", - "-jar", - vim.fn.glob(install_path .. "/plugins/org.eclipse.equinox.launcher_*.jar"), - "-configuration", - install_path .. "/config_" .. os, - "-data", - workspace_dir, - }, - capabilities = capabilities(), - root_dir = root_dir, - settings = { - java = {}, - }, - - init_options = { - bundles = bundles, - -- bundles = { - -- vim.fn.glob( - -- mason_path .. "packages/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar", - -- "\n" - -- ), - -- }, - }, -} - -config["on_attach"] = function(client, bufnr) - local _, _ = pcall(vim.lsp.codelens.refresh) - - -- valdation if DAP not installed - local dap_status, _ = pcall(require, "nvim-dap") - if not dap_status then - return - end - - require("jdtls.dap").setup_dap_main_class_configs() - jdtls.setup_dap({ hotcodereplace = "auto" }) - require("user.lsp.handlers").on_attach(client, bufnr) -end - -vim.api.nvim_create_autocmd({ "BufWritePost" }, { - pattern = { "*.java" }, - callback = function() - local _, _ = pcall(vim.lsp.codelens.refresh) - end, -}) - -jdtls.start_or_attach(config) - -vim.cmd( - [[command! -buffer -nargs=? -complete=custom,v:lua.require'jdtls'._complete_set_runtime JdtSetRuntime lua require('jdtls').set_runtime()]] -) +-- vim.opt_local.shiftwidth = 4 +-- vim.opt_local.tabstop = 4 +-- vim.opt_local.softtabstop = 4 +-- vim.opt_local.ts = 4 +-- vim.opt_local.expandtab = true +-- +-- local status, jdtls = pcall(require, "jdtls") +-- if not status then +-- return +-- end +-- +-- local function capabilities() +-- local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") +-- if status_ok then +-- return cmp_nvim_lsp.default_capabilities() +-- end +-- +-- local CAPABILITIES = vim.lsp.protocol.make_client_capabilities() +-- CAPABILITIES.textDocument.completion.completionItem.snippetSupport = true +-- CAPABILITIES.textDocument.completion.completionItem.resolveSupport = { +-- properties = { +-- "documentation", +-- "detail", +-- "additionalTextEdits", +-- }, +-- } +-- +-- return CAPABILITIES +-- end +-- +-- local function directory_exists(path) +-- local f = io.popen("cd " .. path) +-- local ff = f:read("*all") +-- +-- if ff:find("ItemNotFoundException") then +-- return false +-- else +-- return true +-- end +-- end +-- +-- local root_markers = { ".git", "mvnw", "gradlew", "pom.xml", "build.gradle" } +-- local root_dir = require("jdtls.setup").find_root(root_markers) +-- +-- -- calculate workspace dir +-- local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t") +-- local workspace_dir = vim.fn.stdpath("data") .. "/site/java/workspace-root/" .. project_name +-- if directory_exists(workspace_dir) then +-- else +-- os.execute("mkdir " .. workspace_dir) +-- end +-- -- get the mason install path +-- local install_path = require("mason-registry").get_package("jdtls"):get_install_path() +-- +-- -- get the current OS +-- local os +-- if vim.fn.has("macunix") then +-- os = "mac" +-- elseif vim.fn.has("win32") then +-- os = "win" +-- else +-- os = "linux" +-- end +-- +-- local bundles = {} +-- local mason_path = vim.fn.glob(vim.fn.stdpath("data") .. "/mason/") +-- vim.list_extend(bundles, vim.split(vim.fn.glob(mason_path .. "packages/java-test/extension/server/*.jar"), "\n")) +-- vim.list_extend( +-- bundles, +-- vim.split( +-- vim.fn.glob( +-- vim.fn.stdpath("data") +-- .. "/lazy/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-*.jar" +-- ), +-- "\n" +-- ) +-- ) +-- +-- local config = { +-- cmd = { +-- "java", +-- "-Declipse.application=org.eclipse.jdt.ls.core.id1", +-- "-Dosgi.bundles.defaultStartLevel=4", +-- "-Declipse.product=org.eclipse.jdt.ls.core.product", +-- "-Dlog.protocol=true", +-- "-Dlog.level=ALL", +-- "-javaagent:" .. install_path .. "/lombok.jar", +-- "-Xms1g", +-- "--add-modules=ALL-SYSTEM", +-- "--add-opens", +-- "java.base/java.util=ALL-UNNAMED", +-- "--add-opens", +-- "java.base/java.lang=ALL-UNNAMED", +-- "-jar", +-- vim.fn.glob(install_path .. "/plugins/org.eclipse.equinox.launcher_*.jar"), +-- "-configuration", +-- install_path .. "/config_" .. os, +-- "-data", +-- workspace_dir, +-- }, +-- capabilities = capabilities(), +-- root_dir = root_dir, +-- settings = { +-- java = {}, +-- }, +-- +-- init_options = { +-- bundles = bundles, +-- -- bundles = { +-- -- vim.fn.glob( +-- -- mason_path .. "packages/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar", +-- -- "\n" +-- -- ), +-- -- }, +-- }, +-- } +-- +-- config["on_attach"] = function(client, bufnr) +-- local _, _ = pcall(vim.lsp.codelens.refresh) +-- +-- -- valdation if DAP not installed +-- local dap_status, _ = pcall(require, "nvim-dap") +-- if not dap_status then +-- return +-- end +-- +-- require("jdtls.dap").setup_dap_main_class_configs() +-- jdtls.setup_dap({ hotcodereplace = "auto" }) +-- require("user.lsp.handlers").on_attach(client, bufnr) +-- end +-- +-- vim.api.nvim_create_autocmd({ "BufWritePost" }, { +-- pattern = { "*.java" }, +-- callback = function() +-- local _, _ = pcall(vim.lsp.codelens.refresh) +-- end, +-- }) +-- +-- jdtls.start_or_attach(config) +-- +-- vim.cmd( +-- [[command! -buffer -nargs=? -complete=custom,v:lua.require'jdtls'._complete_set_runtime JdtSetRuntime lua require('jdtls').set_runtime()]] +-- ) diff --git a/lazy-lock.json b/lazy-lock.json index e46d65d..7e86f2c 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -3,9 +3,8 @@ "FixCursorHold.nvim": { "branch": "master", "commit": "1900f89dc17c603eec29960f57c00bd9ae696495" }, "LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" }, "alpha-nvim": { "branch": "main", "commit": "41283fb402713fc8b327e60907f74e46166f4cfd" }, - "auto-save.nvim": { "branch": "main", "commit": "5fe9ab0c42f0457f2a973e814a6352b8eeb04730" }, "bigfile.nvim": { "branch": "main", "commit": "33eb067e3d7029ac77e081cfe7c45361887a311a" }, - "bufferline.nvim": { "branch": "main", "commit": "1662fed6ecd512d1f381fc2a4e77532c379d25c6" }, + "bufferline.nvim": { "branch": "main", "commit": "81820cac7c85e51e4cf179f8a66d13dbf7b032d9" }, "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, "cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" }, "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" }, @@ -14,13 +13,11 @@ "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, "code_runner.nvim": { "branch": "main", "commit": "6c5bfe44a6c7523350cd706e6b3b8101166eed99" }, "codeium.nvim": { "branch": "main", "commit": "d3b88eb3aa1de6da33d325c196b8a41da2bcc825" }, - "conform.nvim": { "branch": "master", "commit": "60e6fbddbdf37d7790de07dc7420beefaf650e5e" }, "dracula.nvim": { "branch": "main", "commit": "8d8bddb8814c3e7e62d80dda65a9876f97eb699c" }, "dressing.nvim": { "branch": "master", "commit": "71349f24c6e07b39f33600985843c289ca735308" }, "friendly-snippets": { "branch": "main", "commit": "682157939e57bd6a2c86277dfd4d6fbfce63dbac" }, "gitsigns.nvim": { "branch": "main", "commit": "0b04035bb7b3c83e999b9676e2fb46fd0aa9f910" }, "indent-blankline.nvim": { "branch": "master", "commit": "4036c8ae9cc29faf8e6443fa5b23e679db055d24" }, - "laravel.nvim": { "branch": "main", "commit": "8aaf614b5c8fc045f75ebc2ba69d68e33847b06d" }, "lazy.nvim": { "branch": "main", "commit": "378bfb465673a747e9e9f966e518063499e20cfe" }, "lsp-progress.nvim": { "branch": "main", "commit": "55a04895ea20c365b670051a3128265d43bdfa3d" }, "lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" }, @@ -30,7 +27,7 @@ "mini.indentscope": { "branch": "main", "commit": "56d42be090e8fcc68eda69cfe55af8c5e562300e" }, "neoscroll.nvim": { "branch": "master", "commit": "a731f66f1d39ec6175fd201c5bf849e54abda99c" }, "neotest": { "branch": "master", "commit": "f30bab1faef13d47f3905e065215c96a42d075ad" }, - "neotest-phpunit": { "branch": "main", "commit": "baae8dfa0a3aaacd9f0bb6845d6348f5bcdc48bb" }, + "neotest-java": { "branch": "main", "commit": "320f31c71b183f2c584198f33f93542fd0e5a768" }, "noice.nvim": { "branch": "main", "commit": "d580646db85f49b8226d52b143a458161f41954a" }, "none-ls-extras.nvim": { "branch": "main", "commit": "336e84b9e43c0effb735b08798ffac382920053b" }, "none-ls.nvim": { "branch": "main", "commit": "f1b438ab1709cf9d8875843559d20265013ac755" }, @@ -38,17 +35,14 @@ "nvim-autopairs": { "branch": "master", "commit": "c15de7e7981f1111642e7e53799e1211d4606cb9" }, "nvim-cmp": { "branch": "main", "commit": "a110e12d0b58eefcf5b771f533fc2cf3050680ac" }, "nvim-colorizer.lua": { "branch": "master", "commit": "85855b38011114929f4058efc97af1059ab3e41d" }, - "nvim-dap": { "branch": "master", "commit": "5ba8ceace596360321cf33fa4b56d9d46e057ce9" }, - "nvim-dap-ui": { "branch": "master", "commit": "f7d75cca202b52a60c520ec7b1ec3414d6e77b0f" }, - "nvim-lint": { "branch": "master", "commit": "941fa1220a61797a51f3af9ec6b7d74c8c7367ce" }, "nvim-lspconfig": { "branch": "master", "commit": "0b8165cf95806bc4bb8f745bb0c92021b2ed4b98" }, - "nvim-material-icon": { "branch": "main", "commit": "2f1d6333bbec2e787774193c9fc7b447b878069a" }, + "nvim-material-icon": { "branch": "main", "commit": "5ad42234d880659dfe9d4ff936c310cd6c5a1610" }, "nvim-navic": { "branch": "master", "commit": "8649f694d3e76ee10c19255dece6411c29206a54" }, "nvim-nio": { "branch": "master", "commit": "7969e0a8ffabdf210edd7978ec954a47a737bbcc" }, "nvim-notify": { "branch": "master", "commit": "d333b6f167900f6d9d42a59005d82919830626bf" }, "nvim-scrollview": { "branch": "main", "commit": "fd334e5ad0c616987d1b9114890a59c97165cf83" }, "nvim-tree.lua": { "branch": "master", "commit": "2086e564c4d23fea714e8a6d63b881e551af2f41" }, - "nvim-treesitter": { "branch": "master", "commit": "d4a888ae3cff358cb239643c45b2b38bb60e29c6" }, + "nvim-treesitter": { "branch": "master", "commit": "09700b88b41ed96391de3d2010d74dc54fd5c210" }, "nvim-treesitter-context": { "branch": "master", "commit": "5efba33af0f39942e426340da7bc15d7dec16474" }, "nvim-treesitter-textobjects": { "branch": "master", "commit": "34867c69838078df7d6919b130c0541c0b400c47" }, "nvim-ts-autotag": { "branch": "main", "commit": "ddfccbf0df1b9349c2b9e9b17f4afa8f9b6c1ed1" }, @@ -61,12 +55,11 @@ "smart-splits.nvim": { "branch": "master", "commit": "66fda3a601a5b4c679656f15eb6ddd613c8d3216" }, "telescope.nvim": { "branch": "master", "commit": "58ec6eca1c3704d130d749843e16fbf6c8cdc57e" }, "tiny-devicons-auto-colors.nvim": { "branch": "main", "commit": "9be4af5b1bc1f26a11206ed7ce8bf44312e7941a" }, - "toggleterm.nvim": { "branch": "main", "commit": "fee58a0473fd92b28c34f8f724e4918b15ba30a3" }, + "toggleterm.nvim": { "branch": "main", "commit": "cd55bf6aab3f88c259fa29ea86bbdcb1a325687d" }, "vim-illuminate": { "branch": "master", "commit": "5eeb7951fc630682c322e88a9bbdae5c224ff0aa" }, "vim-startuptime": { "branch": "master", "commit": "97a88e688482a09c3c4b777d07b509b328a5ec29" }, "vim-visual-multi": { "branch": "master", "commit": "b84a6d42c1c10678928b0bf8327f378c8bc8af5a" }, "virt-column.nvim": { "branch": "master", "commit": "b62b4ef0774d19452d4ed18e473e824c7a756f2f" }, - "vscode-php-debug": { "branch": "main", "commit": "3025d1f01b5b7725e7c1c213d63f3de45f0534b3" }, "which-key.nvim": { "branch": "main", "commit": "0539da005b98b02cf730c1d9da82b8e8edb1c2d2" }, "yanky.nvim": { "branch": "main", "commit": "9268018e92d02650a94e39dd5f5903c542f7ea11" } } \ No newline at end of file diff --git a/lua/custom/default.lua b/lua/custom/default.lua index 9317a20..d4189f0 100644 --- a/lua/custom/default.lua +++ b/lua/custom/default.lua @@ -65,7 +65,7 @@ pcode.mason_ensure_installed = { -- sebelumnya register_lsp -- tambahkan di bawah sini setelah melakukan :masoninstall } pcode.unregister_lsp = { - "jdtls", -- tambahkan di bawah ini + -- "jdtls", -- tambahkan di bawah ini } -- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/BUILTINS.md @@ -129,7 +129,7 @@ pcode.adaptive_color_icon = true pcode.columnline = true -- https://github.com/okuuva/auto-save.nvim -pcode.auto_save = true +pcode.auto_save = false -- https://github.com/folke/todo-comments.nvim pcode.todo_comment = false @@ -162,11 +162,11 @@ pcode.active_javascript_config = { jest_command = "npm test -- ", jest_config = "jest.config.mjs", } -pcode.active_php_config = true +pcode.active_php_config = false pcode.active_golang_config = false pcode.active_python_config = false pcode.active_cpp_config = false pcode.active_java_config = { - active = false, + active = true, project = "gradle", -- gradle or maven } diff --git a/lua/plugins/java.lua b/lua/plugins/java.lua index e5c49d0..56b375d 100644 --- a/lua/plugins/java.lua +++ b/lua/plugins/java.lua @@ -1,9 +1,9 @@ local M = {} if pcode.active_java_config.active then M = { - { - "mfussenegger/nvim-jdtls", - }, + -- { + -- "mfussenegger/nvim-jdtls", + -- }, { "nvim-neotest/neotest", dependencies = { @@ -46,33 +46,33 @@ if pcode.active_java_config.active then { "TS", function() require("neotest").run.stop() end, desc = "Stop" }, }, }, - { - "stevearc/conform.nvim", - event = { "BufReadPre", "BufNewFile" }, - opts = function(_, opts) - local psave = pcode.format_on_save or 0 - opts.formatters_by_ft = opts.formatters_by_ft or {} - opts.formatters_by_ft.java = { "lsp_fmt" } - if psave == 1 then - opts.format_on_save = { - timeout_ms = pcode.format_timeout_ms or 500, - lsp_fallback = true, - } - end - return opts - end, - config = function(_, opts) - local conform = require("conform") - conform.setup(opts) - vim.keymap.set({ "n", "v" }, "lF", function() - conform.format({ - lsp_fallback = true, - async = false, - timeout_ms = pcode.format_timeout_ms or 500, - }) - end, { desc = "Format file or range (in visual mode)" }) - end, - }, + -- { + -- "stevearc/conform.nvim", + -- event = { "BufReadPre", "BufNewFile" }, + -- opts = function(_, opts) + -- local psave = pcode.format_on_save or 0 + -- opts.formatters_by_ft = opts.formatters_by_ft or {} + -- opts.formatters_by_ft.java = { "lsp_fmt" } + -- if psave == 1 then + -- opts.format_on_save = { + -- timeout_ms = pcode.format_timeout_ms or 500, + -- lsp_fallback = true, + -- } + -- end + -- return opts + -- end, + -- config = function(_, opts) + -- local conform = require("conform") + -- conform.setup(opts) + -- vim.keymap.set({ "n", "v" }, "lF", function() + -- conform.format({ + -- lsp_fallback = true, + -- async = false, + -- timeout_ms = pcode.format_timeout_ms or 500, + -- }) + -- end, { desc = "Format file or range (in visual mode)" }) + -- end, + -- }, } end return M diff --git a/lua/plugins/themes/_globalvar.lua b/lua/plugins/themes/_globalvar.lua index 12fd4e6..f2923d2 100644 --- a/lua/plugins/themes/_globalvar.lua +++ b/lua/plugins/themes/_globalvar.lua @@ -99,7 +99,8 @@ end if pcode.active_java_config.active then table.insert(pcode.treesitter_ensure_installed, "java") table.insert(pcode.mason_ensure_installed, "jdtls") - table.insert(pcode.dap_ensure_installed, "javadbg") - table.insert(pcode.unregister_lsp, "jdtls") + table.insert(pcode.null_ls_ensure_installed, "google_java_format") + -- table.insert(pcode.dap_ensure_installed, "javadbg") + -- table.insert(pcode.unregister_lsp, "jdtls") end return {} diff --git a/lua/user/lsp/settings/jdtls.lua b/lua/user/lsp/settings/jdtls.lua new file mode 100644 index 0000000..2c455de --- /dev/null +++ b/lua/user/lsp/settings/jdtls.lua @@ -0,0 +1,15 @@ +return { + filetypes = { "java" }, + root_dir = require("lspconfig.util").root_pattern( + -- Single-module projects + { + "build.xml", -- Ant + "pom.xml", -- Maven + "settings.gradle", -- Gradle + "settings.gradle.kts", -- Gradle + }, + -- Multi-module projects + { "build.gradle", "build.gradle.kts" } + ) or vim.fn.getcwd(), + singe_file_support = true, +}