feat: start lang refactor
This commit is contained in:
parent
ce12ab0e1a
commit
bd30fb626c
7 changed files with 229 additions and 45 deletions
|
|
@ -351,6 +351,50 @@ function M.get_config()
|
|||
return current_config or M.defaults
|
||||
end
|
||||
|
||||
---Validate and get effective language config for a platform
|
||||
---@param platform_id string
|
||||
---@param language_id string
|
||||
---@return { valid: boolean, effective?: CpLanguage, extension?: string, error?: string }
|
||||
function M.get_language_for_platform(platform_id, language_id)
|
||||
local cfg = M.get_config()
|
||||
|
||||
if not cfg.platforms[platform_id] then
|
||||
return { valid = false, error = string.format("Unknown platform '%s'", platform_id) }
|
||||
end
|
||||
|
||||
if not cfg.languages[language_id] then
|
||||
return { valid = false, error = string.format("Unknown language '%s'", language_id) }
|
||||
end
|
||||
|
||||
local platform = cfg.platforms[platform_id]
|
||||
if not vim.tbl_contains(platform.enabled_languages, language_id) then
|
||||
local available = table.concat(platform.enabled_languages, ', ')
|
||||
return {
|
||||
valid = false,
|
||||
error = string.format(
|
||||
"Language '%s' not enabled for %s. Available: %s",
|
||||
language_id,
|
||||
platform_id,
|
||||
available
|
||||
),
|
||||
}
|
||||
end
|
||||
|
||||
local effective = cfg.runtime.effective[platform_id][language_id]
|
||||
if not effective then
|
||||
return {
|
||||
valid = false,
|
||||
error = string.format('No effective config for %s/%s', platform_id, language_id),
|
||||
}
|
||||
end
|
||||
|
||||
return {
|
||||
valid = true,
|
||||
effective = effective,
|
||||
extension = effective.extension,
|
||||
}
|
||||
end
|
||||
|
||||
---@param contest_id string
|
||||
---@param problem_id? string
|
||||
---@return string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue