From 615433f5772748d8beaa4eef61082ac39c7c5c3b Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Wed, 5 Aug 2026 03:19:05 +0300 Subject: Refactor compile/task system thing to be more flexible, can now define any number of tasks instead of just hardcoding build/run/test --- .config/nvim/lua/keymaps.lua | 38 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) (limited to '.config/nvim/lua/keymaps.lua') diff --git a/.config/nvim/lua/keymaps.lua b/.config/nvim/lua/keymaps.lua index a5c1aad..20d977d 100644 --- a/.config/nvim/lua/keymaps.lua +++ b/.config/nvim/lua/keymaps.lua @@ -204,36 +204,20 @@ vim.api.nvim_create_autocmd('LspAttach', { end, }) -local compile = function() - if vim.g.project_compile_cmd then - Compile_project(vim.g.project_compile_cmd) - -- vim.notify(vim.g.project_compile_cmd) - else - vim.notify('vim.g.project_compile_cmd is not set', 'warn') - end -end -local run = function() - if vim.g.project_run_cmd then - Compile_project(vim.g.project_run_cmd) - -- vim.notify(vim.g.project_run_cmd) - else - vim.notify('vim.g.project_run_cmd is not set', 'warn') - end -end -local test = function() - if vim.g.project_test_cmd then - Compile_project(vim.g.project_test_cmd) - -- vim.notify(vim.g.project_test_cmd) - else - vim.notify('vim.g.project_test_cmd is not set', 'warn') +function RunTask(task_name) + return function() + local task = vim.g.workspace_tasks[task_name] + if task and task.cmd then + RunCommand(task.cmd) + else + vim.notify('either ' .. task_name .. "or vim.g.workspace_tasks[task_name].cmd don't exist", 'warn') + end end end -vim.keymap.set('n', '', compile, { desc = 'Idk? lol' }) -vim.keymap.set('n', '', compile, { desc = '[C]ompile Project' }) -vim.keymap.set('n', '', compile, { desc = '[B]uild Project' }) -vim.keymap.set('n', '', run, { desc = '[R]un Project' }) -vim.keymap.set('n', '', test, { desc = '[T]est Project' }) +vim.keymap.set('n', '', RunTask('build'), { desc = '[B]uild Project' }) +vim.keymap.set('n', '', RunTask('run'), { desc = '[R]un Project' }) +vim.keymap.set('n', '', RunTask('test'), { desc = '[T]est Project' }) vim.keymap.set('n', '', function() Run_nvim_lua() -- cgit v1.3.1