@@ -68,7 +68,7 @@ function! leetcode#Submission() abort
6868 endif
6969 try
7070 let problem_slug = s: ProblemSlugFromFileName ()
71- call s: ListSubmissions (problem_slug, 1 )
71+ call s: ListSubmissions (problem_slug, 0 )
7272 catch
7373 echo " invalid filename, not found submission"
7474 endtry
@@ -728,6 +728,58 @@ function! s:SolutionFileExt(filetype) abort
728728 return s: file_type_to_ext [a: filetype ]
729729endfunction
730730
731+ function ! leetcode#Problem () abort
732+ if s: CheckSignIn () == v: false
733+ return
734+ endif
735+
736+ let problem_slug = s: ProblemSlugFromFileName ()
737+ let expr = printf (' leetcode.get_problem("%s")' , problem_slug)
738+ let problem = py3eval (expr )
739+ if type (problem) != v: t_dict
740+ return
741+ endif
742+
743+ let filetype = s: GuessFileType ()
744+ if ! has_key (problem[' templates' ], filetype )
745+ echo ' the file type is not supported: ' . filetype
746+ return
747+ endif
748+
749+ let problem_desc_file_name = printf (' [DESCRIPTION] %s.%s.%s' , problem[' fid' ], problem_slug, filetype )
750+ if buflisted (problem_desc_file_name)
751+ execute bufnr (problem_desc_file_name) . ' buffer'
752+ return
753+ endif
754+
755+ let output = []
756+ call add (output, s: CommentStart (filetype , problem[' title' ]))
757+ let meta_format = ' [%s] [AC:%s %s of %s] [filetype:%s]'
758+ let meta = printf (meta_format, problem[' level' ], problem[' ac_rate' ],
759+ \ problem[' total_accepted' ], problem[' total_submission' ],
760+ \ filetype )
761+ call add (output, s: CommentLine (filetype , ' ' ))
762+ call add (output, s: CommentLine (filetype , meta))
763+ call add (output, s: CommentLine (filetype , ' ' ))
764+ for line in problem[' desc' ]
765+ call add (output, s: CommentLine (filetype , line ))
766+ endfor
767+ call add (output, s: CommentEnd (filetype ))
768+
769+ execute ' vertical ' . ' new ' . problem_desc_file_name
770+ " execute 'leftabove '. len(output). 'new ' . problem_desc_file_name
771+ call append (' $' , output)
772+ silent ! normal ! ggdd
773+ silent ! normal ! gggqG
774+
775+ setlocal nomodifiable
776+ setlocal buftype = nofile
777+ setlocal nospell
778+ setlocal bufhidden = delete
779+
780+ execute ' wincmd j'
781+ endfunction
782+
731783function ! leetcode#ResetSolution (with_latest_submission, select_filetype) abort
732784 if s: CheckSignIn () == v: false
733785 return
@@ -1212,6 +1264,7 @@ function! s:ListSubmissions(slug, refresh) abort
12121264 hi ! lcNA ctermfg= gray guifg= gray
12131265 endif
12141266
1267+
12151268 let b: leetcode_problem_slug = a: slug
12161269
12171270 let expr = printf (' leetcode.get_submissions("%s")' , a: slug )
0 commit comments