xeluxee / competitest.nvim

CompetiTest.nvim is a Neovim plugin for Competitive Programming: it can manage and check testcases, download problems and contests from online judges and much more
GNU Lesser General Public License v3.0
381 stars 15 forks source link

feat: head comments #39

Closed D4NZ-jpg closed 11 months ago

D4NZ-jpg commented 1 year ago

I've added this new feature that I personally find really neat to keep track of my solutions, and I think it could benefit others too.

The idea behind this feature is to provide users with the ability to add a header comment at the start of each file automatically. This feature is useful for adding metadata about the problem such as the problem name, group, URL, memory limit, time limit and the starting time.

If you decide to add a comment, you can use specific modifiers to insert dynamic information. For example, you can set the head_comment variable to "//This file was generated at $(TIME)", and it will automatically insert the current time in your preferred format, which can be specified with the time_format option, which allows you to specify how you'd like to display the time in your header comment.

This feature is not mandatory; if you don't want a comment in your files, just set the head_comment variable to false.

The way I like to use it is something like this:

head_comment = "//Problem: $(NAME)\n//Contest: $(GROUP)\n//URL: $(URL)\n//Memory Limit: $(MEMLIM) MB\n//Time Limit: $(TIMELIM) ms\n//Start: $(TIME)",
time_format = "%d-%m-%Y %H:%M:%S"

which produces something like this on the top of every file:

//Problem: A. Forbidden Integer
//Contest: Codeforces - Educational Codeforces Round 151 (Rated for Div. 2)
//URL: https://codeforces.com/contest/1845/problem/A
//Memory Limit: 256 MB
//Time Limit: 2000 ms
//Start: 06-07-2023 13:00:17
...
xeluxee commented 1 year ago

CompetiTest can be configured to create source files from templates for received problems and contests, see template_file. I think it'd be more straightforward to integrate head comments into templates, not only because a single string would make configuration long and unreadable, but also because different filetypes have different comments, e.g. double slash won't work with python. So the option head_comment should be substituted by a boolean evaluate_templates, to let users decide whether to enable this feature or not.

Regarding new modifiers, they should be kept separated from file format modifiers. We already discussed about $(CONTEST) and $(JUDGE) modifers in #28 and #29. See also competitive companion format: https://github.com/jmerle/competitive-companion#the-format

I suggest the following receive-modifers, that will be used to evaluate contests_directory, problems_directory (from #29) and header comments in template files.

modifier meaning
$(PROBLEM) Problem name, name field
$(GROUP) judge and contest name, group field
$(JUDGE) first part of group, before hyphen
$(CONTEST) second part of group, after hyphen
$(URL) problem url, url field
$(MEMLIM) available memory, memoryLimit field
$(TIMELIM) time limit, timeLimit field
$(HOME) home directory
$(DATE) current time, following date_format

@D4NZ-jpg wait before proceeding with commits until we reach an agreement about what to do

xeluxee commented 11 months ago

Now that #40 is closed and receive modifiers (previously called comment modifiers) are implemented, you should rebase this PR or make it from scratch (don't worry, it'll be easier). Here are some suggestions:

  1. Add date_format (string) and evaluate_template_modifiers (boolean) options
  2. Take a look at lua/competitest/receive.lua: use eval_receive_modifiers() to substitute modifiers from loaded file
  3. Add $(DATE) modifier among the others, get date_format as function argument in eval_receive_modifiers()
  4. Templates creation should be managed by store_problem_config and store_problem functions
  5. To do that the third argument of store_problem_config, tclist, should be replaced by task, a table with all task details
D4NZ-jpg commented 11 months ago

Got it. Will make the changes soon.

D4NZ-jpg commented 11 months ago

@xeluxee done, does everything seems okay?

xeluxee commented 11 months ago

This PR looks ready to be merged

D4NZ-jpg commented 11 months ago

Great, thanks!