mirror of
https://github.com/harivansh-afk/nvim.git
synced 2026-04-16 19:04:40 +00:00
cp
This commit is contained in:
parent
ca5d1145dd
commit
dcc452e395
2 changed files with 66 additions and 5 deletions
|
|
@ -1,22 +1,22 @@
|
||||||
{
|
{
|
||||||
"cp.nvim": { "branch": "main", "commit": "ff5ba39a592d079780819bb8226dcb35741349a4" },
|
"cp.nvim": { "branch": "main", "commit": "3a5917711b2f23e39aa5f11fcea3bdef0094b240" },
|
||||||
"diffs.nvim": { "branch": "main", "commit": "dfebc68a1fc3e93dae5b6d49133243ec1886cb19" },
|
"diffs.nvim": { "branch": "main", "commit": "dfebc68a1fc3e93dae5b6d49133243ec1886cb19" },
|
||||||
"flash.nvim": { "branch": "main", "commit": "fcea7ff883235d9024dc41e638f164a450c14ca2" },
|
"flash.nvim": { "branch": "main", "commit": "fcea7ff883235d9024dc41e638f164a450c14ca2" },
|
||||||
"fzf-lua": { "branch": "main", "commit": "9004cbb4c065a32b690e909c49903967b45301eb" },
|
"fzf-lua": { "branch": "main", "commit": "9004cbb4c065a32b690e909c49903967b45301eb" },
|
||||||
"gitsigns.nvim": { "branch": "main", "commit": "9f3c6dd7868bcc116e9c1c1929ce063b978fa519" },
|
"gitsigns.nvim": { "branch": "main", "commit": "9f3c6dd7868bcc116e9c1c1929ce063b978fa519" },
|
||||||
"gruvbox.nvim": { "branch": "main", "commit": "561126520034a1dac2f78ab063db025d12555998" },
|
"gruvbox.nvim": { "branch": "main", "commit": "561126520034a1dac2f78ab063db025d12555998" },
|
||||||
"lazy.nvim": { "branch": "main", "commit": "85c7ff3711b730b4030d03144f6db6375044ae82" },
|
"lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" },
|
||||||
"lualine.nvim": { "branch": "master", "commit": "47f91c416daef12db467145e16bed5bbfe00add8" },
|
"lualine.nvim": { "branch": "master", "commit": "47f91c416daef12db467145e16bed5bbfe00add8" },
|
||||||
"nonicons.nvim": { "branch": "main", "commit": "5426ec037f2a295ae687fa9d4def290fb044e3e8" },
|
"nonicons.nvim": { "branch": "main", "commit": "5426ec037f2a295ae687fa9d4def290fb044e3e8" },
|
||||||
"nvim-autopairs": { "branch": "master", "commit": "59bce2eef357189c3305e25bc6dd2d138c1683f5" },
|
"nvim-autopairs": { "branch": "master", "commit": "59bce2eef357189c3305e25bc6dd2d138c1683f5" },
|
||||||
"nvim-lspconfig": { "branch": "master", "commit": "5a855bcfec7973767a1a472335684bbd71d2fa2b" },
|
"nvim-lspconfig": { "branch": "master", "commit": "5a855bcfec7973767a1a472335684bbd71d2fa2b" },
|
||||||
"nvim-surround": { "branch": "main", "commit": "1098d7b3c34adcfa7feb3289ee434529abd4afd1" },
|
"nvim-surround": { "branch": "main", "commit": "2800277e75eda268df2bfab6ebc53e2635455318" },
|
||||||
"nvim-treesitter": { "branch": "main", "commit": "dc42c209f3820bdfaae0956f15de29689aa6b451" },
|
"nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" },
|
||||||
"nvim-treesitter-textobjects": { "branch": "main", "commit": "a0e182ae21fda68c59d1f36c9ed45600aef50311" },
|
"nvim-treesitter-textobjects": { "branch": "main", "commit": "a0e182ae21fda68c59d1f36c9ed45600aef50311" },
|
||||||
"nvim-ufo": { "branch": "main", "commit": "ab3eb124062422d276fae49e0dd63b3ad1062cfc" },
|
"nvim-ufo": { "branch": "main", "commit": "ab3eb124062422d276fae49e0dd63b3ad1062cfc" },
|
||||||
"nvim-web-devicons": { "branch": "master", "commit": "746ffbb17975ebd6c40142362eee1b0249969c5c" },
|
"nvim-web-devicons": { "branch": "master", "commit": "746ffbb17975ebd6c40142362eee1b0249969c5c" },
|
||||||
"oil-git.nvim": { "branch": "main", "commit": "c99db7b1dd8dd500c3ec530dc07000dfbeb6e080" },
|
"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" },
|
"promise-async": { "branch": "main", "commit": "119e8961014c9bfaf1487bf3c2a393d254f337e2" },
|
||||||
"supermaven-nvim": { "branch": "main", "commit": "07d20fce48a5629686aefb0a7cd4b25e33947d50" },
|
"supermaven-nvim": { "branch": "main", "commit": "07d20fce48a5629686aefb0a7cd4b25e33947d50" },
|
||||||
"vim-fugitive": { "branch": "master", "commit": "61b51c09b7c9ce04e821f6cf76ea4f6f903e3cf4" }
|
"vim-fugitive": { "branch": "master", "commit": "61b51c09b7c9ce04e821f6cf76ea4f6f903e3cf4" }
|
||||||
|
|
|
||||||
|
|
@ -70,12 +70,72 @@ return {
|
||||||
default_language = 'python',
|
default_language = 'python',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
open_url = true,
|
||||||
ui = {
|
ui = {
|
||||||
picker = 'fzf-lua',
|
picker = 'fzf-lua',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
config = function()
|
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', '<leader>cr', '<cmd>CP run<cr>', { desc = 'CP run' })
|
map('n', '<leader>cr', '<cmd>CP run<cr>', { desc = 'CP run' })
|
||||||
map('n', '<leader>cp', '<cmd>CP panel<cr>', { desc = 'CP panel' })
|
map('n', '<leader>cp', '<cmd>CP panel<cr>', { desc = 'CP panel' })
|
||||||
map('n', '<leader>ce', '<cmd>CP edit<cr>', { desc = 'CP edit tests' })
|
map('n', '<leader>ce', '<cmd>CP edit<cr>', { desc = 'CP edit tests' })
|
||||||
|
|
@ -83,6 +143,7 @@ return {
|
||||||
map('n', '<leader>cN', '<cmd>CP prev<cr>', { desc = 'CP previous problem' })
|
map('n', '<leader>cN', '<cmd>CP prev<cr>', { desc = 'CP previous problem' })
|
||||||
map('n', '<leader>cc', '<cmd>CP pick<cr>', { desc = 'CP contest picker' })
|
map('n', '<leader>cc', '<cmd>CP pick<cr>', { desc = 'CP contest picker' })
|
||||||
map('n', '<leader>ci', '<cmd>CP interact<cr>', { desc = 'CP interact' })
|
map('n', '<leader>ci', '<cmd>CP interact<cr>', { desc = 'CP interact' })
|
||||||
|
map('n', '<leader>co', open_current_cp_problem_url, { desc = 'CP open problem url' })
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue