feat: flesh out language support
This commit is contained in:
parent
e806b23020
commit
4aa16d2858
7 changed files with 254 additions and 99 deletions
|
|
@ -11,15 +11,41 @@ vim.api.nvim_create_user_command("CP", function(opts)
|
|||
cp.handle_command(opts)
|
||||
end, {
|
||||
nargs = "*",
|
||||
desc = "Competitive programming helper",
|
||||
complete = function(ArgLead, CmdLine, _)
|
||||
local filetype_to_language = {
|
||||
cc = "cpp",
|
||||
c = "cpp",
|
||||
py = "python",
|
||||
py3 = "python",
|
||||
}
|
||||
|
||||
local languages = vim.tbl_keys(vim.tbl_add_reverse_lookup(filetype_to_language))
|
||||
|
||||
if ArgLead:match("^--lang=") then
|
||||
local lang_completions = {}
|
||||
for _, lang in ipairs(languages) do
|
||||
table.insert(lang_completions, "--lang=" .. lang)
|
||||
end
|
||||
return vim.tbl_filter(function(completion)
|
||||
return completion:find(ArgLead, 1, true) == 1
|
||||
end, lang_completions)
|
||||
end
|
||||
|
||||
if ArgLead == "--lang" then
|
||||
return { "--lang" }
|
||||
end
|
||||
|
||||
local args = vim.split(vim.trim(CmdLine), "%s+")
|
||||
local num_args = #args
|
||||
if CmdLine:sub(-1) == " " then
|
||||
num_args = num_args + 1
|
||||
end
|
||||
|
||||
local lang_flag_present = vim.tbl_contains(args, "--lang") or vim.iter(args):any(function(arg) return arg:match("^--lang=") end)
|
||||
|
||||
if num_args == 2 then
|
||||
local candidates = {}
|
||||
local candidates = { "--lang" }
|
||||
vim.list_extend(candidates, platforms)
|
||||
vim.list_extend(candidates, actions)
|
||||
local cp = require("cp")
|
||||
|
|
@ -37,13 +63,17 @@ end, {
|
|||
return vim.tbl_filter(function(cmd)
|
||||
return cmd:find(ArgLead, 1, true) == 1
|
||||
end, candidates)
|
||||
elseif num_args == 4 then
|
||||
elseif args[#args-1] == "--lang" then
|
||||
return vim.tbl_filter(function(lang)
|
||||
return lang:find(ArgLead, 1, true) == 1
|
||||
end, languages)
|
||||
elseif num_args == 4 and not lang_flag_present then
|
||||
if vim.tbl_contains(platforms, args[2]) then
|
||||
local cache = require("cp.cache")
|
||||
cache.load()
|
||||
local contest_data = cache.get_contest_data(args[2], args[3])
|
||||
if contest_data and contest_data.problems then
|
||||
local candidates = {}
|
||||
local candidates = { "--lang" }
|
||||
for _, problem in ipairs(contest_data.problems) do
|
||||
table.insert(candidates, problem.id)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue