feat: remove default contest
This commit is contained in:
parent
d5395b20ab
commit
b679e2b932
5 changed files with 81 additions and 134 deletions
|
|
@ -39,6 +39,7 @@
|
|||
---@class Hooks
|
||||
---@field before_run? fun(ctx: HookContext)
|
||||
---@field before_debug? fun(ctx: HookContext)
|
||||
---@field setup_code? fun(ctx: HookContext)
|
||||
|
||||
---@class cp.Config
|
||||
---@field contests table<string, ContestConfig>
|
||||
|
|
@ -67,78 +68,18 @@ local filetype_to_language = {
|
|||
|
||||
---@type cp.Config
|
||||
M.defaults = {
|
||||
contests = {
|
||||
default = {
|
||||
cpp = {
|
||||
compile = {
|
||||
"g++",
|
||||
"-std=c++{version}",
|
||||
"-O2",
|
||||
"-DLOCAL",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"{source}",
|
||||
"-o",
|
||||
"{binary}",
|
||||
},
|
||||
run = { "{binary}" },
|
||||
debug = {
|
||||
"g++",
|
||||
"-std=c++{version}",
|
||||
"-g3",
|
||||
"-fsanitize=address,undefined",
|
||||
"-DLOCAL",
|
||||
"{source}",
|
||||
"-o",
|
||||
"{binary}",
|
||||
},
|
||||
executable = nil,
|
||||
version = 20,
|
||||
extension = "cc",
|
||||
},
|
||||
python = {
|
||||
compile = nil,
|
||||
run = { "{source}" },
|
||||
debug = { "{source}" },
|
||||
executable = "python3",
|
||||
extension = "py",
|
||||
},
|
||||
default_language = "cpp",
|
||||
timeout_ms = 2000,
|
||||
},
|
||||
---@type PartialContestConfig
|
||||
atcoder = {
|
||||
---@type PartialLanguageConfig
|
||||
cpp = { version = 23 },
|
||||
},
|
||||
---@type PartialContestConfig
|
||||
codeforces = {
|
||||
---@type PartialLanguageConfig
|
||||
cpp = { version = 23 },
|
||||
},
|
||||
---@type PartialContestConfig
|
||||
cses = {
|
||||
---@type PartialLanguageConfig
|
||||
cpp = { version = 20 },
|
||||
},
|
||||
},
|
||||
contests = {},
|
||||
snippets = {},
|
||||
hooks = {
|
||||
before_run = nil,
|
||||
before_debug = nil,
|
||||
setup_code = nil,
|
||||
},
|
||||
debug = false,
|
||||
tile = nil,
|
||||
filename = nil,
|
||||
}
|
||||
|
||||
---@param base_config table
|
||||
---@param contest_config table
|
||||
---@return table
|
||||
local function extend_contest_config(base_config, contest_config)
|
||||
local result = vim.tbl_deep_extend("force", base_config, contest_config)
|
||||
return result
|
||||
end
|
||||
|
||||
---@param user_config cp.UserConfig|nil
|
||||
---@return cp.Config
|
||||
|
|
@ -161,6 +102,7 @@ function M.setup(user_config)
|
|||
vim.validate({
|
||||
before_run = { user_config.hooks.before_run, { "function", "nil" }, true },
|
||||
before_debug = { user_config.hooks.before_debug, { "function", "nil" }, true },
|
||||
setup_code = { user_config.hooks.setup_code, { "function", "nil" }, true },
|
||||
})
|
||||
end
|
||||
|
||||
|
|
@ -185,14 +127,6 @@ function M.setup(user_config)
|
|||
end
|
||||
|
||||
local config = vim.tbl_deep_extend("force", M.defaults, user_config or {})
|
||||
|
||||
local default_contest = config.contests.default
|
||||
for contest_name, contest_config in pairs(config.contests) do
|
||||
if contest_name ~= "default" then
|
||||
config.contests[contest_name] = extend_contest_config(default_contest, contest_config)
|
||||
end
|
||||
end
|
||||
|
||||
return config
|
||||
end
|
||||
|
||||
|
|
@ -218,9 +152,18 @@ local function default_filename(contest, contest_id, problem_id, config, languag
|
|||
end
|
||||
end
|
||||
|
||||
local contest_config = config.contests[contest] or config.contests.default
|
||||
local contest_config = config.contests[contest]
|
||||
local target_language = language or contest_config.default_language
|
||||
local language_config = contest_config[target_language]
|
||||
|
||||
if not language_config then
|
||||
error(("No language config found for '%s' in contest '%s'"):format(target_language, contest))
|
||||
end
|
||||
|
||||
if not language_config.extension then
|
||||
error(("No extension configured for language '%s' in contest '%s'"):format(target_language, contest))
|
||||
end
|
||||
|
||||
return full_problem_id .. "." .. language_config.extension
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -135,13 +135,10 @@ local function setup_problem(contest_id, problem_id, language)
|
|||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_set_option_value("winbar", "", { scope = "local" })
|
||||
vim.api.nvim_set_option_value("foldlevel", 0, { scope = "local" })
|
||||
vim.api.nvim_set_option_value("foldmethod", "marker", { scope = "local" })
|
||||
vim.api.nvim_set_option_value("foldmarker", "{{{,}}}", { scope = "local" })
|
||||
vim.api.nvim_set_option_value("foldtext", "", { scope = "local" })
|
||||
|
||||
vim.diagnostic.enable(false)
|
||||
if config.hooks and config.hooks.setup_code then
|
||||
local ctx = problem.create_context(state.platform, state.contest_id, state.problem_id, config)
|
||||
config.hooks.setup_code(ctx)
|
||||
end
|
||||
|
||||
local source_buf = vim.api.nvim_get_current_buf()
|
||||
local input_buf = vim.fn.bufnr(ctx.input_file, true)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
---@field height integer
|
||||
|
||||
local M = {}
|
||||
local languages = require("cp.languages")
|
||||
|
||||
function M.clearcol()
|
||||
vim.api.nvim_set_option_value("number", false, { scope = "local" })
|
||||
|
|
@ -78,7 +79,7 @@ function M.restore_layout(state, tile_fn)
|
|||
local source_file
|
||||
if source_files ~= "" then
|
||||
local files = vim.split(source_files, "\n")
|
||||
local valid_extensions = { "cc", "cpp", "cxx", "c", "py", "py3" }
|
||||
local valid_extensions = vim.tbl_keys(languages.filetype_to_language)
|
||||
for _, file in ipairs(files) do
|
||||
local ext = vim.fn.fnamemodify(file, ":e")
|
||||
if vim.tbl_contains(valid_extensions, ext) then
|
||||
|
|
@ -87,11 +88,9 @@ function M.restore_layout(state, tile_fn)
|
|||
end
|
||||
end
|
||||
source_file = source_file or files[1]
|
||||
else
|
||||
source_file = problem_id .. ".cc"
|
||||
end
|
||||
|
||||
if vim.fn.filereadable(source_file) == 0 then
|
||||
if not source_file or vim.fn.filereadable(source_file) == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue