add vim.validate on user spec
This commit is contained in:
parent
d336fc33f7
commit
3f49721657
13 changed files with 33 additions and 268 deletions
|
|
@ -14,9 +14,15 @@ M.defaults = {
|
|||
codeforces = {
|
||||
cpp_version = 23,
|
||||
},
|
||||
cses = {},
|
||||
cses = {
|
||||
cpp_version = 20,
|
||||
},
|
||||
},
|
||||
snippets = {},
|
||||
hooks = {
|
||||
before_run = nil,
|
||||
before_debug = nil,
|
||||
},
|
||||
}
|
||||
|
||||
local function extend_contest_config(base_config, contest_config)
|
||||
|
|
@ -30,6 +36,25 @@ local function extend_contest_config(base_config, contest_config)
|
|||
end
|
||||
|
||||
function M.setup(user_config)
|
||||
vim.validate({
|
||||
user_config = { user_config, { "table", "nil" }, true },
|
||||
})
|
||||
|
||||
if user_config then
|
||||
vim.validate({
|
||||
contests = { user_config.contests, { "table", "nil" }, true },
|
||||
snippets = { user_config.snippets, { "table", "nil" }, true },
|
||||
hooks = { user_config.hooks, { "table", "nil" }, true },
|
||||
})
|
||||
|
||||
if user_config.hooks then
|
||||
vim.validate({
|
||||
before_run = { user_config.hooks.before_run, { "function", "nil" }, true },
|
||||
before_debug = { user_config.hooks.before_debug, { "function", "nil" }, true },
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
local config = vim.tbl_deep_extend("force", M.defaults, user_config or {})
|
||||
|
||||
local default_contest = config.contests.default
|
||||
|
|
|
|||
|
|
@ -161,9 +161,8 @@ local function run_problem()
|
|||
return
|
||||
end
|
||||
|
||||
local has_lsp, lsp = pcall(require, "lsp")
|
||||
if has_lsp and lsp.lsp_format then
|
||||
lsp.lsp_format({ async = true })
|
||||
if config.hooks and config.hooks.before_run then
|
||||
config.hooks.before_run(problem_id)
|
||||
end
|
||||
|
||||
if not vim.g.cp_contest then
|
||||
|
|
@ -185,9 +184,8 @@ local function debug_problem()
|
|||
return
|
||||
end
|
||||
|
||||
local has_lsp, lsp = pcall(require, "lsp")
|
||||
if has_lsp and lsp.lsp_format then
|
||||
lsp.lsp_format({ async = true })
|
||||
if config.hooks and config.hooks.before_debug then
|
||||
config.hooks.before_debug(problem_id)
|
||||
end
|
||||
|
||||
if not vim.g.cp_contest then
|
||||
|
|
@ -246,9 +244,6 @@ function M.setup(user_config)
|
|||
|
||||
config = config_module.setup(user_config)
|
||||
|
||||
local plugin_path = get_plugin_path()
|
||||
config.snippets.path = plugin_path .. "/templates/snippets"
|
||||
|
||||
snippets.setup(config)
|
||||
|
||||
if initialized then
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ function M.scrape_problem(contest, problem_id, problem_letter)
|
|||
ensure_io_directory()
|
||||
|
||||
local plugin_path = get_plugin_path()
|
||||
local scraper_path = plugin_path .. "/templates/scrapers/" .. contest .. ".py"
|
||||
local scraper_path = plugin_path .. "/scrapers/" .. contest .. ".py"
|
||||
|
||||
local args
|
||||
if contest == "cses" then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue