diff --git a/.luarc.json b/.luarc.json index e0f7a7c..19558f6 100644 --- a/.luarc.json +++ b/.luarc.json @@ -1,16 +1,8 @@ { - "runtime": { - "version": "LuaJIT", - "path": ["lua/?.lua", "lua/?/init.lua"] - }, - "diagnostics": { - "globals": ["vim"] - }, - "workspace": { - "library": ["$VIMRUNTIME/lua", "${3rd}/luv/library", "${3rd}/busted/library"], - "checkThirdParty": false - }, - "completion": { - "callSnippet": "Replace" - } + "runtime.version": "LuaJIT", + "runtime.path": ["lua/?.lua", "lua/?/init.lua"], + "diagnostics.globals": ["vim"], + "workspace.library": ["$VIMRUNTIME/lua", "${3rd}/luv/library"], + "workspace.checkThirdParty": false, + "completion.callSnippet": "Replace" } diff --git a/doc/cp.nvim.txt b/doc/cp.nvim.txt index 27563a1..49cdaf7 100644 --- a/doc/cp.nvim.txt +++ b/doc/cp.nvim.txt @@ -888,116 +888,6 @@ Functions ~ Parameters: ~ {bufnr} (integer) Buffer handle -============================================================================== -STATUSLINE INTEGRATION *cp-statusline* - -cp.nvim exposes its runtime state through a public module that can be queried -from any statusline plugin. Import it with: >lua - local state = require('cp.state') -< -All getters return nil when no problem is active, so guard every value before -use. Calling any getter outside a CP context is safe and has no side effects. - -State API ~ - *cp.State* -The following getters are available for statusline use: - - get_platform() (string?) Platform id. e.g. "codeforces", "atcoder" - get_contest_id() (string?) Contest id. e.g. "1933", "abc324" - get_problem_id() (string?) Problem id. e.g. "A", "B" - get_language() (string?) Language id. e.g. "cpp", "python" - get_base_name() (string?) Derived filename stem. e.g. "1933a" - get_source_file() (string?) Full source filename. e.g. "1933a.cc" - get_active_panel() (string?) Non-nil when the test panel is open. - -Recipe: vanilla statusline ~ - -Set vim.o.statusline from an autocommand so it is recalculated on every -BufEnter: >lua - local function cp_component() - local state = require('cp.state') - local platform = state.get_platform() - if not platform then - return '' - end - local parts = { - platform, - state.get_contest_id(), - state.get_problem_id(), - state.get_language(), - } - local filtered = {} - for _, v in ipairs(parts) do - if v then filtered[#filtered + 1] = v end - end - return '[' .. table.concat(filtered, ' · ') .. ']' - end - - vim.api.nvim_create_autocmd({ 'BufEnter', 'User' }, { - callback = function() - vim.o.statusline = cp_component() .. ' %f %=%l:%c' - end - }) -< - -Recipe: lualine ~ - -Add a custom component to any lualine section. The cond field hides the -component entirely when no problem is active: >lua - local function cp_lualine() - local state = require('cp.state') - local parts = { - state.get_platform(), - state.get_contest_id(), - state.get_problem_id(), - state.get_language(), - } - local filtered = {} - for _, v in ipairs(parts) do - if v then filtered[#filtered + 1] = v end - end - return table.concat(filtered, ' · ') - end - - require('lualine').setup({ - sections = { - lualine_c = { - { - cp_lualine, - cond = function() - return require('cp.state').get_platform() ~= nil - end, - }, - }, - }, - }) -< - -Recipe: heirline ~ - -Build a heirline component using a provider and condition: >lua - local CpComponent = { - condition = function() - return require('cp.state').get_platform() ~= nil - end, - provider = function() - local state = require('cp.state') - local parts = { - state.get_platform(), - state.get_contest_id(), - state.get_problem_id(), - state.get_language(), - } - local filtered = {} - for _, v in ipairs(parts) do - if v then filtered[#filtered + 1] = v end - end - return '[' .. table.concat(filtered, ' · ') .. ']' - end, - } -< -Include CpComponent in your heirline StatusLine spec wherever desired. - ============================================================================== PANEL KEYMAPS *cp-panel-keys* diff --git a/lua/cp/cache.lua b/lua/cp/cache.lua index 33342c2..efdcad7 100644 --- a/lua/cp/cache.lua +++ b/lua/cp/cache.lua @@ -346,8 +346,6 @@ function M.get_data_pretty() return vim.inspect(cache_data) end -function M.get_raw_cache() - return cache_data -end +M._cache = cache_data return M diff --git a/lua/cp/health.lua b/lua/cp/health.lua index 97595d6..d3a3fea 100644 --- a/lua/cp/health.lua +++ b/lua/cp/health.lua @@ -13,7 +13,7 @@ local function check() vim.health.error('cp.nvim requires Neovim 0.10.0+') end - local uname = vim.uv.os_uname() + local uname = vim.loop.os_uname() if uname.sysname == 'Windows_NT' then vim.health.error('Windows is not supported') end diff --git a/lua/cp/runner/run.lua b/lua/cp/runner/run.lua index 4e4a8f6..36a560c 100644 --- a/lua/cp/runner/run.lua +++ b/lua/cp/runner/run.lua @@ -276,35 +276,26 @@ function M.run_all_test_cases(indices, debug, on_each, on_done) end end - if #to_run == 0 then - logger.log( - ('Finished %s %d test cases.'):format(debug and 'debugging' or 'running', 0), - vim.log.levels.INFO, - true - ) - on_done(panel_state.test_cases) - return - end + local function run_next(pos) + if pos > #to_run then + logger.log( + ('Finished %s %d test cases.'):format(debug and 'debugging' or 'running', #to_run), + vim.log.levels.INFO, + true + ) + on_done(panel_state.test_cases) + return + end - local total = #to_run - local remaining = total - - for _, idx in ipairs(to_run) do - M.run_test_case(idx, debug, function() + M.run_test_case(to_run[pos], debug, function() if on_each then - on_each(idx, total) - end - remaining = remaining - 1 - if remaining == 0 then - logger.log( - ('Finished %s %d test cases.'):format(debug and 'debugging' or 'running', total), - vim.log.levels.INFO, - true - ) - on_done(panel_state.test_cases) + on_each(pos, #to_run) end + run_next(pos + 1) end) end + + run_next(1) end ---@return PanelState diff --git a/lua/cp/scraper.lua b/lua/cp/scraper.lua index 29cc63e..73b6177 100644 --- a/lua/cp/scraper.lua +++ b/lua/cp/scraper.lua @@ -57,7 +57,7 @@ local function run_scraper(platform, subcommand, args, opts) env.CONDA_PREFIX = '' if opts and opts.ndjson then - local uv = vim.uv + local uv = vim.loop local stdout = uv.new_pipe(false) local stderr = uv.new_pipe(false) local buf = '' diff --git a/lua/cp/setup.lua b/lua/cp/setup.lua index 44c993d..0e8080b 100644 --- a/lua/cp/setup.lua +++ b/lua/cp/setup.lua @@ -10,13 +10,17 @@ local state = require('cp.state') local function apply_template(bufnr, lang_id, platform) local config = config_module.get_config() - local eff = config.runtime.effective[platform] and config.runtime.effective[platform][lang_id] + local eff = config.runtime.effective[platform] + and config.runtime.effective[platform][lang_id] if not eff or not eff.template then return end local path = vim.fn.expand(eff.template) if vim.fn.filereadable(path) ~= 1 then - logger.log(('[cp.nvim] template not readable: %s'):format(path), vim.log.levels.WARN) + logger.log( + ('[cp.nvim] template not readable: %s'):format(path), + vim.log.levels.WARN + ) return end local lines = vim.fn.readfile(path) @@ -194,7 +198,7 @@ function M.setup_contest(platform, contest_id, problem_id, language) contest_id = contest_id, language = lang, requested_problem_id = problem_id, - token = vim.uv.hrtime(), + token = vim.loop.hrtime(), }) logger.log('Fetching contests problems...', vim.log.levels.INFO, true) diff --git a/lua/cp/utils.lua b/lua/cp/utils.lua index 285ebf8..b602940 100644 --- a/lua/cp/utils.lua +++ b/lua/cp/utils.lua @@ -5,7 +5,7 @@ local logger = require('cp.log') local _nix_python = nil local _nix_discovered = false -local uname = vim.uv.os_uname() +local uname = vim.loop.os_uname() local _time_cached = false local _time_path = nil @@ -336,7 +336,7 @@ function M.timeout_capability() end function M.cwd_executables() - local uv = vim.uv + local uv = vim.uv or vim.loop local req = uv.fs_scandir('.') if not req then return {}