diff --git a/lazy-lock.json b/lazy-lock.json index 9b8df1b..70ecf68 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -26,7 +26,7 @@ "indent-blankline.nvim": { "branch": "master", "commit": "005b56001b2cb30bfa61b7986bc50657816ba4ba" }, "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, "lualine.nvim": { "branch": "master", "commit": "a94fc68960665e54408fe37dcf573193c4ce82c9" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "f54e3c11fc9ebfcfc27e696182b0295b071d0811" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "c4c84f4521d62de595c0d0f718a9a40c1890c8ce" }, "mason-nvim-dap.nvim": { "branch": "main", "commit": "4c2cdc69d69fe00c15ae8648f7e954d99e5de3ea" }, "mason.nvim": { "branch": "main", "commit": "8024d64e1330b86044fed4c8494ef3dcd483a67c" }, "menu": { "branch": "main", "commit": "7a0a4a2896b715c066cfbe320bdc048091874cc6" }, @@ -38,6 +38,7 @@ "neotest-plenary": { "branch": "master", "commit": "3523adcf9ffaad1911960c5813b0136c1b63a2ec" }, "neotest-vim-test": { "branch": "master", "commit": "75c4228882ae4883b11bfce9b8383e637eb44192" }, "noice.nvim": { "branch": "main", "commit": "0427460c2d7f673ad60eb02b35f5e9926cf67c59" }, + "npm-runner.nvim": { "branch": "main", "commit": "4acc407e07e16eb42e356b10bc17886b21744606" }, "nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" }, "nvim-autopairs": { "branch": "master", "commit": "2647cce4cb64fb35c212146663384e05ae126bdf" }, "nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" }, diff --git a/lua/pcode/plugins/lang/javascript.lua b/lua/pcode/plugins/lang/javascript.lua index 271f8bc..25b8585 100644 --- a/lua/pcode/plugins/lang/javascript.lua +++ b/lua/pcode/plugins/lang/javascript.lua @@ -94,29 +94,28 @@ local M = { end require("neotest").setup(opts) - local command = pcode.npm_commad - or { - dev = { - start = "NpmRunDev", - stop = "NpmStopDev", - cmd = "npm run dev", - }, - prod = { - start = "NpmStart", - stop = "NpmStop", - cmd = "npm start", - }, - } - require("pcode.user.npmrun").setup(command, { - show_mapping = "nm", - hide_mapping = "nh", - width = 70, - height = 20, - }) + -- local command = pcode.npm_commad + -- or { + -- dev = { + -- start = "NpmRunDev", + -- stop = "NpmStopDev", + -- cmd = "npm run dev", + -- }, + -- prod = { + -- start = "NpmStart", + -- stop = "NpmStop", + -- cmd = "npm start", + -- }, + -- } + -- require("pcode.user.npmrun").setup(command, { + -- show_mapping = "nm", + -- hide_mapping = "nh", + -- width = 70, + -- height = 20, + -- }) end, -- stylua: ignore keys = { - {"n","",desc="  Npm"}, { "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" }, @@ -128,6 +127,40 @@ local M = { { "TS", function() require("neotest").run.stop() end, desc = "Stop" }, }, }, + { + "pojokcodeid/npm-runner.nvim", + event = "VeryLazy", + dependencies = { + "rcarriga/nvim-notify", + }, + -- your opts go here + opts = { + command = { + dev = { + start = "NpmRunDev", + stop = "NpmStopDev", + cmd = "npm run dev", + }, + prod = { + start = "NpmStart", + stop = "NpmStop", + cmd = "npm start", + }, + }, + opt = { + show_mapping = "nm", + hide_mapping = "nh", + width = 70, + height = 20, + }, + }, + keys = { + { "n", "", desc = "  Npm" }, + }, + config = function(_, opts) + require("npm-runner").setup(opts.command, opts.opt) + end, + }, { "rcarriga/nvim-dap-ui", lazy = true, diff --git a/lua/pcode/user/npmrun.lua b/lua/pcode/user/npmrun.lua index 495468a..ab88fb7 100644 --- a/lua/pcode/user/npmrun.lua +++ b/lua/pcode/user/npmrun.lua @@ -6,6 +6,7 @@ local function modal_manager(opts) local buf_id = nil local last_content = "" local is_shown = false + local ever_shown = false local function close() if win_id and vim.api.nvim_win_is_valid(win_id) then @@ -31,7 +32,6 @@ local function modal_manager(opts) end, }) end - -- Pastikan buffer modifiable sebelum update, abaikan jika error (buffer deleted) pcall(vim.api.nvim_buf_set_option, buf_id, "modifiable", true) pcall(vim.api.nvim_buf_set_lines, buf_id, 0, -1, false, lines) pcall(vim.api.nvim_buf_set_option, buf_id, "modifiable", false) @@ -47,6 +47,7 @@ local function modal_manager(opts) }) end is_shown = true + ever_shown = true end local function show() @@ -72,13 +73,15 @@ local function modal_manager(opts) end end + -- Hanya auto open saat pertama kali, tidak auto open setelah pernah di-close/hide local function set_content(content) last_content = content - if is_shown then - update(content) - else + if not ever_shown then open(content) + elseif is_shown then + update(content) end + -- jika ever_shown dan !is_shown, cukup simpan output saja end return { @@ -149,6 +152,19 @@ M.setup = function(command_table, opts) end, { desc = "Hide last NPM modal output" }) end + -- Tambah user command global untuk show/hide modal + vim.api.nvim_create_user_command("NpmModalShow", function() + if last_modal then + last_modal.show() + end + end, { desc = "Show last NPM modal output" }) + + vim.api.nvim_create_user_command("NpmModalHide", function() + if last_modal then + last_modal.hide() + end + end, { desc = "Hide last NPM modal output" }) + for key, conf in pairs(command_table) do local start_cmd = conf.start or ("NpmRun" .. key) local stop_cmd = conf.stop or ("NpmStop" .. key)