feat: language

This commit is contained in:
Barrett Ruth 2025-10-24 01:21:16 -04:00
parent bd30fb626c
commit 48d4c6f113
4 changed files with 18 additions and 3 deletions

View file

@ -164,7 +164,7 @@ function M.compile_problem(debug)
local state = require('cp.state') local state = require('cp.state')
local config = require('cp.config').get_config() local config = require('cp.config').get_config()
local platform = state.get_platform() local platform = state.get_platform()
local language = config.platforms[platform].default_language local language = state.get_language() or config.platforms[platform].default_language
local eff = config.runtime.effective[platform][language] local eff = config.runtime.effective[platform][language]
local compile_config = (debug and eff.commands.debug) or eff.commands.build local compile_config = (debug and eff.commands.debug) or eff.commands.build

View file

@ -109,7 +109,7 @@ local function run_single_test_case(test_case, debug)
local substitutions = { source = source_file, binary = binary_file } local substitutions = { source = source_file, binary = binary_file }
local platform_config = config.platforms[state.get_platform() or ''] local platform_config = config.platforms[state.get_platform() or '']
local language = platform_config.default_language local language = state.get_language() or platform_config.default_language
local eff = config.runtime.effective[state.get_platform() or ''][language] local eff = config.runtime.effective[state.get_platform() or ''][language]
local run_template = eff and eff.commands and eff.commands.run or {} local run_template = eff and eff.commands and eff.commands.run or {}
local cmd = build_command(run_template, substitutions) local cmd = build_command(run_template, substitutions)

View file

@ -202,6 +202,8 @@ function M.setup_problem(problem_id, language)
end end
end end
state.set_language(lang)
local source_file = state.get_source_file(lang) local source_file = state.get_source_file(lang)
if not source_file then if not source_file then
return return

View file

@ -20,6 +20,8 @@
---@field set_contest_id fun(contest_id: string) ---@field set_contest_id fun(contest_id: string)
---@field get_problem_id fun(): string? ---@field get_problem_id fun(): string?
---@field set_problem_id fun(problem_id: string) ---@field set_problem_id fun(problem_id: string)
---@field get_language fun(): string?
---@field set_language fun(language: string)
---@field get_active_panel fun(): string? ---@field get_active_panel fun(): string?
---@field set_active_panel fun(panel: string?) ---@field set_active_panel fun(panel: string?)
---@field get_base_name fun(): string? ---@field get_base_name fun(): string?
@ -42,6 +44,7 @@ local state = {
platform = nil, platform = nil,
contest_id = nil, contest_id = nil,
problem_id = nil, problem_id = nil,
language = nil,
test_cases = nil, test_cases = nil,
saved_session = nil, saved_session = nil,
active_panel = nil, active_panel = nil,
@ -80,6 +83,16 @@ function M.set_problem_id(problem_id)
state.problem_id = problem_id state.problem_id = problem_id
end end
---@return string?
function M.get_language()
return state.language
end
---@param language string
function M.set_language(language)
state.language = language
end
---@return string? ---@return string?
function M.get_base_name() function M.get_base_name()
local platform, contest_id, problem_id = M.get_platform(), M.get_contest_id(), M.get_problem_id() local platform, contest_id, problem_id = M.get_platform(), M.get_contest_id(), M.get_problem_id()
@ -112,7 +125,7 @@ function M.get_source_file(language)
return nil return nil
end end
local target_language = language or platform_cfg.default_language local target_language = language or state.language or platform_cfg.default_language
local eff = config.runtime.effective[plat] and config.runtime.effective[plat][target_language] local eff = config.runtime.effective[plat] and config.runtime.effective[plat][target_language]
or nil or nil
if not eff or not eff.extension then if not eff or not eff.extension then