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
417 stars 20 forks source link

Template file is not used when received problems path is set to a function #45

Closed hhdqirui closed 1 year ago

hhdqirui commented 1 year ago

When received_problems_path is set to a string or function as shown in readme, the template file specified for template_file is not being used.

xeluxee commented 1 year ago

Cannot reproduce. Please provide more details and share your CompetiTest setup().

hhdqirui commented 1 year ago

Below is my setup.

return {
        {
                'xeluxee/competitest.nvim',
                dependencies = 'MunifTanjim/nui.nvim',
                config = function()
                        require('competitest').setup({
                                runner_ui = {
                                        interface = "split",
                                },
                                split_ui = {
                                        position = "right",
                                        relative_to_editor = false,
                                        total_width = 0.3,
                                        vertical_layout = {
                                                { 1, "tc" },
                                                { 1, { { 1, "so" }, { 1, "eo" } } },
                                                { 1, { { 1, "si" }, { 1, "se" } } },
                                        },
                                        total_height = 0.4,
                                        horizontal_layout = {
                                                { 2, "tc" },
                                                { 3, { { 1, "so" }, { 1, "si" } } },
                                                { 3, { { 1, "eo" }, { 1, "se" } } },
                                        },
                                },
                                view_output_diff = true,
                                receive_print_message = true,
                                template_file = {
                                        cpp = "~/cp/template.cpp",
                                },
                                evaluate_template_modifiers = true,
                                received_files_extension = "cpp",
                                received_problems_prompt_path = false,
                                received_problems_path = function(task, file_extension)
                                        local hyphen = string.find(task.group, " - ")
                                        local judge, contest
                                        if not hyphen then
                                                judge = task.group
                                                local slash = string.find(task.url, "/[^/]*$");
                                                local name = string.sub(task.url, slash + 1, string.len(task.url))
                                                return string.format("~/cp/%s/%s.%s", judge, name, file_extension)
                                        else
                                                judge = string.sub(task.group, 1, hyphen - 1)
                                                contest = string.sub(task.group, hyphen + 3)
                                        end
                                        return string.format("~/cp/%s/%s/%s.%s", judge, contest, task.name, file_extension)
                                 end,
                        })
                end,
        }
}
hhdqirui commented 1 year ago

@xeluxee sorry, only setting received_problem_path to a function will have this issue.

xeluxee commented 1 year ago

@hhdqirui your issue could be related to tilde. Replace this

return string.format("~/cp/%s/%s/%s.%s", judge, contest, task.name, file_extension)

with this

return string.format("%s/cp/%s/%s/%s.%s", vim.loop.os_homedir(), judge, contest, task.name, file_extension)

As README states, when received_problems_path is a function it should return the absolute path to store received problem. Here tilde is recognized as a directory and files are stored there.

hhdqirui commented 1 year ago

Thank you so much for your help! It works! Thank you for your plugin! It is great!