From 5417da9b52b6a045b15583e310fb7f9e26dd6ed1 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Mon, 15 Sep 2025 14:32:44 -0400 Subject: [PATCH] feat: make autocomplete more sophisticated --- lua/cp/init.lua | 4 ++-- plugin/cp.lua | 9 ++++++--- scrapers/codeforces.py | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lua/cp/init.lua b/lua/cp/init.lua index 92b78a7..6ea45da 100644 --- a/lua/cp/init.lua +++ b/lua/cp/init.lua @@ -41,8 +41,8 @@ local function set_platform(platform) end state.platform = platform - vim.fs.mkdir("build", { parents = true }) - vim.fs.mkdir("io", { parents = true }) + vim.fn.mkdir("build", "p") + vim.fn.mkdir("io", "p") return true end diff --git a/plugin/cp.lua b/plugin/cp.lua index f96db7f..9e19695 100644 --- a/plugin/cp.lua +++ b/plugin/cp.lua @@ -26,8 +26,10 @@ end, { end, lang_completions) end - if ArgLead == "--lang" then - return { "--lang" } + if ArgLead:match("^%-") and not ArgLead:match("^--lang") then + return vim.tbl_filter(function(completion) + return completion:find(ArgLead, 1, true) == 1 + end, { "--lang" }) end local args = vim.split(vim.trim(CmdLine), "%s+") @@ -43,7 +45,6 @@ end, { if num_args == 2 then local candidates = { "--lang" } - vim.list_extend(candidates, platforms) vim.list_extend(candidates, actions) local cp = require("cp") local context = cp.get_current_context() @@ -56,6 +57,8 @@ end, { table.insert(candidates, problem.id) end end + else + vim.list_extend(candidates, platforms) end return vim.tbl_filter(function(cmd) return cmd:find(ArgLead, 1, true) == 1 diff --git a/scrapers/codeforces.py b/scrapers/codeforces.py index 4610ae9..8e89b0a 100644 --- a/scrapers/codeforces.py +++ b/scrapers/codeforces.py @@ -30,7 +30,7 @@ def scrape(url: str) -> list[tuple[str, str]]: lines = [div.get_text().strip() for div in divs] text = "\n".join(lines) else: - text = inp_pre.get_text().replace("\r", "") + text = inp_pre.get_text().replace("\r", "").strip() all_inputs.append(text) for out_section in output_sections: @@ -41,7 +41,7 @@ def scrape(url: str) -> list[tuple[str, str]]: lines = [div.get_text().strip() for div in divs] text = "\n".join(lines) else: - text = out_pre.get_text().replace("\r", "") + text = out_pre.get_text().replace("\r", "").strip() all_outputs.append(text) if all_inputs and all_outputs: