Skip to content

Commit

Permalink
feat: add ExercismSubmit command
Browse files Browse the repository at this point in the history
  • Loading branch information
2KAbhishek committed Nov 21, 2024
1 parent 165f434 commit 802f8e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lua/exercism/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ M.setup = function()
main.test_exercise()
end, {})

vim.api.nvim_create_user_command('ExercismSubmit', function(_)
main.submit_exercise()
end, {})

if config.add_default_keybindings then
local function add_keymap(keys, cmd, desc)
vim.api.nvim_set_keymap('n', keys, cmd, { noremap = true, silent = true, desc = desc })
Expand All @@ -21,6 +25,7 @@ M.setup = function()
if config.add_default_keybindings then
add_keymap('<leader>exl', ':ExercismList<CR>', 'Exercism List')
add_keymap('<leader>ext', ':ExercismTest<CR>', 'Exercism Test')
add_keymap('<leader>exs', ':ExercismSubmit<CR>', 'Exercism Submit')
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions lua/exercism/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,17 @@ M.test_exercise = function()
end
end

M.submit_exercise = function()
local submit_cmd = 'exercism submit'
utils.async_shell_execute(submit_cmd, function(result)
if result then
vim.schedule(function()
local output = type(result) == 'table' and table.concat(result, '\n') or tostring(result)
local message = string.format('Exercise submitted successfully!\n%s', vim.trim(output))
utils.show_notification(message, vim.log.levels.INFO, 'Exercism')
end)
end
end)
end

return M

0 comments on commit 802f8e0

Please sign in to comment.