feat(config): add language version selection with setup-time validation

Problem: users cannot choose which C++ standard (e.g. C++17 vs C++20
vs C++23) to submit with — the plugin hardcodes a single platform ID
per language with no discoverability or override mechanism.

Solution: add `LANGUAGE_VERSIONS` and `DEFAULT_VERSIONS` tables in
`constants.lua` as the single source of truth. `config.lua` gains
`version` and `submit_id` fields on `CpLanguage`/`CpPlatformOverrides`,
validated at setup time. `submit.lua` resolves the effective config to
a platform ID (priority: `submit_id` > `version` > default). Helpdocs
document the new `*cp-submit-language*` section with per-platform
available versions and the `submit_id` escape hatch. Tests cover
`LANGUAGE_IDS` completeness and `get_language_id` lookups.
This commit is contained in:
Barrett Ruth 2026-03-06 18:04:04 -05:00
parent 4e709c8470
commit b90ac67826
Signed by: barrett
GPG key ID: A6C96C9349D2FC81
5 changed files with 153 additions and 11 deletions

View file

@ -1,6 +1,8 @@
local M = {}
local cache = require('cp.cache')
local config = require('cp.config')
local constants = require('cp.constants')
local logger = require('cp.log')
local state = require('cp.state')
@ -56,6 +58,24 @@ function M.submit(opts)
end
source_file = vim.fn.fnamemodify(source_file, ':p')
local submit_language = language
local cfg = config.get_config()
local plat_effective = cfg.runtime and cfg.runtime.effective and cfg.runtime.effective[platform]
local eff = plat_effective and plat_effective[language]
if eff then
if eff.submit_id then
submit_language = eff.submit_id
else
local ver = eff.version or constants.DEFAULT_VERSIONS[language]
if ver then
local versions = (constants.LANGUAGE_VERSIONS[platform] or {})[language]
if versions and versions[ver] then
submit_language = versions[ver]
end
end
end
end
prompt_credentials(platform, function(creds)
vim.cmd.update()
vim.notify('[cp.nvim] Submitting...', vim.log.levels.INFO)
@ -64,7 +84,7 @@ function M.submit(opts)
platform,
contest_id,
problem_id,
language,
submit_language,
source_file,
creds,
function(ev)