add: user command for runner cmd

This commit is contained in:
pojok code 2025-06-22 18:29:49 +07:00
parent 7450625ba8
commit 339f818e4a
3 changed files with 75 additions and 25 deletions

View file

@ -26,7 +26,7 @@
"indent-blankline.nvim": { "branch": "master", "commit": "005b56001b2cb30bfa61b7986bc50657816ba4ba" }, "indent-blankline.nvim": { "branch": "master", "commit": "005b56001b2cb30bfa61b7986bc50657816ba4ba" },
"lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" },
"lualine.nvim": { "branch": "master", "commit": "a94fc68960665e54408fe37dcf573193c4ce82c9" }, "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-dap.nvim": { "branch": "main", "commit": "4c2cdc69d69fe00c15ae8648f7e954d99e5de3ea" },
"mason.nvim": { "branch": "main", "commit": "8024d64e1330b86044fed4c8494ef3dcd483a67c" }, "mason.nvim": { "branch": "main", "commit": "8024d64e1330b86044fed4c8494ef3dcd483a67c" },
"menu": { "branch": "main", "commit": "7a0a4a2896b715c066cfbe320bdc048091874cc6" }, "menu": { "branch": "main", "commit": "7a0a4a2896b715c066cfbe320bdc048091874cc6" },
@ -38,6 +38,7 @@
"neotest-plenary": { "branch": "master", "commit": "3523adcf9ffaad1911960c5813b0136c1b63a2ec" }, "neotest-plenary": { "branch": "master", "commit": "3523adcf9ffaad1911960c5813b0136c1b63a2ec" },
"neotest-vim-test": { "branch": "master", "commit": "75c4228882ae4883b11bfce9b8383e637eb44192" }, "neotest-vim-test": { "branch": "master", "commit": "75c4228882ae4883b11bfce9b8383e637eb44192" },
"noice.nvim": { "branch": "main", "commit": "0427460c2d7f673ad60eb02b35f5e9926cf67c59" }, "noice.nvim": { "branch": "main", "commit": "0427460c2d7f673ad60eb02b35f5e9926cf67c59" },
"npm-runner.nvim": { "branch": "main", "commit": "4acc407e07e16eb42e356b10bc17886b21744606" },
"nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" }, "nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" },
"nvim-autopairs": { "branch": "master", "commit": "2647cce4cb64fb35c212146663384e05ae126bdf" }, "nvim-autopairs": { "branch": "master", "commit": "2647cce4cb64fb35c212146663384e05ae126bdf" },
"nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" }, "nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" },

View file

@ -94,29 +94,28 @@ local M = {
end end
require("neotest").setup(opts) require("neotest").setup(opts)
local command = pcode.npm_commad -- local command = pcode.npm_commad
or { -- or {
dev = { -- dev = {
start = "NpmRunDev", -- start = "NpmRunDev",
stop = "NpmStopDev", -- stop = "NpmStopDev",
cmd = "npm run dev", -- cmd = "npm run dev",
}, -- },
prod = { -- prod = {
start = "NpmStart", -- start = "NpmStart",
stop = "NpmStop", -- stop = "NpmStop",
cmd = "npm start", -- cmd = "npm start",
}, -- },
} -- }
require("pcode.user.npmrun").setup(command, { -- require("pcode.user.npmrun").setup(command, {
show_mapping = "<leader>nm", -- show_mapping = "<leader>nm",
hide_mapping = "<leader>nh", -- hide_mapping = "<leader>nh",
width = 70, -- width = 70,
height = 20, -- height = 20,
}) -- })
end, end,
-- stylua: ignore -- stylua: ignore
keys = { keys = {
{"<leader>n","",desc="  Npm"},
{ "<leader>T","",desc="  Test"}, { "<leader>T","",desc="  Test"},
{ "<leader>Tt", function() require("neotest").run.run(vim.fn.expand("%")) end, desc = "Run File" }, { "<leader>Tt", function() require("neotest").run.run(vim.fn.expand("%")) end, desc = "Run File" },
{ "<leader>Tr", function() require("neotest").run.run() end, desc = "Run Nearest" }, { "<leader>Tr", function() require("neotest").run.run() end, desc = "Run Nearest" },
@ -128,6 +127,40 @@ local M = {
{ "<Leader>TS", function() require("neotest").run.stop() end, desc = "Stop" }, { "<Leader>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 = "<leader>nm",
hide_mapping = "<leader>nh",
width = 70,
height = 20,
},
},
keys = {
{ "<leader>n", "", desc = "  Npm" },
},
config = function(_, opts)
require("npm-runner").setup(opts.command, opts.opt)
end,
},
{ {
"rcarriga/nvim-dap-ui", "rcarriga/nvim-dap-ui",
lazy = true, lazy = true,

View file

@ -6,6 +6,7 @@ local function modal_manager(opts)
local buf_id = nil local buf_id = nil
local last_content = "" local last_content = ""
local is_shown = false local is_shown = false
local ever_shown = false
local function close() local function close()
if win_id and vim.api.nvim_win_is_valid(win_id) then if win_id and vim.api.nvim_win_is_valid(win_id) then
@ -31,7 +32,6 @@ local function modal_manager(opts)
end, end,
}) })
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_option, buf_id, "modifiable", true)
pcall(vim.api.nvim_buf_set_lines, buf_id, 0, -1, false, lines) pcall(vim.api.nvim_buf_set_lines, buf_id, 0, -1, false, lines)
pcall(vim.api.nvim_buf_set_option, buf_id, "modifiable", false) pcall(vim.api.nvim_buf_set_option, buf_id, "modifiable", false)
@ -47,6 +47,7 @@ local function modal_manager(opts)
}) })
end end
is_shown = true is_shown = true
ever_shown = true
end end
local function show() local function show()
@ -72,13 +73,15 @@ local function modal_manager(opts)
end end
end end
-- Hanya auto open saat pertama kali, tidak auto open setelah pernah di-close/hide
local function set_content(content) local function set_content(content)
last_content = content last_content = content
if is_shown then if not ever_shown then
update(content)
else
open(content) open(content)
elseif is_shown then
update(content)
end end
-- jika ever_shown dan !is_shown, cukup simpan output saja
end end
return { return {
@ -149,6 +152,19 @@ M.setup = function(command_table, opts)
end, { desc = "Hide last NPM modal output" }) end, { desc = "Hide last NPM modal output" })
end 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 for key, conf in pairs(command_table) do
local start_cmd = conf.start or ("NpmRun" .. key) local start_cmd = conf.start or ("NpmRun" .. key)
local stop_cmd = conf.stop or ("NpmStop" .. key) local stop_cmd = conf.stop or ("NpmStop" .. key)