Refactor compile/task system thing to be more flexible, can now define

any number of tasks instead of just hardcoding build/run/test
This commit is contained in:
2026-08-05 03:19:05 +03:00
parent 0e25e3f5d9
commit 615433f577
2 changed files with 20 additions and 37 deletions

View File

@@ -385,7 +385,7 @@ vim.api.nvim_create_autocmd('TermOpen', {
----------------------------------------------------------------------------
-- NOTE: Compile a project by opening a terminal, inspired by Casey's workflow
----------------------------------------------------------------------------
function Compile_project(command)
function RunCommand(command)
local x = 2
local y = 1
local filter = function(win)
@@ -631,10 +631,11 @@ function JumpToDiagnostic(direction, is_error, is_warning)
end, 0) -- in milliseconds
vim.defer_fn(function()
if vim.g.project_compile_cmd then
Compile_project(vim.g.project_compile_cmd)
local build_task = vim.g.workspace_tasks['build']
if build_task and build_task.cmd then
RunCommand(build_task.cmd)
else
vim.notify('vim.g.project_compile_cmd missing', 'warn')
vim.notify('vim.g.workspace_tasks["build"].cmd missing', 'warn')
end
end, 100) -- in milliseconds
end
@@ -648,11 +649,11 @@ function JumpToPrevError()
end
function JumpToNextWarning()
return JumpToDiagnostic(1, true, true)
return JumpToDiagnostic(1, false, true)
end
function JumpToPrevWarning()
return JumpToDiagnostic(-1, true, true)
return JumpToDiagnostic(-1, false, true)
end
----------------------------------------------------------------------------
@@ -980,15 +981,13 @@ local function open_scratch_buffer_map(is_global)
end
end
vim.keymap.set('n', '<leader>ge', open_scratch_buffer_map(true))
vim.keymap.set('n', '<leader>we', open_scratch_buffer_map(false))
vim.keymap.set('n', '<leader>go', open_scratch_buffer_map(true))
vim.keymap.set('n', '<leader>so', open_scratch_buffer_map(false))
----------------------------------------------------------------------------
-- NOTE: Insert commit msg into commit buffer in neogit
----------------------------------------------------------------------------
local commit_msg = 'Your default commit message\nTest\nMultiline'
local group = vim.api.nvim_create_augroup('NeogitCommitMessage', { clear = true })
vim.api.nvim_create_autocmd('FileType', {

View File

@@ -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', '<A-m>', compile, { desc = 'Idk? lol' })
vim.keymap.set('n', '<A-c>', compile, { desc = '[C]ompile Project' })
vim.keymap.set('n', '<A-b>', compile, { desc = '[B]uild Project' })
vim.keymap.set('n', '<A-r>', run, { desc = '[R]un Project' })
vim.keymap.set('n', '<A-t>', test, { desc = '[T]est Project' })
vim.keymap.set('n', '<A-b>', RunTask('build'), { desc = '[B]uild Project' })
vim.keymap.set('n', '<A-r>', RunTask('run'), { desc = '[R]un Project' })
vim.keymap.set('n', '<A-t>', RunTask('test'), { desc = '[T]est Project' })
vim.keymap.set('n', '<A-s>', function()
Run_nvim_lua()