cleanup
This commit is contained in:
parent
71a6aac826
commit
91f85d066d
1 changed files with 52 additions and 46 deletions
|
|
@ -242,60 +242,66 @@ 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
|
||||||
vim.api.nvim_buf_set_name(prov.bufnr, source_file)
|
local existing_bufnr = vim.fn.bufnr(source_file)
|
||||||
vim.bo[prov.bufnr].swapfile = true
|
if existing_bufnr ~= -1 then
|
||||||
-- selene: allow(mixed_table)
|
vim.api.nvim_buf_delete(prov.bufnr, { force = true })
|
||||||
vim.cmd.write({
|
state.set_provisional(nil)
|
||||||
vim.fn.fnameescape(source_file),
|
else
|
||||||
bang = true,
|
vim.api.nvim_buf_set_name(prov.bufnr, source_file)
|
||||||
mods = { silent = true, noautocmd = true, keepalt = true },
|
vim.bo[prov.bufnr].swapfile = true
|
||||||
})
|
-- selene: allow(mixed_table)
|
||||||
state.set_solution_win(vim.api.nvim_get_current_win())
|
vim.cmd.write({
|
||||||
if config.hooks and config.hooks.setup_code and not vim.b[prov.bufnr].cp_setup_done then
|
vim.fn.fnameescape(source_file),
|
||||||
local ok = pcall(config.hooks.setup_code, state)
|
bang = true,
|
||||||
if ok then
|
mods = { silent = true, noautocmd = true, keepalt = true },
|
||||||
|
})
|
||||||
|
state.set_solution_win(vim.api.nvim_get_current_win())
|
||||||
|
if config.hooks and config.hooks.setup_code and not vim.b[prov.bufnr].cp_setup_done then
|
||||||
|
local ok = pcall(config.hooks.setup_code, state)
|
||||||
|
if ok then
|
||||||
|
vim.b[prov.bufnr].cp_setup_done = true
|
||||||
|
end
|
||||||
|
elseif not vim.b[prov.bufnr].cp_setup_done then
|
||||||
|
helpers.clearcol(prov.bufnr)
|
||||||
vim.b[prov.bufnr].cp_setup_done = true
|
vim.b[prov.bufnr].cp_setup_done = true
|
||||||
end
|
end
|
||||||
elseif not vim.b[prov.bufnr].cp_setup_done then
|
cache.set_file_state(
|
||||||
helpers.clearcol(prov.bufnr)
|
vim.fn.fnamemodify(source_file, ':p'),
|
||||||
vim.b[prov.bufnr].cp_setup_done = true
|
platform,
|
||||||
|
state.get_contest_id() or '',
|
||||||
|
state.get_problem_id() or '',
|
||||||
|
lang
|
||||||
|
)
|
||||||
|
require('cp.ui.views').ensure_io_view()
|
||||||
|
state.set_provisional(nil)
|
||||||
|
return
|
||||||
end
|
end
|
||||||
cache.set_file_state(
|
else
|
||||||
vim.fn.fnamemodify(source_file, ':p'),
|
state.set_provisional(nil)
|
||||||
platform,
|
|
||||||
state.get_contest_id() or '',
|
|
||||||
state.get_problem_id() or '',
|
|
||||||
lang
|
|
||||||
)
|
|
||||||
require('cp.ui.views').ensure_io_view()
|
|
||||||
end
|
end
|
||||||
state.set_provisional(nil)
|
|
||||||
return
|
|
||||||
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
|
||||||
vim.b[bufnr].cp_setup_done = true
|
|
||||||
end
|
|
||||||
elseif not vim.b[bufnr].cp_setup_done then
|
|
||||||
helpers.clearcol(bufnr)
|
|
||||||
vim.b[bufnr].cp_setup_done = true
|
vim.b[bufnr].cp_setup_done = true
|
||||||
end
|
end
|
||||||
cache.set_file_state(
|
elseif not vim.b[bufnr].cp_setup_done then
|
||||||
vim.fn.expand('%:p'),
|
helpers.clearcol(bufnr)
|
||||||
platform,
|
vim.b[bufnr].cp_setup_done = true
|
||||||
state.get_contest_id() or '',
|
end
|
||||||
state.get_problem_id() or '',
|
cache.set_file_state(
|
||||||
lang
|
vim.fn.expand('%:p'),
|
||||||
)
|
platform,
|
||||||
require('cp.ui.views').ensure_io_view()
|
state.get_contest_id() or '',
|
||||||
end)
|
state.get_problem_id() or '',
|
||||||
|
lang
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param direction integer
|
---@param direction integer
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue