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

Add template functionality #26

Closed ayham-1 closed 1 year ago

ayham-1 commented 1 year ago

Added template_file configuration option.

In order to accommodate for multiple languages, $(FEXT) modifier is used.

xeluxee commented 1 year ago

In order to accommodate for multiple languages, $(FEXT) modifier is used.

Modifiers looks like an unnecessary complication for this task.

I think a template_files option would be clearer:

template_files = {
  c = "/path/to/file.c",    -- absoulte path
  cpp = "~/path/to/file.cpp",    -- path starting from home directory
  py = "~/path/to/file.py",
}

CompetiTest asks for file extension when download a problem or a contest, so you can use it to determine if a template file is configured. If it's not configured you just create an empty file.

ayham-1 commented 1 year ago

In order to accommodate for multiple languages, $(FEXT) modifier is used.

Modifiers looks like an unnecessary complication for this task.

I think a template_files option would be clearer:

template_files = {
  c = "/path/to/file.c",    -- absoulte path
  cpp = "~/path/to/file.cpp",    -- path starting from home directory
  py = "~/path/to/file.py",
}

CompetiTest asks for file extension when download a problem or a contest, so you can use it to determine if a template file is configured. If it's not configured you just create an empty file.

I would say that there is no real use to having explicit per language template file configuration. The only real situation where this is useful is when one has templates all over his system, which is unorganized.

It should also be noted that if the user has the template files in the same directory he would need to write multiple file paths for multiple templates, which most likely would have the pattern of path/template.$(FEXT).

MuhammadSawalhy commented 1 year ago

which most likely would have the pattern of path/template.$(FEXT).

Agree

xeluxee commented 1 year ago

It should also be noted that if the user has the template files in the same directory he would need to write multiple file paths for multiple templates, which most likely would have the pattern of path/template.$(FEXT).

You're right, but this could be constraining for some users.

So I propose the following changes:

xeluxee commented 1 year ago

@ayham-1 @MuhammadSawalhy please try out latest commit

MuhammadSawalhy commented 1 year ago

🎉 It works

But I don't get any error message when the template file doesn't exist.

xeluxee commented 1 year ago

But I don't get any error message when the template file doesn't exist.

That's intended, because users may like to use templates only for some filetypes

MuhammadSawalhy commented 1 year ago

That's intended, because users may like to use templates only for some filetypes

Ok, I think this is a good idea for this.

  template_file = "~/myp/problem-solving/template.$(FEXT)"

But this should display something indicating that the file doesn't exist. I'm ok with the current behaviour but let's make it better.

  template_file = {
    cpp = "~/myp/problem-solving/tempate.cpp"
  },
MuhammadSawalhy commented 1 year ago

I can't test the template feature with contests. The issue exists in the master branch.

image

ayham-1 commented 1 year ago

@ayham-1 @MuhammadSawalhy please try out latest commit

Does work on my side.

ayham-1 commented 1 year ago

I can't test the template feature with contests. The issue exists in the master branch.

image

Contest clone does work using the latest comment in add-template-functionality branch

MuhammadSawalhy commented 1 year ago

It also doesn't work with latest commit in master branch of xeluxee/competitest.nvim

xeluxee commented 1 year ago

I can't test the template feature with contests. The issue exists in the master branch.

image

Cannot reproduce. What command have you launched? What commit are you using?

xeluxee commented 1 year ago

But this should display something indicating that the file doesn't exist. I'm ok with the current behaviour but let's make it better.

Thanks for pointing that out. Fixed with 054738c