From ba5ae8df69c682e9ae6e5c358b483bd860d446a2 Mon Sep 17 00:00:00 2001 From: Barrett Ruth <62671086+barrettruth@users.noreply.github.com> Date: Fri, 6 Mar 2026 13:25:17 -0500 Subject: [PATCH] fix(kattis): fix nil display_name in contest picker (#332) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Problem `ContestSummary.display_name` defaults to `None`, which serializes to JSON `null` → Lua `vim.NIL`. The contest picker displayed "vim.NIL" for every entry. Additionally, `start_time` was always stored even when null, because `vim.NIL` is truthy in Lua. ## Solution Pass `display_name=name` explicitly in `_parse_contests_page` so JSON never emits `null`. In `cache.lua` `set_contest_summaries`, coerce `display_name` via a `~= vim.NIL` guard and apply the same guard before storing `start_time`. --- lua/cp/cache.lua | 6 ++++-- scrapers/kattis.py | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lua/cp/cache.lua b/lua/cp/cache.lua index 3370532..987caee 100644 --- a/lua/cp/cache.lua +++ b/lua/cp/cache.lua @@ -396,9 +396,11 @@ function M.set_contest_summaries(platform, contests) cache_data[platform] = cache_data[platform] or {} for _, contest in ipairs(contests) do cache_data[platform][contest.id] = cache_data[platform][contest.id] or {} - cache_data[platform][contest.id].display_name = contest.display_name + cache_data[platform][contest.id].display_name = ( + contest.display_name ~= vim.NIL and contest.display_name + ) or contest.name cache_data[platform][contest.id].name = contest.name - if contest.start_time then + if contest.start_time and contest.start_time ~= vim.NIL then cache_data[platform][contest.id].start_time = contest.start_time end end diff --git a/scrapers/kattis.py b/scrapers/kattis.py index 734705e..7741847 100644 --- a/scrapers/kattis.py +++ b/scrapers/kattis.py @@ -123,7 +123,9 @@ def _parse_contests_page(html: str) -> list[ContestSummary]: start_time = int(dt.timestamp()) except Exception: pass - results.append(ContestSummary(id=cid, name=name, start_time=start_time)) + results.append( + ContestSummary(id=cid, name=name, display_name=name, start_time=start_time) + ) return results