Skip to content

Commit 9fa6eba

Browse files
feat: add onsubmit hook
1 parent 10f63d6 commit 9fa6eba

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lua/leetcode/config/template.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
---| "enter"
2525
---| "question_enter"
2626
---| "leave"
27+
---| "on_submit"
2728

2829
---@alias lc.size
2930
---| string
@@ -120,6 +121,10 @@ local M = {
120121

121122
---@type fun()[]
122123
["leave"] = {},
124+
125+
---@type fun(question: lc.ui.Question, buffer: string, status_msg: string|nil)[]
126+
["on_submit"] = {},
127+
123128
},
124129

125130
keys = {

lua/leetcode/runner/init.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local log = require("leetcode.logger")
44
local interpreter = require("leetcode.api.interpreter")
55
local config = require("leetcode.config")
66
local Judge = require("leetcode.logger.spinner.judge")
7+
local utils = require("leetcode.utils")
78

89
---@type Path
910
local leetbody = config.storage.cache:joinpath("body")
@@ -64,7 +65,11 @@ function Runner:handle(submit)
6465
end
6566

6667
if item then
67-
question.console.result:handle(item)
68+
question.console.result:handle(item)
69+
70+
if item._.submission then
71+
utils.exec_hooks("on_submit", question, body.typed_code, item.status_msg)
72+
end
6873
end
6974
end
7075

0 commit comments

Comments
 (0)