feat(config): merge platform config model and add disabled-platform guard (#336)

## Problem

Supplying any `platforms` table silently dropped all unlisted platforms,
making it easy to accidentally disable platforms. Invoking a disabled
platform produced no user-facing error.

## Solution

Switch to a merge model: all six platforms are enabled by default and
user entries are deep-merged on top. Set a platform key to `false` to
disable it explicitly. Add a `check_platform_enabled` guard in
`handle_command` for contest fetch, login, logout, and race actions.
This commit is contained in:
Barrett Ruth 2026-03-06 16:14:16 -05:00 committed by GitHub
parent 82640709d6
commit e89c57558d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 74 additions and 29 deletions

View file

@ -107,6 +107,7 @@
---@field runtime { effective: table<string, table<string, CpLanguage>> } -- computed
---@class cp.PartialConfig: cp.Config
---@field platforms? table<string, CpPlatform|false>
local M = {}
@ -333,13 +334,18 @@ function M.setup(user_config)
vim.validate({ user_config = { user_config, { 'table', 'nil' }, true } })
local defaults = vim.deepcopy(M.defaults)
if user_config and user_config.platforms then
for plat in pairs(defaults.platforms) do
if not user_config.platforms[plat] then
for plat, v in pairs(user_config.platforms) do
if v == false then
defaults.platforms[plat] = nil
end
end
end
local cfg = vim.tbl_deep_extend('force', defaults, user_config or {})
for plat, v in pairs(cfg.platforms) do
if v == false then
cfg.platforms[plat] = nil
end
end
if not next(cfg.languages) then
error('[cp.nvim] At least one language must be configured')