Merge pull request #185 from barrett-ruth/cleanup

cleanup
This commit is contained in:
Barrett Ruth 2025-10-31 23:27:23 -04:00 committed by GitHub
commit 73c91e2b28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -242,6 +242,11 @@ function M.setup_problem(problem_id, language)
local prov = state.get_provisional() local prov = state.get_provisional()
if prov and prov.platform == platform and prov.contest_id == (state.get_contest_id() or '') then if prov and prov.platform == platform and prov.contest_id == (state.get_contest_id() or '') then
if vim.api.nvim_buf_is_valid(prov.bufnr) then if vim.api.nvim_buf_is_valid(prov.bufnr) then
local existing_bufnr = vim.fn.bufnr(source_file)
if existing_bufnr ~= -1 then
vim.api.nvim_buf_delete(prov.bufnr, { force = true })
state.set_provisional(nil)
else
vim.api.nvim_buf_set_name(prov.bufnr, source_file) vim.api.nvim_buf_set_name(prov.bufnr, source_file)
vim.bo[prov.bufnr].swapfile = true vim.bo[prov.bufnr].swapfile = true
-- selene: allow(mixed_table) -- selene: allow(mixed_table)
@ -268,16 +273,19 @@ function M.setup_problem(problem_id, language)
lang lang
) )
require('cp.ui.views').ensure_io_view() require('cp.ui.views').ensure_io_view()
end
state.set_provisional(nil) state.set_provisional(nil)
return return
end end
else
state.set_provisional(nil)
end
end
vim.schedule(function()
vim.cmd.only({ mods = { silent = true } }) vim.cmd.only({ mods = { silent = true } })
vim.cmd.e(source_file) vim.cmd.e(source_file)
local bufnr = vim.api.nvim_get_current_buf() local bufnr = vim.api.nvim_get_current_buf()
state.set_solution_win(vim.api.nvim_get_current_win()) state.set_solution_win(vim.api.nvim_get_current_win())
require('cp.ui.views').ensure_io_view()
if config.hooks and config.hooks.setup_code and not vim.b[bufnr].cp_setup_done then if config.hooks and config.hooks.setup_code and not vim.b[bufnr].cp_setup_done then
local ok = pcall(config.hooks.setup_code, state) local ok = pcall(config.hooks.setup_code, state)
if ok then if ok then
@ -294,8 +302,6 @@ function M.setup_problem(problem_id, language)
state.get_problem_id() or '', state.get_problem_id() or '',
lang lang
) )
require('cp.ui.views').ensure_io_view()
end)
end end
---@param direction integer ---@param direction integer