feat: include versioning
This commit is contained in:
parent
6a7ade554e
commit
f13a05c806
6 changed files with 60 additions and 29 deletions
|
|
@ -2,11 +2,11 @@ if exists("b:current_syntax")
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
syntax match cpOutputCode /^\[code\]: .*/
|
syntax match cpOutputCode /^\[code\]:/
|
||||||
syntax match cpOutputTime /^\[time\]: .*/
|
syntax match cpOutputTime /^\[time\]:/
|
||||||
syntax match cpOutputDebug /^\[debug\]: .*/
|
syntax match cpOutputDebug /^\[debug\]:/
|
||||||
syntax match cpOutputMatchesTrue /^\[matches\]: true$/
|
syntax match cpOutputMatchesTrue /^\[matches\]:\ze true$/
|
||||||
syntax match cpOutputMatchesFalse /^\[matches\]: false$/
|
syntax match cpOutputMatchesFalse /^\[matches\]:\ze false$/
|
||||||
|
|
||||||
highlight default link cpOutputCode DiagnosticInfo
|
highlight default link cpOutputCode DiagnosticInfo
|
||||||
highlight default link cpOutputTime Comment
|
highlight default link cpOutputTime Comment
|
||||||
|
|
|
||||||
|
|
@ -75,8 +75,14 @@ local function check_config()
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.check()
|
function M.check()
|
||||||
|
local version = require("cp.version")
|
||||||
vim.health.start("cp.nvim health check")
|
vim.health.start("cp.nvim health check")
|
||||||
|
|
||||||
|
vim.health.info("Version: " .. version.version)
|
||||||
|
if version.semver then
|
||||||
|
vim.health.info("Semantic version: v" .. version.semver.full)
|
||||||
|
end
|
||||||
|
|
||||||
check_nvim_version()
|
check_nvim_version()
|
||||||
check_uv()
|
check_uv()
|
||||||
check_python_env()
|
check_python_env()
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ local function setup_problem(problem_id, problem_letter)
|
||||||
|
|
||||||
local ctx = problem.create_context(vim.g.cp_contest, problem_id, problem_letter, config)
|
local ctx = problem.create_context(vim.g.cp_contest, problem_id, problem_letter, config)
|
||||||
|
|
||||||
local scrape_result = scrape.scrape_problem(vim.g.cp_contest, problem_id, problem_letter)
|
local scrape_result = scrape.scrape_problem(ctx)
|
||||||
|
|
||||||
if not scrape_result.success then
|
if not scrape_result.success then
|
||||||
logger.log("scraping failed: " .. scrape_result.error, vim.log.levels.WARN)
|
logger.log("scraping failed: " .. scrape_result.error, vim.log.levels.WARN)
|
||||||
|
|
|
||||||
|
|
@ -35,23 +35,14 @@ local function setup_python_env()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.scrape_problem(contest, problem_id, problem_letter)
|
---@param ctx ProblemContext
|
||||||
|
function M.scrape_problem(ctx)
|
||||||
ensure_io_directory()
|
ensure_io_directory()
|
||||||
|
|
||||||
local cache_problem_id = problem_id:lower()
|
if vim.fn.filereadable(ctx.input_file) == 1 and vim.fn.filereadable(ctx.expected_file) == 1 then
|
||||||
if contest == "atcoder" or contest == "codeforces" then
|
|
||||||
if problem_letter then
|
|
||||||
cache_problem_id = cache_problem_id .. problem_letter:lower()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local input_file = "io/" .. cache_problem_id .. ".in"
|
|
||||||
local expected_file = "io/" .. cache_problem_id .. ".expected"
|
|
||||||
|
|
||||||
if vim.fn.filereadable(input_file) == 1 and vim.fn.filereadable(expected_file) == 1 then
|
|
||||||
return {
|
return {
|
||||||
success = true,
|
success = true,
|
||||||
problem_id = cache_problem_id,
|
problem_id = ctx.problem_name,
|
||||||
test_count = 1,
|
test_count = 1,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
@ -64,13 +55,13 @@ function M.scrape_problem(contest, problem_id, problem_letter)
|
||||||
end
|
end
|
||||||
|
|
||||||
local plugin_path = get_plugin_path()
|
local plugin_path = get_plugin_path()
|
||||||
local scraper_path = plugin_path .. "/scrapers/" .. contest .. ".py"
|
local scraper_path = plugin_path .. "/scrapers/" .. ctx.contest .. ".py"
|
||||||
|
|
||||||
local args
|
local args
|
||||||
if contest == "cses" then
|
if ctx.contest == "cses" then
|
||||||
args = { "uv", "run", scraper_path, problem_id }
|
args = { "uv", "run", scraper_path, ctx.problem_id }
|
||||||
else
|
else
|
||||||
args = { "uv", "run", scraper_path, problem_id, problem_letter }
|
args = { "uv", "run", scraper_path, ctx.problem_id, ctx.problem_letter }
|
||||||
end
|
end
|
||||||
|
|
||||||
local result = vim.system(args, {
|
local result = vim.system(args, {
|
||||||
|
|
@ -98,9 +89,6 @@ function M.scrape_problem(contest, problem_id, problem_letter)
|
||||||
return data
|
return data
|
||||||
end
|
end
|
||||||
|
|
||||||
local full_problem_id = data.problem_id:lower()
|
|
||||||
input_file = "io/" .. full_problem_id .. ".in"
|
|
||||||
expected_file = "io/" .. full_problem_id .. ".expected"
|
|
||||||
|
|
||||||
if #data.test_cases > 0 then
|
if #data.test_cases > 0 then
|
||||||
local all_inputs = {}
|
local all_inputs = {}
|
||||||
|
|
@ -119,13 +107,13 @@ function M.scrape_problem(contest, problem_id, problem_letter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.fn.writefile(all_inputs, input_file)
|
vim.fn.writefile(all_inputs, ctx.input_file)
|
||||||
vim.fn.writefile(all_outputs, expected_file)
|
vim.fn.writefile(all_outputs, ctx.expected_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success = true,
|
success = true,
|
||||||
problem_id = full_problem_id,
|
problem_id = ctx.problem_name,
|
||||||
test_count = #data.test_cases,
|
test_count = #data.test_cases,
|
||||||
url = data.url,
|
url = data.url,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
36
lua/cp/version.lua
Normal file
36
lua/cp/version.lua
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
local function get_git_version()
|
||||||
|
local plugin_path = debug.getinfo(1, "S").source:sub(2)
|
||||||
|
local plugin_root = vim.fn.fnamemodify(plugin_path, ":h:h:h")
|
||||||
|
|
||||||
|
local result = vim.system({"git", "describe", "--tags", "--always", "--dirty"}, {
|
||||||
|
cwd = plugin_root,
|
||||||
|
text = true
|
||||||
|
}):wait()
|
||||||
|
|
||||||
|
if result.code == 0 then
|
||||||
|
return result.stdout:gsub("\n", "")
|
||||||
|
else
|
||||||
|
return "unknown"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function parse_semver(version_string)
|
||||||
|
local semver = version_string:match("^v?(%d+%.%d+%.%d+)")
|
||||||
|
if semver then
|
||||||
|
local major, minor, patch = semver:match("(%d+)%.(%d+)%.(%d+)")
|
||||||
|
return {
|
||||||
|
full = semver,
|
||||||
|
major = tonumber(major),
|
||||||
|
minor = tonumber(minor),
|
||||||
|
patch = tonumber(patch)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
M.version = get_git_version()
|
||||||
|
M.semver = parse_semver(M.version)
|
||||||
|
|
||||||
|
return M
|
||||||
|
|
@ -20,3 +20,4 @@ end, {
|
||||||
end, commands)
|
end, commands)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue