fix(config): platforms, not contests
This commit is contained in:
parent
ef8ee26edf
commit
0a320945a0
4 changed files with 21 additions and 17 deletions
|
|
@ -28,7 +28,7 @@
|
||||||
---@field git DiffGitConfig
|
---@field git DiffGitConfig
|
||||||
|
|
||||||
---@class cp.Config
|
---@class cp.Config
|
||||||
---@field contests table<string, ContestConfig>
|
---@field platforms table<string, ContestConfig>
|
||||||
---@field snippets any[]
|
---@field snippets any[]
|
||||||
---@field hooks Hooks
|
---@field hooks Hooks
|
||||||
---@field debug boolean
|
---@field debug boolean
|
||||||
|
|
@ -39,7 +39,7 @@
|
||||||
---@field picker string|nil
|
---@field picker string|nil
|
||||||
|
|
||||||
---@class cp.PartialConfig
|
---@class cp.PartialConfig
|
||||||
---@field contests? table<string, ContestConfig>
|
---@field platforms? table<string, ContestConfig>
|
||||||
---@field snippets? any[]
|
---@field snippets? any[]
|
||||||
---@field hooks? Hooks
|
---@field hooks? Hooks
|
||||||
---@field debug? boolean
|
---@field debug? boolean
|
||||||
|
|
@ -71,7 +71,7 @@ local default_contest_config = {
|
||||||
|
|
||||||
---@type cp.Config
|
---@type cp.Config
|
||||||
M.defaults = {
|
M.defaults = {
|
||||||
contests = {
|
platforms = {
|
||||||
codeforces = default_contest_config,
|
codeforces = default_contest_config,
|
||||||
atcoder = default_contest_config,
|
atcoder = default_contest_config,
|
||||||
cses = default_contest_config,
|
cses = default_contest_config,
|
||||||
|
|
@ -107,7 +107,7 @@ function M.setup(user_config)
|
||||||
|
|
||||||
if user_config then
|
if user_config then
|
||||||
vim.validate({
|
vim.validate({
|
||||||
contests = { user_config.contests, { 'table', 'nil' }, true },
|
platforms = { user_config.platforms, { 'table', 'nil' }, true },
|
||||||
snippets = { user_config.snippets, { 'table', 'nil' }, true },
|
snippets = { user_config.snippets, { 'table', 'nil' }, true },
|
||||||
hooks = { user_config.hooks, { 'table', 'nil' }, true },
|
hooks = { user_config.hooks, { 'table', 'nil' }, true },
|
||||||
debug = { user_config.debug, { 'boolean', 'nil' }, true },
|
debug = { user_config.debug, { 'boolean', 'nil' }, true },
|
||||||
|
|
@ -118,11 +118,11 @@ function M.setup(user_config)
|
||||||
picker = { user_config.picker, { 'string', 'nil' }, true },
|
picker = { user_config.picker, { 'string', 'nil' }, true },
|
||||||
})
|
})
|
||||||
|
|
||||||
if user_config.contests then
|
if user_config.platforms then
|
||||||
for contest_name, contest_config in pairs(user_config.contests) do
|
for platform_name, platform_config in pairs(user_config.platforms) do
|
||||||
vim.validate({
|
vim.validate({
|
||||||
[contest_name] = {
|
[platform_name] = {
|
||||||
contest_config,
|
platform_config,
|
||||||
function(config)
|
function(config)
|
||||||
if type(config) ~= 'table' then
|
if type(config) ~= 'table' then
|
||||||
return false
|
return false
|
||||||
|
|
@ -205,8 +205,8 @@ function M.setup(user_config)
|
||||||
git = { config.diff.git, { 'table', 'nil' }, true },
|
git = { config.diff.git, { 'table', 'nil' }, true },
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, contest_config in pairs(config.contests) do
|
for _, platform_config in pairs(config.platforms) do
|
||||||
for lang_name, lang_config in pairs(contest_config) do
|
for lang_name, lang_config in pairs(platform_config) do
|
||||||
if type(lang_config) == 'table' and not lang_config.extension then
|
if type(lang_config) == 'table' and not lang_config.extension then
|
||||||
if lang_name == 'cpp' then
|
if lang_name == 'cpp' then
|
||||||
lang_config.extension = 'cpp'
|
lang_config.extension = 'cpp'
|
||||||
|
|
@ -216,9 +216,10 @@ function M.setup(user_config)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not contest_config.default_language then
|
vim.print(platform_config)
|
||||||
|
if not platform_config.default_language then
|
||||||
local available_langs = {}
|
local available_langs = {}
|
||||||
for lang_name, lang_config in pairs(contest_config) do
|
for lang_name, lang_config in pairs(platform_config) do
|
||||||
if type(lang_config) == 'table' and lang_name ~= 'default_language' then
|
if type(lang_config) == 'table' and lang_name ~= 'default_language' then
|
||||||
table.insert(available_langs, lang_name)
|
table.insert(available_langs, lang_name)
|
||||||
end
|
end
|
||||||
|
|
@ -228,8 +229,11 @@ function M.setup(user_config)
|
||||||
error('No language configurations found')
|
error('No language configurations found')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
vim.print('sorting langs')
|
||||||
|
--- arbitrarily break ties
|
||||||
table.sort(available_langs)
|
table.sort(available_langs)
|
||||||
contest_config.default_language = available_langs[1]
|
vim.print(available_langs)
|
||||||
|
platform_config.default_language = available_langs[1]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ function M.get_platforms()
|
||||||
local result = {}
|
local result = {}
|
||||||
|
|
||||||
for _, platform in ipairs(constants.PLATFORMS) do
|
for _, platform in ipairs(constants.PLATFORMS) do
|
||||||
if config.contests[platform] then
|
if config.platforms[platform] then
|
||||||
table.insert(result, {
|
table.insert(result, {
|
||||||
id = platform,
|
id = platform,
|
||||||
display_name = constants.PLATFORM_DISPLAY_NAMES[platform] or platform,
|
display_name = constants.PLATFORM_DISPLAY_NAMES[platform] or platform,
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ function M.get_source_file(language)
|
||||||
end
|
end
|
||||||
|
|
||||||
local config = require('cp.config').get_config()
|
local config = require('cp.config').get_config()
|
||||||
local contest_config = config.contests[M.get_platform()]
|
local contest_config = config.platforms[M.get_platform()]
|
||||||
if not contest_config then
|
if not contest_config then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ function M.toggle_interactive()
|
||||||
vim.cmd('silent only')
|
vim.cmd('silent only')
|
||||||
|
|
||||||
local config = config_module.get_config()
|
local config = config_module.get_config()
|
||||||
local contest_config = config.contests[state.get_platform() or '']
|
local contest_config = config.platforms[state.get_platform() or '']
|
||||||
local execute = require('cp.runner.execute')
|
local execute = require('cp.runner.execute')
|
||||||
local compile_result = execute.compile_problem(contest_config, false)
|
local compile_result = execute.compile_problem(contest_config, false)
|
||||||
if not compile_result.success then
|
if not compile_result.success then
|
||||||
|
|
@ -284,7 +284,7 @@ function M.toggle_run_panel(is_debug)
|
||||||
setup_keybindings_for_buffer(test_buffers.tab_buf)
|
setup_keybindings_for_buffer(test_buffers.tab_buf)
|
||||||
|
|
||||||
local execute = require('cp.runner.execute')
|
local execute = require('cp.runner.execute')
|
||||||
local contest_config = config.contests[state.get_platform() or '']
|
local contest_config = config.platforms[state.get_platform() or '']
|
||||||
local compile_result = execute.compile_problem(contest_config, is_debug)
|
local compile_result = execute.compile_problem(contest_config, is_debug)
|
||||||
if compile_result.success then
|
if compile_result.success then
|
||||||
run.run_all_test_cases(contest_config, config)
|
run.run_all_test_cases(contest_config, config)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue