diff --git a/lazy-lock.json b/lazy-lock.json index ef32cdc..5ee0b4f 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -28,14 +28,13 @@ "mini.indentscope": { "branch": "main", "commit": "56d42be090e8fcc68eda69cfe55af8c5e562300e" }, "neoscroll.nvim": { "branch": "master", "commit": "a731f66f1d39ec6175fd201c5bf849e54abda99c" }, "neotest": { "branch": "master", "commit": "f30bab1faef13d47f3905e065215c96a42d075ad" }, - "neotest-python": { "branch": "master", "commit": "2e83d2bc00acbcc1fd529dbf0a0e677cabfe6b50" }, + "neotest-java": { "branch": "main", "commit": "320f31c71b183f2c584198f33f93542fd0e5a768" }, "noice.nvim": { "branch": "main", "commit": "03c6a75661e68012e30b0ed81f050358b1e2233c" }, "nui.nvim": { "branch": "main", "commit": "a0fd35fcbb4cb479366f1dc5f20145fd718a3733" }, "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-python": { "branch": "master", "commit": "d777c2b32ed39f61209c09bede28d7491621a631" }, "nvim-dap-ui": { "branch": "master", "commit": "f7d75cca202b52a60c520ec7b1ec3414d6e77b0f" }, "nvim-dap-virtual-text": { "branch": "master", "commit": "d7c695ea39542f6da94ee4d66176f5d660ab0a77" }, "nvim-lint": { "branch": "master", "commit": "efc6fc83f0772283e064c53a8f9fb5645bde0bc0" }, @@ -46,7 +45,7 @@ "nvim-notify": { "branch": "master", "commit": "d333b6f167900f6d9d42a59005d82919830626bf" }, "nvim-scrollview": { "branch": "main", "commit": "06563ae0c9928a2df42aefe66f2aed2f2943e32e" }, "nvim-tree.lua": { "branch": "master", "commit": "2086e564c4d23fea714e8a6d63b881e551af2f41" }, - "nvim-treesitter": { "branch": "master", "commit": "c11d49cbefb3c22550747840843eb86ab4a3b267" }, + "nvim-treesitter": { "branch": "master", "commit": "cf7baac35aa5c103b960bcb3f15c690a4aa5c6f1" }, "nvim-treesitter-textobjects": { "branch": "master", "commit": "34867c69838078df7d6919b130c0541c0b400c47" }, "nvim-ts-autotag": { "branch": "main", "commit": "ddfccbf0df1b9349c2b9e9b17f4afa8f9b6c1ed1" }, "nvim-ts-context-commentstring": { "branch": "main", "commit": "cb064386e667def1d241317deed9fd1b38f0dc2e" }, diff --git a/lua/custom/default.lua b/lua/custom/default.lua index 11ca8d3..4ea9586 100644 --- a/lua/custom/default.lua +++ b/lua/custom/default.lua @@ -70,7 +70,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 @@ -169,10 +169,9 @@ pcode.active_javascript_config = { } pcode.active_php_config = false pcode.active_golang_config = false -pcode.active_python_config = true +pcode.active_python_config = false pcode.active_cpp_config = false pcode.active_java_config = { - active = false, + active = true, project = "gradle", -- gradle or maven - use_nvim_jdtls = true, -- mfussenegger/nvim-jdtls } diff --git a/lua/plugins/cppcfg.lua b/lua/plugins/cppcfg.lua index 561a834..5bb7318 100644 --- a/lua/plugins/cppcfg.lua +++ b/lua/plugins/cppcfg.lua @@ -4,36 +4,12 @@ local M = {} if pcode.active_cpp_config then M = { { - "nvim-treesitter/nvim-treesitter", + "nvimtools/none-ls.nvim", + optional = true, opts = function(_, opts) - opts.ensure_installed = opts.ensure_installed or {} - vim.list_extend(opts.ensure_installed, { "cpp", "c" }) - end, - }, - { - "williamboman/mason-lspconfig.nvim", - opts = function(_, opts) - opts.ensure_installed = opts.ensure_installed or {} - vim.list_extend(opts.ensure_installed, { "clangd" }) - require("user.utils.masoncfg").try_install("clang-format") - end, - }, - { - "jay-babu/mason-nvim-dap.nvim", - event = "VeryLazy", - opts = function(_, opts) - opts.ensure_installed = opts.ensure_installed or {} - vim.list_extend(opts.ensure_installed, { "codelldb" }) - end, - }, - { - "stevearc/conform.nvim", - event = "VeryLazy", - opts = function(_, opts) - local package = "clang-format" - require("user.utils.masoncfg").try_install(package) - opts.formatters_by_ft.cpp = { package } - opts.formatters_by_ft.c = { package } + local nls = require("null-ls") + opts.sources = opts.sources or {} + table.insert(opts.sources, nls.builtins.formatting.clang_format.with({ filetypes = { "cpp", "c" } })) end, }, { diff --git a/lua/plugins/dap.lua b/lua/plugins/dap.lua index 51b0bfe..0bbf8db 100644 --- a/lua/plugins/dap.lua +++ b/lua/plugins/dap.lua @@ -1,5 +1,5 @@ local M = {} -if pcode.nvim_dap or pcode.active_cpp_config then +if pcode.nvim_dap then M = { { "rcarriga/nvim-dap-ui", @@ -42,25 +42,9 @@ if pcode.nvim_dap or pcode.active_cpp_config then lazy = true, event = "BufRead", dependencies = { "williamboman/mason.nvim", "mfussenegger/nvim-dap" }, - opts = function(_, opts) - local dap_data = pcode.dap_ensure_installed or {} - opts.ensure_installed = opts.ensure_installed or {} - vim.list_extend(opts.ensure_installed, dap_data) - opts.automatic_setup = true - opts.handlers = { - function(config) - -- all sources with no handler get passed here - - -- Keep original functionality - require("mason-nvim-dap").default_setup(config) - end, - } - return opts - end, -- enabled = vim.fn.has("win32") == 0, - config = function(_, opts) - require("mason").setup() - require("mason-nvim-dap").setup(opts) + config = function() + require("user.mason_dap") end, }, } diff --git a/lua/plugins/java.lua b/lua/plugins/java.lua index 1e83c8a..f1c1fa8 100644 --- a/lua/plugins/java.lua +++ b/lua/plugins/java.lua @@ -1,186 +1,9 @@ local M = {} -local java_filetypes = { "java" } -local root_markers = { ".git", "mvnw", "gradlew", "pom.xml", "build.gradle" } - --- Utility function to extend or override a config table, similar to the way --- that Plugin.opts works. ----@param config table ----@param custom function | table | nil -local function extend_or_override(config, custom, ...) - if type(custom) == "function" then - config = custom(config, ...) or config - elseif custom then - config = vim.tbl_deep_extend("force", config, custom) --[[@as table]] - end - return config -end - if pcode.active_java_config.active then M = { - { - "mfussenegger/nvim-jdtls", - ft = java_filetypes, - enabled = pcode.active_java_config.use_nvim_jdtls or false, - opts = function() - return { - root_dir = require("jdtls.setup").find_root(root_markers), - project_name = function() - return vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t") - end, - - -- Where are the config and workspace dirs for a project? - jdtls_config_dir = function(project_name) - return vim.fn.stdpath("cache") .. "/jdtls/" .. project_name .. "/config" - end, - jdtls_workspace_dir = function(project_name) - return vim.fn.stdpath("cache") .. "/jdtls/" .. project_name .. "/workspace" - end, - cmd = { vim.fn.exepath("jdtls") }, - full_cmd = function(opts) - local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t") - local cmd = vim.deepcopy(opts.cmd) - if project_name then - vim.list_extend(cmd, { - "-configuration", - opts.jdtls_config_dir(project_name), - "-data", - opts.jdtls_workspace_dir(project_name), - }) - end - return cmd - end, - - -- These depend on nvim-dap, but can additionally be disabled by setting false here. - dap = { hotcodereplace = "auto", config_overrides = {} }, - dap_main = {}, - test = true, - settings = { - java = { - inlayHints = { - parameterNames = { - enabled = "all", - }, - }, - }, - }, - } - end, - config = function(_, opts) - 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 mason_registry = require("mason-registry") - local bundles = {} ---@type string[] - if opts.dap and mason_registry.is_installed("java-debug-adapter") then - local java_dbg_pkg = mason_registry.get_package("java-debug-adapter") - local java_dbg_path = java_dbg_pkg:get_install_path() - local jar_patterns = { - java_dbg_path .. "/extension/server/com.microsoft.java.debug.plugin-*.jar", - } - -- java-test also depends on java-debug-adapter. - if opts.test and mason_registry.is_installed("java-test") then - local java_test_pkg = mason_registry.get_package("java-test") - local java_test_path = java_test_pkg:get_install_path() - vim.list_extend(jar_patterns, { - java_test_path .. "/extension/server/*.jar", - }) - end - for _, jar_pattern in ipairs(jar_patterns) do - for _, bundle in ipairs(vim.split(vim.fn.glob(jar_pattern), "\n")) do - table.insert(bundles, bundle) - end - end - end - - local function attach_jdtls() - local fname = vim.api.nvim_buf_get_name(0) - - -- Configuration can be augmented and overridden by opts.jdtls - local config = extend_or_override({ - cmd = opts.full_cmd(opts), - root_dir = require("jdtls.setup").find_root(root_markers), - init_options = { - bundles = bundles, - }, - settings = opts.settings, - -- enable CMP capabilities - capabilities = require("user.lsp.handlers").capabilities or nil, - }, opts.jdtls) - - -- Existing server will be reused if the root_dir matches. - require("jdtls").start_or_attach(config) - -- not need to require("jdtls.setup").add_commands(), start automatically adds commands - end - - vim.api.nvim_create_autocmd("FileType", { - pattern = java_filetypes, - callback = attach_jdtls, - }) - - -- Setup keymap and dap after the lsp is fully attached. - -- https://github.com/mfussenegger/nvim-jdtls#nvim-dap-configuration - -- https://neovim.io/doc/user/lsp.html#LspAttach - vim.api.nvim_create_autocmd("LspAttach", { - callback = function(args) - local client = vim.lsp.get_client_by_id(args.data.client_id) - if client and client.name == "jdtls" then - local wk = require("which-key") - wk.register({ - ["cx"] = { name = "+extract" }, - ["cxv"] = { require("jdtls").extract_variable_all, "Extract Variable" }, - ["cxc"] = { require("jdtls").extract_constant, "Extract Constant" }, - ["gs"] = { require("jdtls").super_implementation, "Goto Super" }, - ["co"] = { require("jdtls").organize_imports, "Organize Imports" }, - }, { mode = "n", buffer = args.buf }) - wk.register({ - ["c"] = { name = "+code" }, - ["cx"] = { name = "+extract" }, - ["cxm"] = { - [[lua require('jdtls').extract_method(true)]], - "Extract Method", - }, - ["cxv"] = { - [[lua require('jdtls').extract_variable_all(true)]], - "Extract Variable", - }, - ["cxc"] = { - [[lua require('jdtls').extract_constant(true)]], - "Extract Constant", - }, - }, { mode = "v", buffer = args.buf }) - - if opts.dap and mason_registry.is_installed("java-debug-adapter") then - -- custom init for Java debugger - require("jdtls").setup_dap(opts.dap) - require("jdtls.dap").setup_dap_main_class_configs(opts.dap_main) - - -- Java Test require Java debugger to work - if opts.test and mason_registry.is_installed("java-test") then - -- custom keymaps for Java test runner (not yet compatible with neotest) - wk.register({ - ["t"] = { name = "+test" }, - ["tt"] = { require("jdtls.dap").test_class, "Run All Test" }, - ["tr"] = { require("jdtls.dap").test_nearest_method, "Run Nearest Test" }, - ["tT"] = { require("jdtls.dap").pick_test, "Run Test" }, - }, { mode = "n", buffer = args.buf }) - end - end - - -- User can set additional keymaps in opts.on_attach - if opts.on_attach then - opts.on_attach(args) - end - end - end, - }) - - -- Avoid race condition by calling attach the first time, since the autocmd won't fire. - attach_jdtls() - end, - }, + -- { + -- "mfussenegger/nvim-jdtls", + -- }, { "nvim-treesitter/nvim-treesitter", opts = function(_, opts) @@ -195,16 +18,15 @@ if pcode.active_java_config.active then vim.list_extend(opts.ensure_installed, { "jdtls" }) end, }, - -- { - -- "stevearc/conform.nvim", - -- event = "VeryLazy", - -- opts = function(_, opts) - -- local package = "lsp_fmt" - -- require("user.utils.masoncfg").try_install("java-debug-adapter") - -- require("user.utils.masoncfg").try_install("java-test") - -- opts.formatters_by_ft.java = { package } - -- end, - -- }, + { + "stevearc/conform.nvim", + event = "VeryLazy", + opts = function(_, opts) + local package="google-java-format" + require("user.utils.mason").try_install(package) + opts.formatters_by_ft.java = { package } + end, + }, { "nvim-neotest/neotest", dependencies = { @@ -247,48 +69,33 @@ if pcode.active_java_config.active then { "TS", function() require("neotest").run.stop() end, desc = "Stop" }, }, }, - { - "rockerBOO/symbols-outline.nvim", - cmd = "SymbolsOutline", - config = function() - require("symbols-outline").setup({ - symbols = { - File = { icon = "󰈔", hl = "@text.uri" }, - Module = { icon = "", hl = "@namespace" }, - Namespace = { icon = "󰅪", hl = "@namespace" }, - Package = { icon = "", hl = "@namespace" }, - Class = { icon = "𝓒", hl = "@type" }, - Method = { icon = "ƒ", hl = "@method" }, - Property = { icon = "", hl = "@method" }, - Field = { icon = "", hl = "@field" }, - Constructor = { icon = "", hl = "@constructor" }, - Enum = { icon = "ℰ", hl = "@type" }, - Interface = { icon = "", hl = "@type" }, - Function = { icon = "", hl = "@function" }, - Variable = { icon = "", hl = "@constant" }, - Constant = { icon = "", hl = "@constant" }, - String = { icon = "𝓐", hl = "@string" }, - Number = { icon = "#", hl = "@number" }, - Boolean = { icon = "󰨙 ", hl = "@boolean" }, - Array = { icon = "", hl = "@constant" }, - Object = { icon = "⦿", hl = "@type" }, - Key = { icon = "🔐", hl = "@type" }, - Null = { icon = "NULL", hl = "@type" }, - EnumMember = { icon = "", hl = "@field" }, - Struct = { icon = "𝓢", hl = "@type" }, - Event = { icon = "🗲", hl = "@type" }, - Operator = { icon = "+", hl = "@operator" }, - TypeParameter = { icon = "𝙏", hl = "@parameter" }, - Component = { icon = "󰅴", hl = "@function" }, - Fragment = { icon = "󰅴", hl = "@constant" }, - }, - }) - end, - keys = { - { "S", "SymbolsOutline", desc = "Toggle Outline" }, - }, - }, + -- { + -- "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/python.lua b/lua/plugins/python.lua index 9a1ed40..e603afa 100644 --- a/lua/plugins/python.lua +++ b/lua/plugins/python.lua @@ -102,31 +102,6 @@ if pcode.active_python_config then { "TS", function() require("neotest").run.stop() end, desc = "Stop" }, }, }, - { - "nvim-treesitter/nvim-treesitter", - opts = function(_, opts) - opts.ensure_installed = opts.ensure_installed or {} - vim.list_extend(opts.ensure_installed, { "python" }) - end, - }, - { - "williamboman/mason-lspconfig.nvim", - opts = function(_, opts) - opts.ensure_installed = opts.ensure_installed or {} - vim.list_extend(opts.ensure_installed, { "pyright" }) - end, - }, - { - "stevearc/conform.nvim", - event = "VeryLazy", - opts = function(_, opts) - local package = "black" - require("user.utils.masoncfg").try_install("flake8") - require("user.utils.masoncfg").try_install("black") - require("user.utils.masoncfg").try_install("debugpy") - opts.formatters_by_ft.python = { package } - end, - }, } if vim.fn.has("win32") ~= 0 then table.insert(M, nvim_dap) diff --git a/lua/plugins/themes/_globalvar.lua b/lua/plugins/themes/_globalvar.lua index d3a1225..c5bed85 100644 --- a/lua/plugins/themes/_globalvar.lua +++ b/lua/plugins/themes/_globalvar.lua @@ -92,29 +92,29 @@ if pcode.active_golang_config then end -- run if python config true if pcode.active_python_config then - -- table.insert(pcode.treesitter_ensure_installed, "python") - -- table.insert(pcode.mason_ensure_installed, "pyright") - -- table.insert(pcode.null_ls_ensure_installed, "flake8") - -- table.insert(pcode.null_ls_ensure_installed, "black") + table.insert(pcode.treesitter_ensure_installed, "python") + table.insert(pcode.mason_ensure_installed, "pyright") + table.insert(pcode.null_ls_ensure_installed, "flake8") + table.insert(pcode.null_ls_ensure_installed, "black") if vim.fn.has("win32") ~= 1 then pcode.nvim_dap = true end end -- run if cpp config true --- if pcode.active_cpp_config then --- table.insert(pcode.treesitter_ensure_installed, "cpp") --- table.insert(pcode.treesitter_ensure_installed, "c") --- table.insert(pcode.mason_ensure_installed, "clangd") --- table.insert(pcode.null_ls_ensure_installed, "clang_format") --- table.insert(pcode.dap_ensure_installed, "codelldb") --- pcode.nvim_dap = true --- end --- run if java config true -if pcode.active_java_config.active and pcode.active_java_config.use_nvim_jdtls then - -- table.insert(pcode.treesitter_ensure_installed, "java") - -- table.insert(pcode.mason_ensure_installed, "jdtls") - -- table.insert(pcode.null_ls_ensure_installed, "google_java_format") - -- table.insert(pcode.dap_ensure_installed, "javadbg") - table.insert(pcode.unregister_lsp, "jdtls") +if pcode.active_cpp_config then + table.insert(pcode.treesitter_ensure_installed, "cpp") + table.insert(pcode.treesitter_ensure_installed, "c") + table.insert(pcode.mason_ensure_installed, "clangd") + table.insert(pcode.null_ls_ensure_installed, "clang_format") + table.insert(pcode.dap_ensure_installed, "codelldb") + pcode.nvim_dap = true end +-- run if java config true +-- if pcode.active_java_config.active then +-- table.insert(pcode.treesitter_ensure_installed, "java") +-- table.insert(pcode.mason_ensure_installed, "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/utils/mason.lua b/lua/user/utils/mason.lua new file mode 100644 index 0000000..7ff3f7b --- /dev/null +++ b/lua/user/utils/mason.lua @@ -0,0 +1,56 @@ +local registry = require("mason-registry") + +local M = {} + +local function resolve_package(mason_package_name) + local Optional = require("mason-core.optional") + + local ok, pkg = pcall(registry.get_package, mason_package_name) + if ok then + return Optional.of_nilable(pkg) + end +end + +local function install_package(pkg, version) + local linter_name = pkg.name + + vim.notify(("[mason-conform] installing %s"):format(linter_name)) + + return pkg:install({ version = version }):once( + "closed", + vim.schedule_wrap(function() + if pkg:is_installed() then + vim.notify(("[mason-conform] %s was successfully installed"):format(linter_name)) + else + vim.notify( + ("[mason-conform] failed to install %s. Installation logs are available in :Mason and :MasonLog"):format( + linter_name + ), + vim.log.levels.ERROR + ) + end + end) + ) +end + +function M.try_install(mason_package_name) + local Package = require("mason-core.package") + local package_name, version = Package.Parse(mason_package_name) + + resolve_package(package_name) + :if_present(function(pkg) + if not pkg:is_installed() then + install_package(pkg, version) + end + end) + :if_not_present(function() + vim.notify( + ("[mason-conform] Formatter %q is not a valid entry in ensure_installed. Make sure to only provide valid formatter names."):format( + package_name + ), + vim.log.levels.WARN + ) + end) +end + +return M