Skip to content

Conversation

@jingyi-zhao-01
Copy link

@jingyi-zhao-01 jingyi-zhao-01 commented Sep 17, 2025

below is a sample on_submit hook with working demo

hooks = {
           ["on_submit"] = {
                 function(question, buffer, status_msg)
                   local ts = os.date("%y-%m-%d-%H-%M")
                   local safe_status = (status_msg or "unknown"):gsub("%s+", "_")



                   local submissions_dir =  "/home/jingyi/.local/share/nvim/leetcode/submissions"
                   vim.fn.mkdir(submissions_dir, "p")
           
				   local file = string.format(
					                       "%s/%s-%s-%s.txt",
					                       submissions_dir,
					                       question.q.title_slug,
					                       safe_status,
					                       ts
					                     )           
                   -- write buffer contents
  				   vim.fn.writefile(vim.split(buffer or "", "\n"), file)
           
                   print("Saved submission to", file)
                 end,
               }
          },

2025-09-17-003214_hyprcap.mp4

Copilot AI review requested due to automatic review settings September 17, 2025 07:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new on_submit hook to the LeetCode plugin that triggers when a solution is submitted. The hook provides access to the question, buffer contents, and submission status message.

  • Adds on_submit hook definition to the configuration template
  • Implements hook execution in the runner when a submission is detected
  • Includes utility module import for hook execution

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lua/leetcode/config/template.lua Adds the on_submit hook type definition with proper typing
lua/leetcode/runner/init.lua Imports utils module and executes the on_submit hook when submission is detected

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@kawre
Copy link
Owner

kawre commented Sep 20, 2025

The hook should include information about whether the submission was successful. You can do it by adding a success parameter sourced from item._.success

@jingyi-zhao-01 jingyi-zhao-01 changed the title feat: add onsubmit hook feat: add submit hook Sep 23, 2025
@jingyi-zhao-01
Copy link
Author

jingyi-zhao-01 commented Sep 23, 2025

added ._.success into the hook parameter, it's now up to the hook implementation to how to differentiate successful submission and failure submission in case one wants to thoroughly review his submission quality

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants