mirror of
https://github.com/pojokcodeid/nvim-lazy.git
synced 2025-07-16 20:34:29 +02:00
enc: add neocodeium config for replace codeium.vim
This commit is contained in:
parent
64e62e59ba
commit
38bf58ad63
61 changed files with 2942 additions and 1051 deletions
|
@ -3,12 +3,12 @@ local api = vim.api
|
|||
-- General Settings
|
||||
api.nvim_create_augroup("_general_settings", { clear = true })
|
||||
|
||||
api.nvim_create_autocmd("TextYankPost", {
|
||||
group = "_general_settings",
|
||||
callback = function()
|
||||
require("vim.highlight").on_yank({ higroup = "Visual", timeout = 200 })
|
||||
end,
|
||||
})
|
||||
-- api.nvim_create_autocmd("TextYankPost", {
|
||||
-- group = "_general_settings",
|
||||
-- callback = function()
|
||||
-- require("vim.highlight").on_yank({ higroup = "Visual", timeout = 200 })
|
||||
-- end,
|
||||
-- })
|
||||
|
||||
api.nvim_create_autocmd("FileType", {
|
||||
group = "_general_settings",
|
||||
|
@ -124,3 +124,264 @@ vim.api.nvim_create_autocmd("ExitPre", {
|
|||
-- vim.api.nvim_set_keymap("n", "<leader>rg", "<cmd>terminal<cr>gradle run<cr>", { noremap = true, silent = true })
|
||||
-- end,
|
||||
-- })
|
||||
|
||||
-- Extras
|
||||
local function lsp_status()
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local clients = vim.lsp.get_clients and vim.lsp.get_clients({ bufnr = bufnr })
|
||||
or vim.lsp.get_active_clients({ bufnr = bufnr })
|
||||
|
||||
if #clients == 0 then
|
||||
print(" No LSP clients attached")
|
||||
return
|
||||
end
|
||||
|
||||
print(" LSP Status for buffer " .. bufnr .. ":")
|
||||
print("─────────────────────────────────")
|
||||
|
||||
for i, client in ipairs(clients) do
|
||||
print(string.format(" Client %d: %s (ID: %d)", i, client.name, client.id))
|
||||
print(" Root: " .. (client.config.root_dir or "N/A"))
|
||||
print(" Filetypes: " .. table.concat(client.config.filetypes or {}, ", "))
|
||||
|
||||
-- Check capabilities
|
||||
local caps = client.server_capabilities
|
||||
local features = {}
|
||||
if caps.completionProvider then
|
||||
table.insert(features, "completion")
|
||||
end
|
||||
if caps.hoverProvider then
|
||||
table.insert(features, "hover")
|
||||
end
|
||||
if caps.definitionProvider then
|
||||
table.insert(features, "definition")
|
||||
end
|
||||
if caps.referencesProvider then
|
||||
table.insert(features, "references")
|
||||
end
|
||||
if caps.renameProvider then
|
||||
table.insert(features, "rename")
|
||||
end
|
||||
if caps.codeActionProvider then
|
||||
table.insert(features, "code_action")
|
||||
end
|
||||
if caps.documentFormattingProvider then
|
||||
table.insert(features, "formatting")
|
||||
end
|
||||
|
||||
print(" Features: " .. table.concat(features, ", "))
|
||||
print("")
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command("LspStatus", lsp_status, { desc = "Show detailed LSP status" })
|
||||
|
||||
local function check_lsp_capabilities()
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local clients = vim.lsp.get_clients and vim.lsp.get_clients({ bufnr = bufnr })
|
||||
or vim.lsp.get_active_clients({ bufnr = bufnr })
|
||||
|
||||
if #clients == 0 then
|
||||
print("No LSP clients attached")
|
||||
return
|
||||
end
|
||||
|
||||
for _, client in ipairs(clients) do
|
||||
print("Capabilities for " .. client.name .. ":")
|
||||
local caps = client.server_capabilities
|
||||
|
||||
local capability_list = {
|
||||
{ "Completion", caps.completionProvider },
|
||||
{ "Hover", caps.hoverProvider },
|
||||
{ "Signature Help", caps.signatureHelpProvider },
|
||||
{ "Go to Definition", caps.definitionProvider },
|
||||
{ "Go to Declaration", caps.declarationProvider },
|
||||
{ "Go to Implementation", caps.implementationProvider },
|
||||
{ "Go to Type Definition", caps.typeDefinitionProvider },
|
||||
{ "Find References", caps.referencesProvider },
|
||||
{ "Document Highlight", caps.documentHighlightProvider },
|
||||
{ "Document Symbol", caps.documentSymbolProvider },
|
||||
{ "Workspace Symbol", caps.workspaceSymbolProvider },
|
||||
{ "Code Action", caps.codeActionProvider },
|
||||
{ "Code Lens", caps.codeLensProvider },
|
||||
{ "Document Formatting", caps.documentFormattingProvider },
|
||||
{ "Document Range Formatting", caps.documentRangeFormattingProvider },
|
||||
{ "Rename", caps.renameProvider },
|
||||
{ "Folding Range", caps.foldingRangeProvider },
|
||||
{ "Selection Range", caps.selectionRangeProvider },
|
||||
}
|
||||
|
||||
for _, cap in ipairs(capability_list) do
|
||||
local status = cap[2] and "✓" or "✗"
|
||||
print(string.format(" %s %s", status, cap[1]))
|
||||
end
|
||||
print("")
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command("LspCapabilities", check_lsp_capabilities, { desc = "Show LSP capabilities" })
|
||||
|
||||
local function lsp_diagnostics_info()
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local diagnostics = vim.diagnostic.get(bufnr)
|
||||
|
||||
local counts = { ERROR = 0, WARN = 0, INFO = 0, HINT = 0 }
|
||||
|
||||
for _, diagnostic in ipairs(diagnostics) do
|
||||
local severity = vim.diagnostic.severity[diagnostic.severity]
|
||||
counts[severity] = counts[severity] + 1
|
||||
end
|
||||
|
||||
print(" Diagnostics for current buffer:")
|
||||
print(" Errors: " .. counts.ERROR)
|
||||
print(" Warnings: " .. counts.WARN)
|
||||
print(" Info: " .. counts.INFO)
|
||||
print(" Hints: " .. counts.HINT)
|
||||
print(" Total: " .. #diagnostics)
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command("LspDiagnostics", lsp_diagnostics_info, { desc = "Show LSP diagnostics count" })
|
||||
|
||||
local function lsp_info()
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local clients = vim.lsp.get_clients and vim.lsp.get_clients({ bufnr = bufnr })
|
||||
or vim.lsp.get_active_clients({ bufnr = bufnr })
|
||||
|
||||
print("═══════════════════════════════════")
|
||||
print(" LSP INFORMATION ")
|
||||
print("═══════════════════════════════════")
|
||||
print("")
|
||||
|
||||
-- Basic info
|
||||
print(" Language client log: " .. vim.lsp.get_log_path())
|
||||
print(" Detected filetype: " .. vim.bo.filetype)
|
||||
print(" Buffer: " .. bufnr)
|
||||
print(" Root directory: " .. (vim.fn.getcwd() or "N/A"))
|
||||
print("")
|
||||
|
||||
if #clients == 0 then
|
||||
print(" No LSP clients attached to buffer " .. bufnr)
|
||||
print("")
|
||||
print("Possible reasons:")
|
||||
print(" • No language server installed for " .. vim.bo.filetype)
|
||||
print(" • Language server not configured")
|
||||
print(" • Not in a project root directory")
|
||||
print(" • File type not recognized")
|
||||
return
|
||||
end
|
||||
|
||||
print(" LSP clients attached to buffer " .. bufnr .. ":")
|
||||
print("─────────────────────────────────")
|
||||
|
||||
for i, client in ipairs(clients) do
|
||||
print(string.format(" Client %d: %s", i, client.name))
|
||||
print(" ID: " .. client.id)
|
||||
print(" Root dir: " .. (client.config.root_dir or "Not set"))
|
||||
print(" Command: " .. table.concat(client.config.cmd or {}, " "))
|
||||
print(" Filetypes: " .. table.concat(client.config.filetypes or {}, ", "))
|
||||
|
||||
-- Server status
|
||||
if client.is_stopped() then
|
||||
print(" Status: Stopped")
|
||||
else
|
||||
print(" Status: Running")
|
||||
end
|
||||
|
||||
-- Workspace folders
|
||||
if client.workspace_folders and #client.workspace_folders > 0 then
|
||||
print(" Workspace folders:")
|
||||
for _, folder in ipairs(client.workspace_folders) do
|
||||
print(" • " .. folder.name)
|
||||
end
|
||||
end
|
||||
|
||||
-- Attached buffers count
|
||||
local attached_buffers = {}
|
||||
for buf, _ in pairs(client.attached_buffers or {}) do
|
||||
table.insert(attached_buffers, buf)
|
||||
end
|
||||
print(" Attached buffers: " .. #attached_buffers)
|
||||
|
||||
-- Key capabilities
|
||||
local caps = client.server_capabilities
|
||||
local key_features = {}
|
||||
if caps.completionProvider then
|
||||
table.insert(key_features, "completion")
|
||||
end
|
||||
if caps.hoverProvider then
|
||||
table.insert(key_features, "hover")
|
||||
end
|
||||
if caps.definitionProvider then
|
||||
table.insert(key_features, "definition")
|
||||
end
|
||||
if caps.documentFormattingProvider then
|
||||
table.insert(key_features, "formatting")
|
||||
end
|
||||
if caps.codeActionProvider then
|
||||
table.insert(key_features, "code_action")
|
||||
end
|
||||
|
||||
if #key_features > 0 then
|
||||
print(" Key features: " .. table.concat(key_features, ", "))
|
||||
end
|
||||
|
||||
print("")
|
||||
end
|
||||
|
||||
-- Diagnostics summary
|
||||
local diagnostics = vim.diagnostic.get(bufnr)
|
||||
if #diagnostics > 0 then
|
||||
print(" Diagnostics Summary:")
|
||||
local counts = { ERROR = 0, WARN = 0, INFO = 0, HINT = 0 }
|
||||
|
||||
for _, diagnostic in ipairs(diagnostics) do
|
||||
local severity = vim.diagnostic.severity[diagnostic.severity]
|
||||
counts[severity] = counts[severity] + 1
|
||||
end
|
||||
|
||||
print(" Errors: " .. counts.ERROR)
|
||||
print(" Warnings: " .. counts.WARN)
|
||||
print(" Info: " .. counts.INFO)
|
||||
print(" Hints: " .. counts.HINT)
|
||||
print(" Total: " .. #diagnostics)
|
||||
else
|
||||
print(" No diagnostics")
|
||||
end
|
||||
|
||||
print("")
|
||||
print("Use :LspLog to view detailed logs")
|
||||
print("Use :LspCapabilities for full capability list")
|
||||
end
|
||||
|
||||
-- Create command
|
||||
vim.api.nvim_create_user_command("LspInfo2", lsp_info, { desc = "Show comprehensive LSP information" })
|
||||
|
||||
vim.api.nvim_create_user_command("OpenBrowser", function(opts)
|
||||
local url = opts.args
|
||||
-- Jika tidak ada URL, pakai about:blank sebagai default
|
||||
if url == "" then
|
||||
url = "http://google.com"
|
||||
end
|
||||
|
||||
-- Deteksi jika dijalankan di WSL
|
||||
local is_wsl = vim.fn.system("uname -r"):find("WSL")
|
||||
if is_wsl then
|
||||
vim.fn.jobstart({ "/mnt/c/Windows/System32/cmd.exe", "/c", "start", url }, { detach = true })
|
||||
return
|
||||
end
|
||||
|
||||
-- Jika bukan WSL, gunakan cara biasa
|
||||
local open_cmd
|
||||
if vim.fn.has("mac") == 1 then
|
||||
open_cmd = "open"
|
||||
elseif vim.fn.has("unix") == 1 then
|
||||
open_cmd = "xdg-open"
|
||||
elseif vim.fn.has("win32") == 1 then
|
||||
open_cmd = "start"
|
||||
else
|
||||
print("OS tidak didukung.")
|
||||
return
|
||||
end
|
||||
|
||||
vim.fn.jobstart({ open_cmd, url }, { detach = true })
|
||||
end, { nargs = "?", complete = "file" })
|
||||
|
|
|
@ -47,7 +47,23 @@ return {
|
|||
"williamboman/mason-lspconfig.nvim",
|
||||
opts = function(_, opts)
|
||||
vim.list_extend(opts.skip_config, {})
|
||||
opts.virtual_text = true
|
||||
opts.virtual_text = false
|
||||
vim.diagnostic.config({ virtual_lines = { current_line = true } })
|
||||
-- sample custom diagnostic icon
|
||||
vim.diagnostic.config({
|
||||
underline = false,
|
||||
virtual_text = false,
|
||||
update_in_insert = false,
|
||||
severity_sort = true,
|
||||
signs = {
|
||||
text = {
|
||||
[vim.diagnostic.severity.ERROR] = " ",
|
||||
[vim.diagnostic.severity.WARN] = " ",
|
||||
[vim.diagnostic.severity.HINT] = " ",
|
||||
[vim.diagnostic.severity.INFO] = " ",
|
||||
},
|
||||
},
|
||||
})
|
||||
end,
|
||||
},
|
||||
-- add whichkey mappings
|
||||
|
|
|
@ -2,11 +2,13 @@
|
|||
pcode.lang = {
|
||||
angular = false,
|
||||
cpp = false,
|
||||
sql = true,
|
||||
sql = false,
|
||||
deno = false,
|
||||
golang = false,
|
||||
java = false,
|
||||
java2 = false,
|
||||
java3 = false,
|
||||
java4 = false,
|
||||
javascript = false,
|
||||
kotlin = false,
|
||||
markdown = false,
|
||||
|
@ -20,43 +22,49 @@ pcode.lang = {
|
|||
pcode.extras = {
|
||||
autosave = false,
|
||||
bigfiles = false,
|
||||
codeium = false,
|
||||
codeiumnvim = false,
|
||||
liveserver = true,
|
||||
neocodeium = true,
|
||||
liveserver = false,
|
||||
minianimate = false,
|
||||
neoscroll = false,
|
||||
nvimufo = false,
|
||||
refactoring = true,
|
||||
rest = true,
|
||||
refactoring = false,
|
||||
rest = false,
|
||||
treesittercontex = false,
|
||||
codeium = true,
|
||||
colorizer = true,
|
||||
dap = true,
|
||||
deviconcolor = true,
|
||||
colorizer = false,
|
||||
dap = false,
|
||||
deviconcolor = false,
|
||||
illuminate = true,
|
||||
indentscupe = true,
|
||||
indentscupe = false,
|
||||
navic = true,
|
||||
nvimmenu = true,
|
||||
nvimmenu = false,
|
||||
rainbowdelimiters = true,
|
||||
scrollview = true,
|
||||
scrollview = false,
|
||||
smartsplit = true,
|
||||
verticalcolumn = true,
|
||||
visualmulti = true,
|
||||
yanky = true,
|
||||
zenmode = true,
|
||||
zenmode = false,
|
||||
lspsignatur = false,
|
||||
telescopetreesiterinfo = true,
|
||||
telescopetreesiterinfo = false,
|
||||
fidget = false,
|
||||
tinydignostic = false,
|
||||
dressing = true,
|
||||
telescopediff = false,
|
||||
cheatsheet = false,
|
||||
}
|
||||
-- activate config themes
|
||||
pcode.themes = {
|
||||
-- note: open remark only one
|
||||
-- **:: Eva Theme ::** --
|
||||
evatheme = "Eva-Dark",
|
||||
-- evatheme = "Eva-Dark",
|
||||
-- evatheme = "Eva-Dark-Italic",
|
||||
-- evatheme = "Eva-Dark-Bold",
|
||||
-- evatheme = "Eva-Light",
|
||||
--
|
||||
-- **:: Dracula Theme ::** --
|
||||
-- dracula = "dracula",
|
||||
dracula = "dracula",
|
||||
-- dracula = "dracula-soft",
|
||||
--
|
||||
-- **:: Onedarkpro Theme ::** --
|
||||
|
@ -93,3 +101,4 @@ pcode.themes = {
|
|||
pcode.transparent = false
|
||||
pcode.localcode = true
|
||||
pcode.snippets_path = vim.fn.stdpath("config") .. "/mysnippets"
|
||||
pcode.nvimtree_float = false
|
||||
|
|
|
@ -2,7 +2,8 @@ return {
|
|||
kind = {
|
||||
Boolean = "",
|
||||
Color = "",
|
||||
Codeium = "",
|
||||
-- Codeium = "",
|
||||
Codeium = "",
|
||||
Control = "",
|
||||
Collapsed = " ",
|
||||
Component = "",
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
require("auto-jdtls2.create_gradle_project")
|
||||
require("auto-jdtls2.create_maven_project")
|
||||
require("auto-jdtls2.create_springboot_project")
|
||||
require("auto-jdtls2.generate_java_class")
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
-- definiskanfunction name
|
||||
local keymap = vim.api.nvim_set_keymap
|
||||
-- local keymap = vim.api.nvim_set_keymap
|
||||
local keymap = vim.keymap.set
|
||||
local opts = { noremap = true, silent = true }
|
||||
|
||||
-- Remap space leader keys
|
||||
|
@ -19,13 +20,17 @@ for _, mode in ipairs({ "i", "v", "n", "x" }) do
|
|||
-- duplicate line
|
||||
keymap(mode, "<S-Down>", "<cmd>t.<cr>", opts)
|
||||
keymap(mode, "<S-Up>", "<cmd>t -1<cr>", opts)
|
||||
keymap(mode, "<S-M-Down>", "<cmd>t.<cr>", opts)
|
||||
keymap(mode, "<S-M-Up>", "<cmd>t -1<cr>", opts)
|
||||
-- save file
|
||||
keymap(mode, "<C-s>", "<cmd>silent! w<cr>", opts)
|
||||
end
|
||||
|
||||
-- duplicate line visual block
|
||||
keymap("x", "<S-Down>", ":'<,'>t'><cr>", opts)
|
||||
keymap("x", "<S-M-Down>", ":'<,'>t'><cr>", opts)
|
||||
keymap("x", "<S-Up>", ":'<,'>t-1<cr>", opts)
|
||||
keymap("x", "<S-M-Up>", ":'<,'>t-1<cr>", opts)
|
||||
|
||||
-- move text up and down
|
||||
keymap("x", "<A-Down>", ":move '>+1<CR>gv-gv", opts)
|
||||
|
@ -35,15 +40,43 @@ keymap("i", "<M-Down>", "<cmd>m+<cr>", opts)
|
|||
keymap("n", "<M-Up>", "<cmd>m-2<cr>", opts)
|
||||
keymap("i", "<M-Up>", "<cmd>m-2<cr>", opts)
|
||||
|
||||
-- create comment CTRL + / all mode
|
||||
keymap("v", "<C-_>", "<esc><cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<cr>", opts)
|
||||
keymap("v", "<C-/>", "<esc><cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<cr>", opts)
|
||||
keymap("i", "<C-_>", "<esc><cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<cr>", opts)
|
||||
keymap("i", "<C-/>", "<esc><cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<cr>", opts)
|
||||
keymap("i", "<C-_>", "<esc><cmd>lua require('Comment.api').toggle.linewise.current()<cr>", opts)
|
||||
keymap("i", "<C-/>", "<esc><cmd>lua require('Comment.api').toggle.linewise.current()<cr>", opts)
|
||||
keymap("n", "<C-_>", "<esc><cmd>lua require('Comment.api').toggle.linewise.current()<cr>", opts)
|
||||
keymap("n", "<C-/>", "<esc><cmd>lua require('Comment.api').toggle.linewise.current()<cr>", opts)
|
||||
-- create comment CTRL + / visual block mode
|
||||
keymap("x", "<C-_>", function()
|
||||
vim.api.nvim_feedkeys("gb", "v", true)
|
||||
end, opts)
|
||||
-- create comment CTRL + / normal mode
|
||||
keymap("i", "<C-_>", function()
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<esc>", true, false, true), "n", true)
|
||||
-- Toggle comment baris
|
||||
vim.api.nvim_feedkeys("gcc", "v", true)
|
||||
|
||||
-- Tunggu sejenak agar komentar terbentuk
|
||||
vim.schedule(function()
|
||||
local row = vim.fn.line(".") - 1 -- index dimulai dari 0
|
||||
local col = #vim.fn.getline(".") -- panjang baris = akhir kalimat
|
||||
|
||||
-- Geser 2 spasi dari akhir dan masuk insert mode
|
||||
vim.api.nvim_win_set_cursor(0, { row + 1, col })
|
||||
vim.api.nvim_feedkeys("i", "v", true)
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Right><leader>", true, false, true), "n", true)
|
||||
end)
|
||||
end, opts)
|
||||
-- create comment CTRL + / normal mode
|
||||
keymap("n", "<C-_>", function()
|
||||
-- Toggle comment baris
|
||||
vim.api.nvim_feedkeys("gcc", "v", true)
|
||||
|
||||
-- Tunggu sejenak agar komentar terbentuk
|
||||
vim.schedule(function()
|
||||
local row = vim.fn.line(".") - 1 -- index dimulai dari 0
|
||||
local col = #vim.fn.getline(".") -- panjang baris = akhir kalimat
|
||||
|
||||
-- Geser 2 spasi dari akhir dan masuk insert mode
|
||||
vim.api.nvim_win_set_cursor(0, { row + 1, col })
|
||||
vim.api.nvim_feedkeys("i", "v", true)
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Right><leader>", true, false, true), "n", true)
|
||||
end)
|
||||
end, opts)
|
||||
|
||||
-- close windows
|
||||
keymap("n", "q", "<cmd>q<cr>", opts)
|
||||
|
@ -91,3 +124,27 @@ keymap("n", "<A-l>", "<cmd>terminal live-server<cr>", opts)
|
|||
|
||||
-- close current buffer
|
||||
keymap("n", "<S-t>", "<cmd>lua require('auto-bufferline.configs.utils').bufremove()<cr>", opts)
|
||||
|
||||
vim.api.nvim_create_user_command("TSIsInstalled", function()
|
||||
local parsers = require("nvim-treesitter.info").installed_parsers()
|
||||
table.sort(parsers)
|
||||
local choices = {}
|
||||
local lookup = {}
|
||||
|
||||
for _, parser in ipairs(parsers) do
|
||||
local label = "[✓] " .. parser
|
||||
table.insert(choices, label)
|
||||
lookup[label] = parser
|
||||
end
|
||||
|
||||
vim.ui.select(choices, {
|
||||
prompt = "Uninstall Treesitter",
|
||||
}, function(choice)
|
||||
if choice then
|
||||
local parser_name = lookup[choice]
|
||||
if parser_name then
|
||||
vim.cmd("TSUninstall " .. parser_name)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end, {})
|
||||
|
|
262
lua/pcode/user/npmrun.lua
Normal file
262
lua/pcode/user/npmrun.lua
Normal file
|
@ -0,0 +1,262 @@
|
|||
local last_modal = nil -- global modal manager instance
|
||||
|
||||
local function modal_manager(opts)
|
||||
opts = opts or {}
|
||||
local win_id = nil
|
||||
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
|
||||
vim.api.nvim_win_close(win_id, true)
|
||||
win_id = nil
|
||||
end
|
||||
is_shown = false
|
||||
end
|
||||
|
||||
local function open(content)
|
||||
local lines = vim.split(content or "", "\n")
|
||||
local width = opts.width or 70
|
||||
local height = math.min(opts.height or 15, #lines + 6)
|
||||
local row = math.floor((vim.o.lines - height) / 2)
|
||||
local col = math.floor((vim.o.columns - width) / 2)
|
||||
if not buf_id or not vim.api.nvim_buf_is_valid(buf_id) then
|
||||
buf_id = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_keymap(buf_id, "n", "q", "", {
|
||||
noremap = true,
|
||||
silent = true,
|
||||
callback = function()
|
||||
close()
|
||||
end,
|
||||
})
|
||||
end
|
||||
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)
|
||||
if not win_id or not vim.api.nvim_win_is_valid(win_id) then
|
||||
win_id = vim.api.nvim_open_win(buf_id, true, {
|
||||
relative = "editor",
|
||||
width = width,
|
||||
height = height,
|
||||
row = row,
|
||||
col = col,
|
||||
style = "minimal",
|
||||
border = "rounded",
|
||||
})
|
||||
end
|
||||
is_shown = true
|
||||
ever_shown = true
|
||||
end
|
||||
|
||||
local function show()
|
||||
if is_shown then
|
||||
return
|
||||
end
|
||||
if last_content ~= "" then
|
||||
open(last_content)
|
||||
end
|
||||
end
|
||||
|
||||
local function hide()
|
||||
close()
|
||||
end
|
||||
|
||||
local function update(content)
|
||||
last_content = content
|
||||
if is_shown and buf_id and vim.api.nvim_buf_is_valid(buf_id) then
|
||||
local lines = vim.split(content or "", "\n")
|
||||
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)
|
||||
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 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 {
|
||||
show = show,
|
||||
hide = hide,
|
||||
update = update,
|
||||
close = close,
|
||||
set_content = set_content,
|
||||
is_shown = function()
|
||||
return is_shown
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
local M = {}
|
||||
M._last_modal = nil
|
||||
|
||||
local function log(message, level)
|
||||
vim.notify(string.format("npm-dev-runner: %s", message), vim.log.levels[level])
|
||||
end
|
||||
|
||||
local function find_cached_dir(dir, cache)
|
||||
if not dir then
|
||||
vim.notify("npm-dev-runner: No directory provided to find_cached_dir()", vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
local cur = dir
|
||||
while not cache[cur] do
|
||||
if cur == "/" or string.match(cur, "^[A-Z]:\\$") then
|
||||
return
|
||||
end
|
||||
cur = vim.fn.fnamemodify(cur, ":h")
|
||||
end
|
||||
return cur
|
||||
end
|
||||
|
||||
local function is_running(dir, cache)
|
||||
local cached_dir = find_cached_dir(dir, cache)
|
||||
return cached_dir and cache[cached_dir]
|
||||
end
|
||||
|
||||
local function is_windows()
|
||||
return vim.loop.os_uname().version:match("Windows")
|
||||
end
|
||||
|
||||
local default_opts = {
|
||||
show_mapping = "<leader>nm",
|
||||
hide_mapping = "<leader>nh",
|
||||
}
|
||||
|
||||
M.setup = function(command_table, opts)
|
||||
opts = vim.tbl_deep_extend("force", {}, default_opts, opts or {})
|
||||
command_table = command_table or {}
|
||||
|
||||
-- Keymap global, pakai modal terakhir yang aktif
|
||||
if opts.show_mapping then
|
||||
vim.keymap.set("n", opts.show_mapping, function()
|
||||
if last_modal then
|
||||
last_modal.show()
|
||||
end
|
||||
end, { desc = "Show last NPM modal output" })
|
||||
end
|
||||
if opts.hide_mapping then
|
||||
vim.keymap.set("n", opts.hide_mapping, function()
|
||||
if last_modal then
|
||||
last_modal.hide()
|
||||
end
|
||||
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)
|
||||
local cmd_str = conf.cmd or "npm run dev"
|
||||
local cache = {}
|
||||
|
||||
local function do_start(dir)
|
||||
if is_running(dir, cache) then
|
||||
log(cmd_str .. " already running", "INFO")
|
||||
return
|
||||
end
|
||||
|
||||
local all_output = {}
|
||||
local modal = modal_manager(opts)
|
||||
last_modal = modal
|
||||
M._last_modal = modal
|
||||
|
||||
local cmd
|
||||
if is_windows() then
|
||||
cmd = { "cmd.exe", "/C" }
|
||||
for word in cmd_str:gmatch("%S+") do
|
||||
table.insert(cmd, word)
|
||||
end
|
||||
else
|
||||
cmd = {}
|
||||
for word in cmd_str:gmatch("%S+") do
|
||||
table.insert(cmd, word)
|
||||
end
|
||||
end
|
||||
|
||||
local function process_lines(lines)
|
||||
if not lines then
|
||||
return
|
||||
end
|
||||
for _, l in ipairs(lines) do
|
||||
table.insert(all_output, tostring(l))
|
||||
end
|
||||
modal.set_content(table.concat(all_output, "\n"))
|
||||
end
|
||||
|
||||
local job_id = vim.fn.jobstart(cmd, {
|
||||
cwd = dir,
|
||||
stdout_buffered = false,
|
||||
stderr_buffered = false,
|
||||
on_stdout = function(_, data)
|
||||
process_lines(data)
|
||||
end,
|
||||
on_stderr = function(_, data)
|
||||
process_lines(data)
|
||||
end,
|
||||
on_exit = function(_, code)
|
||||
table.insert(all_output, ("Process exited with code: %d"):format(code))
|
||||
modal.set_content(table.concat(all_output, "\n"))
|
||||
cache[dir] = nil
|
||||
end,
|
||||
})
|
||||
|
||||
cache[dir] = { job_id = job_id, modal = modal }
|
||||
log(cmd_str .. " started", "INFO")
|
||||
end
|
||||
|
||||
local function do_stop(dir)
|
||||
local running = is_running(dir, cache)
|
||||
if running then
|
||||
local cached_dir = find_cached_dir(dir, cache)
|
||||
if cached_dir then
|
||||
local job_entry = cache[cached_dir]
|
||||
if job_entry then
|
||||
vim.fn.jobstop(job_entry.job_id)
|
||||
if job_entry.modal then
|
||||
job_entry.modal.close()
|
||||
end
|
||||
end
|
||||
cache[cached_dir] = nil
|
||||
log(cmd_str .. " stopped", "INFO")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function find_dir(args)
|
||||
local dir = args ~= "" and args or "%:p:h"
|
||||
return vim.fn.expand(vim.fn.fnamemodify(vim.fn.expand(dir), ":p"))
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command(start_cmd, function(opts)
|
||||
do_start(find_dir(opts.args))
|
||||
end, { nargs = "?" })
|
||||
|
||||
vim.api.nvim_create_user_command(stop_cmd, function(opts)
|
||||
do_stop(find_dir(opts.args))
|
||||
end, { nargs = "?" })
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
171
lua/pcode/user/npmrun2.lua
Normal file
171
lua/pcode/user/npmrun2.lua
Normal file
|
@ -0,0 +1,171 @@
|
|||
local function open_new_buffer(name)
|
||||
local buf = vim.api.nvim_create_buf(true, false)
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
vim.api.nvim_buf_set_option(buf, "modifiable", true)
|
||||
if name then
|
||||
vim.api.nvim_buf_set_name(buf, name)
|
||||
end
|
||||
return buf
|
||||
end
|
||||
|
||||
local M = {}
|
||||
|
||||
local main_cmd = "npm run dev" -- default
|
||||
|
||||
local function log(message, level)
|
||||
vim.notify(string.format("npm-dev-runner: %s", message), vim.log.levels[level])
|
||||
end
|
||||
|
||||
-- Cache: dir -> { job_id=..., buf=... }
|
||||
local job_cache = {}
|
||||
|
||||
local function find_cached_dir(dir)
|
||||
if not dir then
|
||||
vim.notify("npm-dev-runner: No directory provided to find_cached_dir()", vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
|
||||
local cur = dir
|
||||
while not job_cache[cur] do
|
||||
if cur == "/" or string.match(cur, "^[A-Z]:\\$") then
|
||||
return
|
||||
end
|
||||
cur = vim.fn.fnamemodify(cur, ":h")
|
||||
end
|
||||
return cur
|
||||
end
|
||||
|
||||
local function is_running(dir)
|
||||
local cached_dir = find_cached_dir(dir)
|
||||
return cached_dir and job_cache[cached_dir]
|
||||
end
|
||||
|
||||
local function is_windows()
|
||||
return vim.loop.os_uname().version:match("Windows")
|
||||
end
|
||||
|
||||
M.toggle = function(dir)
|
||||
local running = is_running(dir)
|
||||
if not running then
|
||||
M.start(dir)
|
||||
return
|
||||
end
|
||||
M.stop(dir)
|
||||
end
|
||||
|
||||
--- Fungsi setup menerima argumen command utama, contoh: require("npmrun").setup("pnpm dev")
|
||||
M.setup = function(cmd)
|
||||
main_cmd = cmd or "npm run dev"
|
||||
if not vim.fn.executable(main_cmd:match("%S+")) then
|
||||
log(main_cmd .. " is not executable. Make sure it is installed and in PATH.", "ERROR")
|
||||
return
|
||||
end
|
||||
|
||||
local function find_dir(args)
|
||||
local dir = args ~= "" and args or "%:p:h"
|
||||
return vim.fn.expand(vim.fn.fnamemodify(vim.fn.expand(dir), ":p"))
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command("DevStart", function(opts)
|
||||
M.start(find_dir(opts.args))
|
||||
end, { nargs = "?" })
|
||||
|
||||
vim.api.nvim_create_user_command("DevStop", function(opts)
|
||||
M.stop(find_dir(opts.args))
|
||||
end, { nargs = "?" })
|
||||
|
||||
vim.api.nvim_create_user_command("DevToggle", function(opts)
|
||||
M.toggle(find_dir(opts.args))
|
||||
end, { nargs = "?" })
|
||||
end
|
||||
|
||||
M.start = function(dir)
|
||||
if is_running(dir) then
|
||||
log(main_cmd .. " already running", "INFO")
|
||||
return
|
||||
end
|
||||
|
||||
local cmd
|
||||
if is_windows() then
|
||||
cmd = { "cmd.exe", "/C" }
|
||||
for word in main_cmd:gmatch("%S+") do
|
||||
table.insert(cmd, word)
|
||||
end
|
||||
else
|
||||
cmd = {}
|
||||
for word in main_cmd:gmatch("%S+") do
|
||||
table.insert(cmd, word)
|
||||
end
|
||||
end
|
||||
|
||||
local buffer_name = "npmrun.txt"
|
||||
local output_buf = open_new_buffer(buffer_name)
|
||||
vim.api.nvim_buf_set_lines(output_buf, 0, -1, false, {})
|
||||
|
||||
local function append_to_buffer(lines)
|
||||
if not lines then
|
||||
return
|
||||
end
|
||||
if not vim.api.nvim_buf_is_valid(output_buf) then
|
||||
return
|
||||
end
|
||||
local filtered = {}
|
||||
for _, l in ipairs(lines) do
|
||||
if l ~= "" then
|
||||
table.insert(filtered, l)
|
||||
end
|
||||
end
|
||||
if #filtered > 0 then
|
||||
local line_count = vim.api.nvim_buf_line_count(output_buf)
|
||||
vim.api.nvim_buf_set_lines(output_buf, line_count, line_count, false, filtered)
|
||||
end
|
||||
end
|
||||
|
||||
local function close_output_buffer()
|
||||
if output_buf and vim.api.nvim_buf_is_valid(output_buf) then
|
||||
vim.api.nvim_buf_delete(output_buf, { force = true })
|
||||
end
|
||||
end
|
||||
|
||||
local job_id = vim.fn.jobstart(cmd, {
|
||||
cwd = dir,
|
||||
stdout_buffered = false, -- streaming mode
|
||||
stderr_buffered = false,
|
||||
on_stdout = function(_, data)
|
||||
append_to_buffer(data)
|
||||
end,
|
||||
on_stderr = function(_, data)
|
||||
append_to_buffer(vim.tbl_map(function(l)
|
||||
return "[ERR] " .. l
|
||||
end, data))
|
||||
end,
|
||||
on_exit = function(_, code)
|
||||
append_to_buffer({ string.format(main_cmd .. " exited with code %d", code) })
|
||||
close_output_buffer()
|
||||
job_cache[dir] = nil
|
||||
end,
|
||||
})
|
||||
|
||||
job_cache[dir] = { job_id = job_id, buf = output_buf }
|
||||
log(main_cmd .. " started", "INFO")
|
||||
end
|
||||
|
||||
M.stop = function(dir)
|
||||
local running = is_running(dir)
|
||||
if running then
|
||||
local cached_dir = find_cached_dir(dir)
|
||||
if cached_dir then
|
||||
local job_entry = job_cache[cached_dir]
|
||||
if job_entry then
|
||||
vim.fn.jobstop(job_entry.job_id)
|
||||
if job_entry.buf and vim.api.nvim_buf_is_valid(job_entry.buf) then
|
||||
vim.api.nvim_buf_delete(job_entry.buf, { force = true })
|
||||
end
|
||||
end
|
||||
job_cache[cached_dir] = nil
|
||||
log(main_cmd .. " stopped", "INFO")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
174
lua/pcode/user/npmrun3.lua
Normal file
174
lua/pcode/user/npmrun3.lua
Normal file
|
@ -0,0 +1,174 @@
|
|||
local function show_modal(text)
|
||||
local buf = vim.api.nvim_create_buf(false, true) -- buffer untuk modal
|
||||
|
||||
vim.api.nvim_buf_set_lines(buf, 0, -1, false, { text, "", "Press q to close" })
|
||||
|
||||
local width = 50
|
||||
local height = 5
|
||||
local row = math.floor((vim.o.lines - height) / 2)
|
||||
local col = math.floor((vim.o.columns - width) / 2)
|
||||
|
||||
local win = vim.api.nvim_open_win(buf, true, {
|
||||
relative = "editor",
|
||||
width = width,
|
||||
height = height,
|
||||
row = row,
|
||||
col = col,
|
||||
style = "minimal",
|
||||
border = "rounded",
|
||||
})
|
||||
|
||||
-- keymap untuk menutup modal dengan 'q'
|
||||
vim.api.nvim_buf_set_keymap(buf, "n", "q", "", {
|
||||
noremap = true,
|
||||
silent = true,
|
||||
callback = function()
|
||||
vim.api.nvim_win_close(win, true)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
local M = {}
|
||||
|
||||
local main_cmd = "npm run dev" -- default
|
||||
|
||||
local function log(message, level)
|
||||
vim.notify(string.format("npm-dev-runner: %s", message), vim.log.levels[level])
|
||||
end
|
||||
|
||||
-- Cache: dir -> { job_id=..., buf=... }
|
||||
local job_cache = {}
|
||||
|
||||
local function find_cached_dir(dir)
|
||||
if not dir then
|
||||
vim.notify("npm-dev-runner: No directory provided to find_cached_dir()", vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
|
||||
local cur = dir
|
||||
while not job_cache[cur] do
|
||||
if cur == "/" or string.match(cur, "^[A-Z]:\\$") then
|
||||
return
|
||||
end
|
||||
cur = vim.fn.fnamemodify(cur, ":h")
|
||||
end
|
||||
return cur
|
||||
end
|
||||
|
||||
local function is_running(dir)
|
||||
local cached_dir = find_cached_dir(dir)
|
||||
return cached_dir and job_cache[cached_dir]
|
||||
end
|
||||
|
||||
local function is_windows()
|
||||
return vim.loop.os_uname().version:match("Windows")
|
||||
end
|
||||
|
||||
M.toggle = function(dir)
|
||||
local running = is_running(dir)
|
||||
if not running then
|
||||
M.start(dir)
|
||||
return
|
||||
end
|
||||
M.stop(dir)
|
||||
end
|
||||
|
||||
--- Fungsi setup menerima argumen command utama, contoh: require("npmrun").setup("pnpm dev")
|
||||
M.setup = function(cmd)
|
||||
main_cmd = cmd or "npm run dev"
|
||||
if not vim.fn.executable(main_cmd:match("%S+")) then
|
||||
log(main_cmd .. " is not executable. Make sure it is installed and in PATH.", "ERROR")
|
||||
return
|
||||
end
|
||||
|
||||
local function find_dir(args)
|
||||
local dir = args ~= "" and args or "%:p:h"
|
||||
return vim.fn.expand(vim.fn.fnamemodify(vim.fn.expand(dir), ":p"))
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command("DevStart", function(opts)
|
||||
M.start(find_dir(opts.args))
|
||||
end, { nargs = "?" })
|
||||
|
||||
vim.api.nvim_create_user_command("DevStop", function(opts)
|
||||
M.stop(find_dir(opts.args))
|
||||
end, { nargs = "?" })
|
||||
|
||||
vim.api.nvim_create_user_command("DevToggle", function(opts)
|
||||
M.toggle(find_dir(opts.args))
|
||||
end, { nargs = "?" })
|
||||
end
|
||||
|
||||
M.start = function(dir)
|
||||
if is_running(dir) then
|
||||
log(main_cmd .. " already running", "INFO")
|
||||
return
|
||||
end
|
||||
|
||||
local cmd
|
||||
if is_windows() then
|
||||
cmd = { "cmd.exe", "/C" }
|
||||
for word in main_cmd:gmatch("%S+") do
|
||||
table.insert(cmd, word)
|
||||
end
|
||||
else
|
||||
cmd = {}
|
||||
for word in main_cmd:gmatch("%S+") do
|
||||
table.insert(cmd, word)
|
||||
end
|
||||
end
|
||||
|
||||
local function append_to_buffer(lines)
|
||||
if not lines then
|
||||
return
|
||||
end
|
||||
|
||||
for _, line in ipairs(lines) do
|
||||
if line ~= "" then
|
||||
line = tostring(line)
|
||||
line = line:gsub("^%s*(.-)%s*$", "%1")
|
||||
if string.find(line, "http") then
|
||||
show_modal(line)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local job_id = vim.fn.jobstart(cmd, {
|
||||
cwd = dir,
|
||||
stdout_buffered = false, -- streaming mode
|
||||
stderr_buffered = false,
|
||||
on_stdout = function(_, data)
|
||||
append_to_buffer(data)
|
||||
end,
|
||||
on_stderr = function(_, data)
|
||||
append_to_buffer(vim.tbl_map(function(l)
|
||||
return "[ERR] " .. l
|
||||
end, data))
|
||||
end,
|
||||
on_exit = function(_, _)
|
||||
job_cache[dir] = nil
|
||||
end,
|
||||
})
|
||||
|
||||
job_cache[dir] = { job_id = job_id }
|
||||
log(main_cmd .. " started", "INFO")
|
||||
end
|
||||
|
||||
M.stop = function(dir)
|
||||
local running = is_running(dir)
|
||||
if running then
|
||||
local cached_dir = find_cached_dir(dir)
|
||||
if cached_dir then
|
||||
local job_entry = job_cache[cached_dir]
|
||||
if job_entry then
|
||||
vim.fn.jobstop(job_entry.job_id)
|
||||
end
|
||||
job_cache[cached_dir] = nil
|
||||
log(main_cmd .. " stopped", "INFO")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
158
lua/pcode/user/npmrun4.lua
Normal file
158
lua/pcode/user/npmrun4.lua
Normal file
|
@ -0,0 +1,158 @@
|
|||
local function show_modal(text)
|
||||
local buf = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_lines(buf, 0, -1, false, { text, "", "Press q to close" })
|
||||
|
||||
local width = 50
|
||||
local height = 5
|
||||
local row = math.floor((vim.o.lines - height) / 2)
|
||||
local col = math.floor((vim.o.columns - width) / 2)
|
||||
|
||||
local win = vim.api.nvim_open_win(buf, true, {
|
||||
relative = "editor",
|
||||
width = width,
|
||||
height = height,
|
||||
row = row,
|
||||
col = col,
|
||||
style = "minimal",
|
||||
border = "rounded",
|
||||
})
|
||||
|
||||
vim.api.nvim_buf_set_keymap(buf, "n", "q", "", {
|
||||
noremap = true,
|
||||
silent = true,
|
||||
callback = function()
|
||||
vim.api.nvim_win_close(win, true)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
local M = {}
|
||||
|
||||
local function log(message, level)
|
||||
vim.notify(string.format("npm-dev-runner: %s", message), vim.log.levels[level])
|
||||
end
|
||||
|
||||
-- Fungsi untuk mencari cache dir (supaya stop/start tetap per dir/project)
|
||||
local function find_cached_dir(dir, cache)
|
||||
if not dir then
|
||||
vim.notify("npm-dev-runner: No directory provided to find_cached_dir()", vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
local cur = dir
|
||||
while not cache[cur] do
|
||||
if cur == "/" or string.match(cur, "^[A-Z]:\\$") then
|
||||
return
|
||||
end
|
||||
cur = vim.fn.fnamemodify(cur, ":h")
|
||||
end
|
||||
return cur
|
||||
end
|
||||
|
||||
-- Fungsi cek proses running
|
||||
local function is_running(dir, cache)
|
||||
local cached_dir = find_cached_dir(dir, cache)
|
||||
return cached_dir and cache[cached_dir]
|
||||
end
|
||||
|
||||
local function is_windows()
|
||||
return vim.loop.os_uname().version:match("Windows")
|
||||
end
|
||||
|
||||
M.setup = function(command_table)
|
||||
command_table = command_table or {}
|
||||
for key, conf in pairs(command_table) do
|
||||
local start_cmd = conf.start or ("NpmRun" .. key)
|
||||
local stop_cmd = conf.stop or ("NpmStop" .. key)
|
||||
local cmd_str = conf.cmd or "npm run dev"
|
||||
|
||||
-- cache khusus untuk mode ini
|
||||
local cache = {}
|
||||
|
||||
-- Fungsi Start
|
||||
local function do_start(dir)
|
||||
if is_running(dir, cache) then
|
||||
log(cmd_str .. " already running", "INFO")
|
||||
return
|
||||
end
|
||||
|
||||
local cmd
|
||||
if is_windows() then
|
||||
cmd = { "cmd.exe", "/C" }
|
||||
for word in cmd_str:gmatch("%S+") do
|
||||
table.insert(cmd, word)
|
||||
end
|
||||
else
|
||||
cmd = {}
|
||||
for word in cmd_str:gmatch("%S+") do
|
||||
table.insert(cmd, word)
|
||||
end
|
||||
end
|
||||
|
||||
local function process_lines(lines)
|
||||
if not lines then
|
||||
return
|
||||
end
|
||||
for _, line in ipairs(lines) do
|
||||
if line ~= "" then
|
||||
local str = tostring(line):gsub("^%s*(.-)%s*$", "%1")
|
||||
if string.find(str, "http") then
|
||||
show_modal(str)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local job_id = vim.fn.jobstart(cmd, {
|
||||
cwd = dir,
|
||||
stdout_buffered = false,
|
||||
stderr_buffered = false,
|
||||
on_stdout = function(_, data)
|
||||
process_lines(data)
|
||||
end,
|
||||
on_stderr = function(_, data)
|
||||
process_lines(vim.tbl_map(function(l)
|
||||
return "[ERR] " .. l
|
||||
end, data))
|
||||
end,
|
||||
on_exit = function(_, _)
|
||||
cache[dir] = nil
|
||||
end,
|
||||
})
|
||||
|
||||
cache[dir] = { job_id = job_id }
|
||||
log(cmd_str .. " started", "INFO")
|
||||
end
|
||||
|
||||
-- Fungsi Stop
|
||||
local function do_stop(dir)
|
||||
local running = is_running(dir, cache)
|
||||
if running then
|
||||
local cached_dir = find_cached_dir(dir, cache)
|
||||
if cached_dir then
|
||||
local job_entry = cache[cached_dir]
|
||||
if job_entry then
|
||||
vim.fn.jobstop(job_entry.job_id)
|
||||
end
|
||||
cache[cached_dir] = nil
|
||||
log(cmd_str .. " stopped", "INFO")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function find_dir(args)
|
||||
local dir = args ~= "" and args or "%:p:h"
|
||||
return vim.fn.expand(vim.fn.fnamemodify(vim.fn.expand(dir), ":p"))
|
||||
end
|
||||
|
||||
-- Register Perintah
|
||||
vim.api.nvim_create_user_command(start_cmd, function(opts)
|
||||
do_start(find_dir(opts.args))
|
||||
end, { nargs = "?" })
|
||||
|
||||
vim.api.nvim_create_user_command(stop_cmd, function(opts)
|
||||
do_stop(find_dir(opts.args))
|
||||
end, { nargs = "?" })
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
|
@ -61,7 +61,7 @@ vim.loader.enable()
|
|||
|
||||
-- Disable statusline in dashboard
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = { "mysql", "dbout", "dbui", "http", "httpResult" },
|
||||
pattern = { "dbout", "dbui", "http", "httpResult", "checkhealth", "qf", "help", "lazy" },
|
||||
callback = function()
|
||||
local opt = vim.opt
|
||||
opt.number = false -- Print line number
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue