commit
32cecf80d0
4 changed files with 81 additions and 10 deletions
|
|
@ -50,7 +50,7 @@ local function execute_binary(binary_path, input_data, timeout_ms)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local function format_output(exec_result, expected_file)
|
local function format_output(exec_result, expected_file, is_debug)
|
||||||
local lines = { exec_result.stdout }
|
local lines = { exec_result.stdout }
|
||||||
|
|
||||||
if exec_result.timed_out then
|
if exec_result.timed_out then
|
||||||
|
|
@ -63,7 +63,7 @@ local function format_output(exec_result, expected_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(lines, ("\n[time]: %.2f ms"):format(exec_result.time_ms))
|
table.insert(lines, ("\n[time]: %.2f ms"):format(exec_result.time_ms))
|
||||||
table.insert(lines, "\n[debug]: false")
|
table.insert(lines, ("\n[debug]: %s"):format(is_debug and "true" or "false"))
|
||||||
|
|
||||||
if vim.fn.filereadable(expected_file) == 1 and exec_result.code == 0 then
|
if vim.fn.filereadable(expected_file) == 1 and exec_result.code == 0 then
|
||||||
local expected_content = vim.fn.readfile(expected_file)
|
local expected_content = vim.fn.readfile(expected_file)
|
||||||
|
|
@ -103,7 +103,7 @@ function M.run_problem(problem_id, contest_config, is_debug)
|
||||||
end
|
end
|
||||||
|
|
||||||
local exec_result = execute_binary(paths.binary, input_data, contest_config.timeout_ms)
|
local exec_result = execute_binary(paths.binary, input_data, contest_config.timeout_ms)
|
||||||
local formatted_output = format_output(exec_result, paths.expected)
|
local formatted_output = format_output(exec_result, paths.expected, is_debug)
|
||||||
|
|
||||||
vim.fn.writefile(vim.split(formatted_output, "\n"), paths.output)
|
vim.fn.writefile(vim.split(formatted_output, "\n"), paths.output)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ local function log(msg, level)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not vim.fn.has("nvim-0.10.0") then
|
if not vim.fn.has("nvim-0.10.0") then
|
||||||
log("cp.nvim requires Neovim 0.10.0+", vim.log.levels.ERROR)
|
log("cp.nvim requires nvim-0.10.0+", vim.log.levels.ERROR)
|
||||||
return M
|
return M
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -105,7 +105,21 @@ local function setup_problem(problem_id, problem_letter)
|
||||||
vim.cmd.e(filename)
|
vim.cmd.e(filename)
|
||||||
|
|
||||||
if vim.api.nvim_buf_get_lines(0, 0, -1, true)[1] == "" then
|
if vim.api.nvim_buf_get_lines(0, 0, -1, true)[1] == "" then
|
||||||
vim.api.nvim_input(("i%s<c-space><esc>"):format(vim.g.cp_contest))
|
local has_luasnip, luasnip = pcall(require, "luasnip")
|
||||||
|
if has_luasnip then
|
||||||
|
vim.api.nvim_buf_set_lines(0, 0, -1, false, { vim.g.cp_contest })
|
||||||
|
vim.api.nvim_win_set_cursor(0, { 1, #vim.g.cp_contest })
|
||||||
|
vim.cmd.startinsert({ bang = true })
|
||||||
|
|
||||||
|
vim.schedule(function()
|
||||||
|
if luasnip.expandable() then
|
||||||
|
luasnip.expand()
|
||||||
|
end
|
||||||
|
vim.cmd.stopinsert()
|
||||||
|
end)
|
||||||
|
else
|
||||||
|
vim.api.nvim_input(("i%s<c-space><esc>"):format(vim.g.cp_contest))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_set_option_value("winbar", "", { scope = "local" })
|
vim.api.nvim_set_option_value("winbar", "", { scope = "local" })
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,73 @@ local M = {}
|
||||||
function M.setup(config)
|
function M.setup(config)
|
||||||
local has_luasnip, luasnip = pcall(require, "luasnip")
|
local has_luasnip, luasnip = pcall(require, "luasnip")
|
||||||
if not has_luasnip then
|
if not has_luasnip then
|
||||||
|
vim.notify("[cp.nvim]: LuaSnip not available - snippets disabled", vim.log.levels.INFO)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local snippets = {}
|
local s = luasnip.snippet
|
||||||
|
local i = luasnip.insert_node
|
||||||
|
local fmt = require("luasnip.extras.fmt").fmt
|
||||||
|
|
||||||
|
local default_snippets = {
|
||||||
|
s(
|
||||||
|
"codeforces",
|
||||||
|
fmt(
|
||||||
|
[[void solve() {{
|
||||||
|
{}
|
||||||
|
}}
|
||||||
|
|
||||||
|
int main() {{
|
||||||
|
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
|
||||||
|
int tc = 1;
|
||||||
|
std::cin >> tc;
|
||||||
|
|
||||||
|
for (int t = 0; t < tc; ++t) {{
|
||||||
|
solve();
|
||||||
|
}}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}}]],
|
||||||
|
{ i(1) }
|
||||||
|
)
|
||||||
|
),
|
||||||
|
|
||||||
|
s(
|
||||||
|
"atcoder",
|
||||||
|
fmt(
|
||||||
|
[[void solve() {{
|
||||||
|
{}
|
||||||
|
}}
|
||||||
|
|
||||||
|
int main() {{
|
||||||
|
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
|
||||||
|
#ifdef LOCAL
|
||||||
|
int tc;
|
||||||
|
std::cin >> tc;
|
||||||
|
|
||||||
|
for (int t = 0; t < tc; ++t) {{
|
||||||
|
solve();
|
||||||
|
}}
|
||||||
|
#else
|
||||||
|
solve();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}}]],
|
||||||
|
{ i(1) }
|
||||||
|
)
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
local user_snippets = {}
|
||||||
for _, snippet in pairs(config.snippets or {}) do
|
for _, snippet in pairs(config.snippets or {}) do
|
||||||
table.insert(snippets, snippet)
|
table.insert(user_snippets, snippet)
|
||||||
end
|
end
|
||||||
|
|
||||||
if #snippets > 0 then
|
local all_snippets = vim.list_extend(default_snippets, user_snippets)
|
||||||
luasnip.add_snippets("cpp", snippets)
|
luasnip.add_snippets("cpp", all_snippets)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,8 @@ Using [lazy.nvim](https://github.com/folke/lazy.nvim):
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
|
- update templates to minimum vrsion that's comatible with scrapers (i.e.
|
||||||
|
aggregated testcases, ifdef local, etc.)
|
||||||
- vimdocs
|
- vimdocs
|
||||||
- example video
|
- example video
|
||||||
- more flexible setup (more of a question of philosophy)
|
- more flexible setup (more of a question of philosophy)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue