From dcc452e3950ffdc8a711545aa608f79e9c9e33c9 Mon Sep 17 00:00:00 2001 From: Harivansh Rathi Date: Sun, 22 Feb 2026 22:11:26 -0500 Subject: [PATCH] cp --- lazy-lock.json | 10 +++---- lua/plugins/editor.lua | 61 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/lazy-lock.json b/lazy-lock.json index f0f44da..0206dc5 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,22 +1,22 @@ { - "cp.nvim": { "branch": "main", "commit": "ff5ba39a592d079780819bb8226dcb35741349a4" }, + "cp.nvim": { "branch": "main", "commit": "3a5917711b2f23e39aa5f11fcea3bdef0094b240" }, "diffs.nvim": { "branch": "main", "commit": "dfebc68a1fc3e93dae5b6d49133243ec1886cb19" }, "flash.nvim": { "branch": "main", "commit": "fcea7ff883235d9024dc41e638f164a450c14ca2" }, "fzf-lua": { "branch": "main", "commit": "9004cbb4c065a32b690e909c49903967b45301eb" }, "gitsigns.nvim": { "branch": "main", "commit": "9f3c6dd7868bcc116e9c1c1929ce063b978fa519" }, "gruvbox.nvim": { "branch": "main", "commit": "561126520034a1dac2f78ab063db025d12555998" }, - "lazy.nvim": { "branch": "main", "commit": "85c7ff3711b730b4030d03144f6db6375044ae82" }, + "lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" }, "lualine.nvim": { "branch": "master", "commit": "47f91c416daef12db467145e16bed5bbfe00add8" }, "nonicons.nvim": { "branch": "main", "commit": "5426ec037f2a295ae687fa9d4def290fb044e3e8" }, "nvim-autopairs": { "branch": "master", "commit": "59bce2eef357189c3305e25bc6dd2d138c1683f5" }, "nvim-lspconfig": { "branch": "master", "commit": "5a855bcfec7973767a1a472335684bbd71d2fa2b" }, - "nvim-surround": { "branch": "main", "commit": "1098d7b3c34adcfa7feb3289ee434529abd4afd1" }, - "nvim-treesitter": { "branch": "main", "commit": "dc42c209f3820bdfaae0956f15de29689aa6b451" }, + "nvim-surround": { "branch": "main", "commit": "2800277e75eda268df2bfab6ebc53e2635455318" }, + "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, "nvim-treesitter-textobjects": { "branch": "main", "commit": "a0e182ae21fda68c59d1f36c9ed45600aef50311" }, "nvim-ufo": { "branch": "main", "commit": "ab3eb124062422d276fae49e0dd63b3ad1062cfc" }, "nvim-web-devicons": { "branch": "master", "commit": "746ffbb17975ebd6c40142362eee1b0249969c5c" }, "oil-git.nvim": { "branch": "main", "commit": "c99db7b1dd8dd500c3ec530dc07000dfbeb6e080" }, - "oil.nvim": { "branch": "master", "commit": "f55b25e493a7df76371cfadd0ded5004cb9cd48a" }, + "oil.nvim": { "branch": "master", "commit": "48fc83a9978c5f25833634700c08be583ee78eb7" }, "promise-async": { "branch": "main", "commit": "119e8961014c9bfaf1487bf3c2a393d254f337e2" }, "supermaven-nvim": { "branch": "main", "commit": "07d20fce48a5629686aefb0a7cd4b25e33947d50" }, "vim-fugitive": { "branch": "master", "commit": "61b51c09b7c9ce04e821f6cf76ea4f6f903e3cf4" } diff --git a/lua/plugins/editor.lua b/lua/plugins/editor.lua index 6430d7b..15d77d0 100644 --- a/lua/plugins/editor.lua +++ b/lua/plugins/editor.lua @@ -70,12 +70,72 @@ return { default_language = 'python', }, }, + open_url = true, ui = { picker = 'fzf-lua', }, } end, config = function() + local function open_url(url) + local ok_ui_open, opened = pcall(vim.ui.open, url) + if ok_ui_open and opened ~= false then + return + end + + local opener = nil + if vim.fn.has('macunix') == 1 then + opener = 'open' + elseif vim.fn.has('unix') == 1 then + opener = 'xdg-open' + end + + if opener then + vim.fn.jobstart({ opener, url }, { detach = true }) + end + end + + local function open_current_cp_problem_url() + local ok_state, state = pcall(require, 'cp.state') + local ok_cache, cache = pcall(require, 'cp.cache') + if not (ok_state and ok_cache) then + return + end + + local platform = state.get_platform() + local contest_id = state.get_contest_id() + local problem_id = state.get_problem_id() + if not (platform and contest_id and problem_id) then + return + end + + cache.load() + local contest = cache.get_contest_data(platform, contest_id) + if contest and contest.url then + open_url(contest.url:format(problem_id)) + end + end + + -- cp.nvim only opens URLs when first entering a contest; extend this locally for next/prev. + local ok_setup, setup = pcall(require, 'cp.setup') + local ok_config, cp_config = pcall(require, 'cp.config') + if ok_setup and ok_config and not setup._url_open_patch_applied then + local original_navigate_problem = setup.navigate_problem + setup.navigate_problem = function(direction, language) + local ok_state, state = pcall(require, 'cp.state') + local old_problem_id = ok_state and state.get_problem_id() or nil + original_navigate_problem(direction, language) + + local cfg = cp_config.get_config() + local new_problem_id = ok_state and state.get_problem_id() or nil + local moved = old_problem_id ~= nil and new_problem_id ~= nil and old_problem_id ~= new_problem_id + if cfg and cfg.open_url and moved then + vim.schedule(open_current_cp_problem_url) + end + end + setup._url_open_patch_applied = true + end + map('n', 'cr', 'CP run', { desc = 'CP run' }) map('n', 'cp', 'CP panel', { desc = 'CP panel' }) map('n', 'ce', 'CP edit', { desc = 'CP edit tests' }) @@ -83,6 +143,7 @@ return { map('n', 'cN', 'CP prev', { desc = 'CP previous problem' }) map('n', 'cc', 'CP pick', { desc = 'CP contest picker' }) map('n', 'ci', 'CP interact', { desc = 'CP interact' }) + map('n', 'co', open_current_cp_problem_url, { desc = 'CP open problem url' }) end, }, {