@@ -275,13 +275,38 @@ function cmd.reset()
275275 if not q then return end
276276
277277 local snip = q :get_snippet ()
278- if not snip then return end
279-
280- if vim .api .nvim_buf_is_valid (q .bufnr ) then
278+ if snip and vim .api .nvim_buf_is_valid (q .bufnr ) then
281279 vim .api .nvim_buf_set_lines (q .bufnr , 0 , - 1 , false , vim .split (snip , " \n " ))
282280 end
283281end
284282
283+ function cmd .last_submit ()
284+ local utils = require (" leetcode.utils" )
285+ utils .auth_guard ()
286+ local q = utils .curr_question ()
287+ if not q then return end
288+
289+ local question_api = require (" leetcode.api.question" )
290+ question_api .latest_submission (q .q .id , q .lang , function (res , err ) --
291+ if err then
292+ if err .status == 404 then
293+ log .error (" You haven't submitted any code!" )
294+ else
295+ log .err (err )
296+ end
297+
298+ return
299+ end
300+
301+ if type (res ) == " table" and res .code and vim .api .nvim_buf_is_valid (q .bufnr ) then
302+ local code = q :injector (res .code )
303+ vim .api .nvim_buf_set_lines (q .bufnr , 0 , - 1 , false , vim .split (code , " \n " ))
304+ else
305+ log .error (" Something went wrong" )
306+ end
307+ end )
308+ end
309+
285310function cmd .fix ()
286311 require (" leetcode.cache.cookie" ).delete ()
287312 require (" leetcode.cache.problemlist" ).delete ()
@@ -411,7 +436,7 @@ cmd.commands = {
411436 yank = { cmd .yank },
412437 open = { cmd .open },
413438 reset = { cmd .reset },
414- last_submission = { cmd .last_submission },
439+ last_submit = { cmd .last_submit },
415440
416441 list = {
417442 cmd .problems ,
0 commit comments