6
6
; ; Keywords: extensions, tools
7
7
; ; URL: https://github.com/kaiwk/leetcode.el
8
8
; ; Package-Requires: ((emacs "26") (dash "2.16.0") (graphql "0.1.1") (spinner "1.7.3") (aio "1.0"))
9
- ; ; Version: 0.1.7
9
+ ; ; Version: 0.1.8
10
10
11
11
; ; This program is free software; you can redistribute it and/or modify
12
12
; ; it under the terms of the GNU General Public License as published by
@@ -79,11 +79,12 @@ The elements of :problems has attributes:
79
79
:tags List" )
80
80
81
81
(defvar leetcode--all-tags nil
82
- " Problems tags" )
82
+ " All problems tags. " )
83
83
84
84
(defvar leetcode--problem-titles nil
85
85
" Problem titles that have been open in solving layout." )
86
86
87
+ (defvar leetcode-retry-threshold 20 " `leetcode-try' or `leetcode-submit' retry times." )
87
88
(defvar leetcode--filter-regex nil " Filter rows by regex." )
88
89
(defvar leetcode--filter-tag nil " Filter rows by leetcode tag." )
89
90
@@ -138,6 +139,7 @@ The elements of :problems has attributes:
138
139
(defconst leetcode--api-try (concat leetcode--base-url " /problems/%s/interpret_solution/" ))
139
140
140
141
(defun to-list (vec )
142
+ " Convert VEC to list."
141
143
(append vec '()))
142
144
143
145
(defun leetcode--referer (value )
@@ -270,8 +272,7 @@ USER-AND-PROBLEMS is an alist comes from
270
272
problems)))))
271
273
272
274
(defun leetcode--set-tags (all-tags )
273
- " Set `leetcode--all-tags' and `leetcode--all-problems' with
274
- ALL-TAGS."
275
+ " Set `leetcode--all-tags' and `leetcode--all-problems' with ALL-TAGS."
275
276
(let-alist all-tags
276
277
; ; set problems tags
277
278
(dolist (problem (plist-get leetcode--all-problems :problems ))
@@ -417,7 +418,7 @@ Return a list of rows, each row is a vector:
417
418
rows))
418
419
419
420
(defun leetcode--filter (rows )
420
- " Filter ROWS by `leetcode--filter-regex' and `leetcode--filter-tag' "
421
+ " Filter ROWS by `leetcode--filter-regex' and `leetcode--filter-tag' . "
421
422
(seq-filter
422
423
(lambda (row )
423
424
(and
@@ -445,7 +446,7 @@ Return a list of rows, each row is a vector:
445
446
(leetcode-refresh))
446
447
447
448
(defun leetcode-set-filter-tag ()
448
- " Set `leetcode--filter-tag' "
449
+ " Set `leetcode--filter-tag' . "
449
450
(interactive )
450
451
(setq leetcode--filter-tag
451
452
(completing-read " Tags: " leetcode--all-tags))
@@ -540,12 +541,12 @@ see: https://github.com/skeeto/emacs-aio/issues/3."
540
541
(testcase-buf (get-buffer leetcode--testcase-buffer-name))
541
542
(slug-title (with-current-buffer code-buf
542
543
(file-name-base (buffer-name ))))
543
- (id ( plist-get (seq-find (lambda (p )
544
- (equal slug-title
545
- (leetcode--slugify-title
546
- (plist-get p :title ))))
547
- (plist-get leetcode--all-problems :problems ))
548
- :id )))
544
+ (cur-problem (seq-find (lambda (p )
545
+ (equal slug-title
546
+ (leetcode--slugify-title
547
+ (plist-get p :title ))))
548
+ (plist-get leetcode--all-problems :problems ) ))
549
+ (id ( plist-get cur-problem :id )))
549
550
(let* ((url-request-method " POST" )
550
551
(url-request-extra-headers
551
552
`(, leetcode--User-Agent
@@ -572,42 +573,40 @@ see: https://github.com/skeeto/emacs-aio/issues/3."
572
573
(with-current-buffer res-buf
573
574
(erase-buffer )
574
575
(insert (concat " Your input:\n " .test_case " \n\n " )))
575
- ; ; poll expected
576
- (let ((expected_res (aio-await (leetcode--check-submission .interpret_expected_id slug-title))))
577
- (while (not expected_res)
578
- (aio-await (aio-sleep 0.5 ))
579
- (setq expected_res (aio-await (leetcode--check-submission .interpret_expected_id slug-title))))
580
- (let ((answer (aref (alist-get 'code_answer expected_res) 0 )))
581
- (with-current-buffer res-buf
582
- (insert (concat " Expected:\n " answer " \n\n " )))))
583
576
; ; poll interpreted
584
- (let ((actual_res (aio-await (leetcode--check-submission .interpret_id slug-title))))
585
- (while (not actual_res)
577
+ (let ((actual_res (aio-await (leetcode--check-submission .interpret_id slug-title)))
578
+ (retry-times 0 ))
579
+ (while (and (not actual_res) (< retry-times leetcode-retry-threshold))
586
580
(aio-await (aio-sleep 0.5 ))
587
- (setq actual_res (aio-await (leetcode--check-submission .interpret_id slug-title))))
588
- (let-alist actual_res
589
- (with-current-buffer res-buf
590
- (insert " Output:\n " )
591
- (cond
592
- ((eq .status_code 10 )
593
- (insert (aref .code_answer 0 )))
594
- ((eq .status_code 14 )
595
- (insert .status_msg))
596
- ((eq .status_code 15 )
597
- (insert .status_msg)
598
- (insert " \n\n " )
599
- (insert .full_runtime_error))
600
- ((eq .status_code 20 )
601
- (insert .status_msg)
602
- (insert " \n\n " )
603
- (insert .full_compile_error)))
604
- (when (> (length .code_output) 0 )
605
- (insert " \n\n " )
606
- (insert " Code output:\n " )
607
- (dolist (item (append .code_output nil ))
608
- (insert (concat item " \n " ))))
609
- (insert " \n\n " )
610
- (leetcode--loading-mode -1 ))))))))))
581
+ (setq actual_res (aio-await (leetcode--check-submission .interpret_id slug-title)))
582
+ (setq retry-times (1+ retry-times)))
583
+ (if (< retry-times leetcode-retry-threshold)
584
+ (let-alist actual_res
585
+ (with-current-buffer res-buf
586
+ (goto-char (point-max ))
587
+ (insert (concat " Expected:\n " (aref .expected_code_answer 0 ) " \n\n " ))
588
+ (insert " Output:\n " )
589
+ (cond
590
+ ((eq .status_code 10 )
591
+ (insert (aref .code_answer 0 )))
592
+ ((eq .status_code 14 )
593
+ (insert .status_msg))
594
+ ((eq .status_code 15 )
595
+ (insert .status_msg)
596
+ (insert " \n\n " )
597
+ (insert .full_runtime_error))
598
+ ((eq .status_code 20 )
599
+ (insert .status_msg)
600
+ (insert " \n\n " )
601
+ (insert .full_compile_error)))
602
+ (when (> (length .code_output) 0 )
603
+ (insert " \n\n " )
604
+ (insert " Code output:\n " )
605
+ (dolist (item (append .code_output nil ))
606
+ (insert (concat item " \n " ))))
607
+ (insert " \n\n " )))
608
+ (message " LeetCode try timeout. " )))
609
+ (leetcode--loading-mode -1 )))))))
611
610
612
611
(aio-defun leetcode--check-submission (submission-id slug-title)
613
612
" Polling to check submission detail.
@@ -764,12 +763,16 @@ following possible value:
764
763
(progn (goto-char url-http-end-of-headers)
765
764
(json-read ))))
766
765
(submission-id (alist-get 'submission_id resp))
767
- (submission-res (aio-await (leetcode--check-submission submission-id slug-title))))
766
+ (submission-res (aio-await (leetcode--check-submission submission-id slug-title)))
767
+ (retry-times 0 ))
768
768
; ; poll submission result
769
- (while (not submission-res)
769
+ (while (and ( not submission-res) ( < retry-times leetcode-retry-threshold) )
770
770
(aio-await (aio-sleep 0.5 ))
771
- (setq submission-res (aio-await (leetcode--check-submission submission-id slug-title))))
772
- (leetcode--show-submission-result submission-res)
771
+ (setq submission-res (aio-await (leetcode--check-submission submission-id slug-title)))
772
+ (setq retry-times (1+ retry-times)))
773
+ (if (< retry-times leetcode-retry-threshold)
774
+ (leetcode--show-submission-result submission-res)
775
+ (message " LeetCode submit timeout. " ))
773
776
(leetcode--loading-mode -1 ))))))
774
777
775
778
(defun leetcode--problem-link (title )
0 commit comments