diff --git a/lazy-lock.json b/lazy-lock.json index e8e4491..0a9a4a4 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -18,16 +18,17 @@ "friendly-snippets": { "branch": "main", "commit": "682157939e57bd6a2c86277dfd4d6fbfce63dbac" }, "gitsigns.nvim": { "branch": "main", "commit": "0b04035bb7b3c83e999b9676e2fb46fd0aa9f910" }, "indent-blankline.nvim": { "branch": "master", "commit": "d98f537c3492e87b6dc6c2e3f66ac517528f406f" }, - "lazy.nvim": { "branch": "main", "commit": "c501b429cf995c645454539b924aaefae45bb9eb" }, + "lazy.nvim": { "branch": "main", "commit": "4ea9fe060042f345960ad0c01aa7bca91405e10a" }, "lsp-progress.nvim": { "branch": "main", "commit": "55a04895ea20c365b670051a3128265d43bdfa3d" }, "lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "9ae570e206360e47d30b4c35a4550c165f4ea7b7" }, "mason-null-ls.nvim": { "branch": "main", "commit": "2b8433f76598397fcc97318d410e0c4f7a4bea6a" }, + "mason-nvim-dap.nvim": { "branch": "main", "commit": "f5425eb1d0d794f0305d5eeebddabb74614683ff" }, "mason.nvim": { "branch": "main", "commit": "c43eeb5614a09dc17c03a7fb49de2e05de203924" }, - "mini.indentscope": { "branch": "main", "commit": "f0d7faa064c892b96997810afcddfadc3f2a15b3" }, + "mini.indentscope": { "branch": "main", "commit": "f15c61e71318b16c6616c2ace907136b76674f13" }, "neoscroll.nvim": { "branch": "master", "commit": "a731f66f1d39ec6175fd201c5bf849e54abda99c" }, "neotest": { "branch": "master", "commit": "f30bab1faef13d47f3905e065215c96a42d075ad" }, - "neotest-gtest": { "branch": "main", "commit": "b44c8afc26cea75ffc80617ce07b4e745a56e589" }, + "neotest-java": { "branch": "main", "commit": "320f31c71b183f2c584198f33f93542fd0e5a768" }, "noice.nvim": { "branch": "main", "commit": "8f1d9966762e62fa8788e5fb1a5f6a86784221d9" }, "none-ls-extras.nvim": { "branch": "main", "commit": "336e84b9e43c0effb735b08798ffac382920053b" }, "none-ls.nvim": { "branch": "main", "commit": "f1b438ab1709cf9d8875843559d20265013ac755" }, @@ -35,6 +36,10 @@ "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-dap-virtual-text": { "branch": "master", "commit": "d7c695ea39542f6da94ee4d66176f5d660ab0a77" }, + "nvim-jdtls": { "branch": "master", "commit": "a5c6f38f8151d7b4f5b32c005a95022fa66f4c9d" }, "nvim-lspconfig": { "branch": "master", "commit": "0b8165cf95806bc4bb8f745bb0c92021b2ed4b98" }, "nvim-material-icon": { "branch": "main", "commit": "2f1d6333bbec2e787774193c9fc7b447b878069a" }, "nvim-navic": { "branch": "master", "commit": "8649f694d3e76ee10c19255dece6411c29206a54" }, diff --git a/lua/custom/default.lua b/lua/custom/default.lua index 863f88d..f644e1e 100644 --- a/lua/custom/default.lua +++ b/lua/custom/default.lua @@ -159,4 +159,8 @@ pcode.active_javascript_config = { pcode.active_php_config = false pcode.active_golang_config = false pcode.active_python_config = false -pcode.active_cpp_config = true +pcode.active_cpp_config = false +pcode.active_java_config = { + active = true, + project = "gradle", -- gradle or maven +} diff --git a/lua/custom/null-ls.lua b/lua/custom/null-ls.lua index 44ecda1..5bafac0 100644 --- a/lua/custom/null-ls.lua +++ b/lua/custom/null-ls.lua @@ -1,9 +1,10 @@ local null_ls = require("null-ls") local m = { sources = { - null_ls.builtins.formatting.stylua, -- tambahkan di bawah sini - -- null_ls.builtins.diagnostics.flake8, -- tambahkan di bawah sini - -- null_ls.builtins.formatting.blade_formatter.with({ filetypes = { "blade", "php" } }), + -- null_ls.builtins.formatting.stylua, -- tambahkan di bawah sini + -- null_ls.builtins.formatting.clang_format.with({ filetypes = { "c", "cpp" } }), + --null_ls.builtins.diagnostics.flake8, -- tambahkan di bawah sini + --null_ls.builtins.formatting.blade_formatter.with({ filetypes = { "blade", "php" } }), }, } return m diff --git a/lua/plugins/cppcfg.lua b/lua/plugins/cppcfg.lua index f8b806a..5bb7318 100644 --- a/lua/plugins/cppcfg.lua +++ b/lua/plugins/cppcfg.lua @@ -3,6 +3,15 @@ local M = {} -- local file_name_no_ext = vim.fn.expand("%:t:r") if pcode.active_cpp_config then M = { + { + "nvimtools/none-ls.nvim", + optional = true, + opts = function(_, opts) + local nls = require("null-ls") + opts.sources = opts.sources or {} + table.insert(opts.sources, nls.builtins.formatting.clang_format.with({ filetypes = { "cpp", "c" } })) + end, + }, { "nvim-neotest/neotest", ft = { "cpp" }, diff --git a/lua/plugins/java.lua b/lua/plugins/java.lua new file mode 100644 index 0000000..6d98eab --- /dev/null +++ b/lua/plugins/java.lua @@ -0,0 +1,107 @@ +local M = {} +if pcode.active_java_config.active then + M = { + { + "mfussenegger/nvim-jdtls", + }, + { + "nvim-neotest/neotest", + dependencies = { + "nvim-neotest/nvim-nio", + "nvim-lua/plenary.nvim", + "antoinemadec/FixCursorHold.nvim", + "nvim-treesitter/nvim-treesitter", + "andy-bell101/neotest-java", + }, + config = function() + require("neotest").setup({ + adapters = { + require("neotest-java")({ + -- function to determine which runner to use based on project path + determine_runner = function(project_root_path) + -- return should be "maven" or "gradle" + return pcode.active_java_config.project or "gradle" + end, + -- override the builtin runner discovery behaviour to always use given + -- tool. Default is "nil", so no override + force_runner = nil, + -- if the automatic runner discovery can't uniquely determine whether + -- to use Gradle or Maven, fallback to using this runner. Default is + -- "gradle" + fallback_runner = pcode.active_java_config.project or "gradle", + }), + }, + }) + end, + -- stylua: ignore + keys = { + { "T","",desc="  Test"}, + { "Tt", function() require("neotest").run.run(vim.fn.expand("%")) end, desc = "Run File" }, + { "Tr", function() require("neotest").run.run() end, desc = "Run Nearest" }, + { "TT", function() require("neotest").run.run(vim.loop.cwd()) end, desc = "Run All Test Files" }, + { "Tl", function() require("neotest").run.run_last() end, desc = "Run Last" }, + { "Ts", function() require("neotest").summary.toggle() end, desc = "Toggle Summary" }, + { "To", function() require("neotest").output.open({ enter = true, auto_close = true }) end, desc = "Show Output" }, + { "TO", function() require("neotest").output_panel.toggle() end, desc = "Toggle Output Panel" }, + { "TS", function() require("neotest").run.stop() end, desc = "Stop" }, + }, + }, + { + "mfussenegger/nvim-dap", + event = "BufReadPre", + dependencies = { + "rcarriga/nvim-dap-ui", + "theHamsta/nvim-dap-virtual-text", + "nvim-neotest/nvim-nio", + "williamboman/mason.nvim", + "jay-babu/mason-nvim-dap.nvim", + }, + config = function() + require("user.dapui") + local dap = require("dap") + local util = require("jdtls.util") + dap.adapters.java = function(callback) + util.execute_command({ command = "vscode.java.startDebugSession" }, function(err0, port) + if err0 ~= nil then + return + end + callback({ type = "server", host = "127.0.0.1", port = port }) + end) + end + dap.configurations.java = { + { + type = "java", + request = "launch", + name = "Debug Java", + program = "${file}", + args = {}, + cwd = vim.fn.getcwd(), + stopOnEntry = false, + console = "integratedTerminal", + internalConsoleOptions = "neverOpen", + sourceMaps = true, + outDir = "${workspaceFolder}/out", + }, + } + end, + keys = { + { "d", "", desc = "  Debug" }, + { "dt", "lua require'dap'.toggle_breakpoint()", desc = "Toggle Breakpoint" }, + { "db", "lua require'dap'.step_back()", desc = "Step Back" }, + { "dc", "lua require'dap'.continue()", desc = "Continue" }, + { "dC", "lua require'dap'.run_to_cursor()", desc = "Run To Cursor" }, + { "dd", "lua require'dap'.disconnect()", desc = "Disconnect" }, + { "dg", "lua require'dap'.session()", desc = "Get Session" }, + { "di", "lua require'dap'.step_into()", desc = "Step Into" }, + { "do", "lua require'dap'.step_over()", desc = "Step Over" }, + { "du", "lua require'dap'.step_out()", desc = "Step Out" }, + { "dp", "lua require'dap'.pause()", desc = "Pause" }, + { "dr", "lua require'dap'.repl.toggle()", desc = "Toggle Repl" }, + { "ds", "lua require'dap'.continue()", desc = "Start" }, + { "dq", "lua require'dap'.close()", desc = "Quit" }, + { "dU", "lua require'dapui'.toggle({reset = true})", desc = "Toggle UI" }, + }, + }, + } +end +return M diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index 3033d54..9514de8 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -27,22 +27,4 @@ return { require("user.lsp") end, }, - { - "jayp0521/mason-null-ls.nvim", - lazy = true, - dependencies = { - "nvimtools/none-ls.nvim", - dependencies = { - "nvimtools/none-ls-extras.nvim", - lazy = true, - }, - config = function() - require("user.lsp.null-lscfg") - end, - }, - event = "InsertEnter", - opts = function() - require("user.mason-null-ls") - end, - }, } diff --git a/lua/plugins/nonels.lua b/lua/plugins/nonels.lua new file mode 100644 index 0000000..c8974cf --- /dev/null +++ b/lua/plugins/nonels.lua @@ -0,0 +1,58 @@ +return { + { + "nvimtools/none-ls.nvim", + lazy = true, + dependencies = { + { + "jayp0521/mason-null-ls.nvim", + opts = { + ensure_installed = pcode.null_ls_ensure_installed or {}, + automatic_setup = true, + handlers = {}, + }, + config = function(_, opts) + require("mason-null-ls").setup(opts) + end, + }, + "nvimtools/none-ls-extras.nvim", + }, + event = "InsertEnter", + opts = function() + local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) + local sources = {} + local data_ok, data_sources = pcall(require, "custom.null-ls") + if data_ok then + for _, cfg in pairs(data_sources.sources) do + table.insert(sources, cfg) + end + end + local on_save = pcode.format_on_save or 0 + if on_save == 1 then + return { + debug = false, + sources = sources, + on_attach = function(client, bufnr) + if client.supports_method("textDocument/formatting") then + vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) + vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + buffer = bufnr, + callback = function() + vim.lsp.buf.format({ bufnr = bufnr }) + end, + }) + end + end, + } + else + return { + debug = false, + sources = sources, + } + end + end, + config = function(_, opts) + require("null-ls").setup(opts) + end, + }, +} diff --git a/lua/plugins/themes/_globalvar.lua b/lua/plugins/themes/_globalvar.lua index eef7e66..49ef87f 100644 --- a/lua/plugins/themes/_globalvar.lua +++ b/lua/plugins/themes/_globalvar.lua @@ -83,4 +83,12 @@ if pcode.active_cpp_config then table.insert(pcode.dap_ensure_installed, "codelldb") pcode.nvim_dap = true end +-- run if java config true +if pcode.active_java_config 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.dap_ensure_installed, "javatest") + table.insert(pcode.unregister_lsp, "jdtls") +end return {} diff --git a/lua/user/lsp/null-lscfg.lua b/lua/user/lsp/null-lscfg.lua index cfaabd1..cf30f6d 100644 --- a/lua/user/lsp/null-lscfg.lua +++ b/lua/user/lsp/null-lscfg.lua @@ -1,6 +1,6 @@ local null_ls_status_ok, null_ls = pcall(require, "null-ls") if not null_ls_status_ok then - return + return end -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting @@ -15,70 +15,70 @@ local ensure_installed = {} local data_ok, data_sources = pcall(require, "custom.null-ls") if data_ok then - for _, cfg in pairs(data_sources.sources) do - table.insert(sources, cfg) - end + for _, cfg in pairs(data_sources.sources) do + table.insert(sources, cfg) + end end -- load data null-ls local nullls_data = pcode.null_ls_ensure_installed or {} for _, nullls in pairs(nullls_data) do - table.insert(ensure_installed, nullls) + table.insert(ensure_installed, nullls) end local mason_ok, mason_null_ls = pcall(require, "mason-null-ls") if mason_ok then - mason_null_ls.setup({ - ensure_installed = ensure_installed, - }) + mason_null_ls.setup({ + ensure_installed = ensure_installed, + }) end local run = 0 local frmt = pcode.format_on_save or 0 if frmt == 1 then - run = 1 + run = 1 end if run == 1 then - null_ls.setup({ - debug = false, - ensure_installed = ensure_installed, - sources = sources, - --sources = { - --formatting.prettier.with({ extra_args = { "--no-semi", "--single-quote", "--jsx-single-quote" } }), - --formatting.prettier, - -- formatting.prettierd, - -- formatting.black.with({ extra_args = { "--fast" } }), - -- formatting.stylua, - -- formatting.eslint_d, - -- formatting.google_java_format, - -- formatting.phpcbf, - -- formatting.clang_format, - -- diagnostics.flake8 - -- diagnostics.eslint_d, - --}, + null_ls.setup({ + debug = false, + ensure_installed = ensure_installed, + sources = sources, + --sources = { + --formatting.prettier.with({ extra_args = { "--no-semi", "--single-quote", "--jsx-single-quote" } }), + --formatting.prettier, + -- formatting.prettierd, + -- formatting.black.with({ extra_args = { "--fast" } }), + -- formatting.stylua, + -- formatting.eslint_d, + -- formatting.google_java_format, + -- formatting.phpcbf, + -- formatting.clang_format, + -- diagnostics.flake8 + -- diagnostics.eslint_d, + --}, - on_attach = function(client, bufnr) - --if client.resolved_capabilities.document_formatting then - --vim.cmd("autocmd BufWritePre lua vim.lsp.buf.format{async=true}") - --end - if client.supports_method("textDocument/formatting") then - vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) - vim.api.nvim_create_autocmd("BufWritePre", { - group = augroup, - buffer = bufnr, - callback = function() - vim.lsp.buf.format({ bufnr = bufnr }) - -- vim.lsp.buf.formatting_sync() - end, - }) - end - end, - }) + on_attach = function(client, bufnr) + --if client.resolved_capabilities.document_formatting then + --vim.cmd("autocmd BufWritePre lua vim.lsp.buf.format{async=true}") + --end + if client.supports_method("textDocument/formatting") then + vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) + vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + buffer = bufnr, + callback = function() + vim.lsp.buf.format({ bufnr = bufnr }) + -- vim.lsp.buf.formatting_sync() + end, + }) + end + end, + }) else - null_ls.setup({ - debug = false, - ensure_installed = ensure_installed, - sources = sources, - }) + null_ls.setup({ + debug = false, + ensure_installed = ensure_installed, + sources = sources, + }) end