@@ -275,13 +275,38 @@ function cmd.reset()
275
275
if not q then return end
276
276
277
277
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
281
279
vim .api .nvim_buf_set_lines (q .bufnr , 0 , - 1 , false , vim .split (snip , " \n " ))
282
280
end
283
281
end
284
282
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
+
285
310
function cmd .fix ()
286
311
require (" leetcode.cache.cookie" ).delete ()
287
312
require (" leetcode.cache.problemlist" ).delete ()
@@ -411,7 +436,7 @@ cmd.commands = {
411
436
yank = { cmd .yank },
412
437
open = { cmd .open },
413
438
reset = { cmd .reset },
414
- last_submission = { cmd .last_submission },
439
+ last_submit = { cmd .last_submit },
415
440
416
441
list = {
417
442
cmd .problems ,
0 commit comments