fix(config): better file org
This commit is contained in:
parent
a76d228e3f
commit
d2bde9bad8
12 changed files with 77 additions and 79 deletions
|
|
@ -1,4 +1,3 @@
|
|||
-- lua/cp/setup.lua
|
||||
local M = {}
|
||||
|
||||
local cache = require('cp.cache')
|
||||
|
|
@ -40,14 +39,15 @@ end
|
|||
---@param platform string
|
||||
---@param contest_id string
|
||||
---@param problem_id string|nil
|
||||
function M.setup_contest(platform, contest_id, problem_id)
|
||||
---@param language? string|nil
|
||||
function M.setup_contest(platform, contest_id, problem_id, language)
|
||||
state.set_contest_id(contest_id)
|
||||
cache.load()
|
||||
|
||||
local function proceed(contest_data)
|
||||
local problems = contest_data.problems
|
||||
local pid = problems[(problem_id and contest_data.index_map[problem_id] or 1)].id
|
||||
M.setup_problem(pid)
|
||||
M.setup_problem(pid, language)
|
||||
|
||||
local cached_len = #vim.tbl_filter(function(p)
|
||||
return not vim.tbl_isempty(cache.get_test_cases(platform, contest_id, p.id))
|
||||
|
|
@ -89,7 +89,8 @@ function M.setup_contest(platform, contest_id, problem_id)
|
|||
end
|
||||
|
||||
---@param problem_id string
|
||||
function M.setup_problem(problem_id)
|
||||
---@param language? string
|
||||
function M.setup_problem(problem_id, language)
|
||||
local platform = state.get_platform()
|
||||
if not platform then
|
||||
logger.log('No platform set.', vim.log.levels.ERROR)
|
||||
|
|
@ -103,17 +104,17 @@ function M.setup_problem(problem_id)
|
|||
vim.schedule(function()
|
||||
vim.cmd.only({ mods = { silent = true } })
|
||||
|
||||
local language = config.platforms[platform].default_language
|
||||
local source_file = state.get_source_file(language)
|
||||
local lang = language or config.platforms[platform].default_language
|
||||
local source_file = state.get_source_file(lang)
|
||||
vim.cmd.e(source_file)
|
||||
local source_buf = vim.api.nvim_get_current_buf()
|
||||
|
||||
if vim.api.nvim_buf_get_lines(source_buf, 0, -1, true)[1] == '' then
|
||||
local has_luasnip, luasnip = pcall(require, 'luasnip')
|
||||
if has_luasnip then
|
||||
local prefixed_trigger = ('cp.nvim/%s.%s'):format(platform, language)
|
||||
vim.api.nvim_buf_set_lines(0, 0, -1, false, { prefixed_trigger })
|
||||
vim.api.nvim_win_set_cursor(0, { 1, #prefixed_trigger })
|
||||
local ok, luasnip = pcall(require, 'luasnip')
|
||||
if ok then
|
||||
local trigger = ('cp.nvim/%s.%s'):format(platform, lang)
|
||||
vim.api.nvim_buf_set_lines(0, 0, -1, false, { trigger })
|
||||
vim.api.nvim_win_set_cursor(0, { 1, #trigger })
|
||||
vim.cmd.startinsert({ bang = true })
|
||||
vim.schedule(function()
|
||||
if luasnip.expandable() then
|
||||
|
|
@ -135,7 +136,8 @@ function M.setup_problem(problem_id)
|
|||
vim.fn.expand('%:p'),
|
||||
platform,
|
||||
state.get_contest_id() or '',
|
||||
state.get_problem_id()
|
||||
state.get_problem_id() or '',
|
||||
lang
|
||||
)
|
||||
end)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue