mirror of
https://github.com/pojokcodeid/nvim-lazy.git
synced 2025-06-23 17:28:50 +02:00
add: user command for runner cmd
This commit is contained in:
parent
7450625ba8
commit
339f818e4a
3 changed files with 75 additions and 25 deletions
|
@ -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 = "<leader>nm",
|
||||
hide_mapping = "<leader>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 = "<leader>nm",
|
||||
-- hide_mapping = "<leader>nh",
|
||||
-- width = 70,
|
||||
-- height = 20,
|
||||
-- })
|
||||
end,
|
||||
-- stylua: ignore
|
||||
keys = {
|
||||
{"<leader>n","",desc=" Npm"},
|
||||
{ "<leader>T","",desc=" Test"},
|
||||
{ "<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" },
|
||||
|
@ -128,6 +127,40 @@ local M = {
|
|||
{ "<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",
|
||||
lazy = true,
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue