diff --git a/README.md b/README.md index dbbafe4..c2da671 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ cp.nvim follows a simple principle: **solve locally, submit remotely**. ### Basic Usage 1. **Find a contest or problem** on the judge website -2. **Set up locally** with `:CP [--{lang=,debug}]` +2. **Set up locally** with `:CP ` ``` :CP codeforces 1848 diff --git a/doc/cp.nvim.txt b/doc/cp.nvim.txt index 60ceec3..70e2504 100644 --- a/doc/cp.nvim.txt +++ b/doc/cp.nvim.txt @@ -35,13 +35,12 @@ COMMANDS *cp-commands* Requires previous setup with full :CP command. Setup Commands ~ - :CP {platform} {contest_id} {problem_id} [--lang={language}] + :CP {platform} {contest_id} {problem_id} Full setup: set platform, load contest metadata, and set up specific problem. Scrapes test cases and creates source file. Example: > :CP codeforces 1933 a - :CP codeforces 1933 a --lang=python < :CP {platform} {contest_id} Contest setup: set platform, load contest metadata, @@ -89,13 +88,6 @@ Command Flags ~ *cp-flags* Flags can be used with setup and action commands: - --lang={language} Specify language for the problem. - --lang {language} Alternative syntax for language specification. - Supported languages: cpp, python - Example: > - :CP atcoder abc324 a --lang=python - :CP b --lang cpp -< --debug Enable debug compilation with additional flags. Uses the `debug` command template instead of `compile`. Typically includes debug symbols and @@ -103,9 +95,6 @@ Command Flags ~ Example: > :CP run --debug < - Note: Debug compilation may be slower but provides - better error reporting for runtime issues. - Template Variables ~ *cp-template-vars* Command templates support variable substitution using `{variable}` syntax: @@ -204,8 +193,7 @@ is required: Fields: ~ {cpp} (|LanguageConfig|) C++ language configuration. {python} (|LanguageConfig|) Python language configuration. - {default_language} (string, default: "cpp") Default language when - --lang not specified. + {default_language} (string, default: "cpp") Default language for contests. *cp.LanguageConfig* Fields: ~ diff --git a/lua/cp/commands/init.lua b/lua/cp/commands/init.lua index 6ad48c2..6923a0f 100644 --- a/lua/cp/commands/init.lua +++ b/lua/cp/commands/init.lua @@ -10,7 +10,6 @@ local actions = constants.ACTIONS ---@class ParsedCommand ---@field type string ---@field error string? ----@field language? string ---@field debug? boolean ---@field action? string ---@field message? string @@ -27,26 +26,10 @@ local function parse_command(args) } end - local language = nil - local debug = false - - for i, arg in ipairs(args) do - local lang_match = arg:match('^--lang=(.+)$') - if lang_match then - language = lang_match - elseif arg == '--lang' then - if i + 1 <= #args then - language = args[i + 1] - else - return { type = 'error', message = '--lang requires a value' } - end - elseif arg == '--debug' then - debug = true - end - end + local debug = vim.tbl_contains(args, '--debug') local filtered_args = vim.tbl_filter(function(arg) - return not (arg:match('^--lang') or arg == language or arg == '--debug') + return arg ~= '--debug' end, args) local first = filtered_args[1] @@ -68,7 +51,7 @@ local function parse_command(args) return { type = 'error', message = 'unknown cache subcommand: ' .. subcommand } end else - return { type = 'action', action = first, language = language, debug = debug } + return { type = 'action', action = first, debug = debug } end end @@ -83,12 +66,11 @@ local function parse_command(args) type = 'contest_setup', platform = first, contest = filtered_args[2], - language = language, } elseif #filtered_args == 3 then return { type = 'error', - message = 'Setup contests with :CP [--{lang=,debug}]', + message = 'Setup contests with :CP ', } else return { type = 'error', message = 'Too many arguments' } @@ -129,9 +111,9 @@ function M.handle_command(opts) elseif cmd.action == 'run' then ui.toggle_run_panel(cmd.debug) elseif cmd.action == 'next' then - setup.navigate_problem(1, cmd.language) + setup.navigate_problem(1) elseif cmd.action == 'prev' then - setup.navigate_problem(-1, cmd.language) + setup.navigate_problem(-1) elseif cmd.action == 'pick' then local picker = require('cp.commands.picker') picker.handle_pick_action() @@ -142,7 +124,7 @@ function M.handle_command(opts) elseif cmd.type == 'contest_setup' then local setup = require('cp.setup') if setup.set_platform(cmd.platform) then - setup.setup_contest(cmd.platform, cmd.contest, cmd.language, nil) + setup.setup_contest(cmd.platform, cmd.contest, nil) end return end diff --git a/lua/cp/restore.lua b/lua/cp/restore.lua index 54ff8be..2a02f96 100644 --- a/lua/cp/restore.lua +++ b/lua/cp/restore.lua @@ -14,10 +14,7 @@ function M.restore_from_current_file() cache.load() local file_state = cache.get_file_state(current_file) if not file_state then - logger.log( - 'No cached state found for current file. Use :CP [--{lang=,debug}...] first.', - vim.log.levels.ERROR - ) + logger.log('No cached state found for current file.', vim.log.levels.ERROR) return false end @@ -37,12 +34,7 @@ function M.restore_from_current_file() state.set_contest_id(file_state.contest_id) state.set_problem_id(file_state.problem_id) - setup.setup_contest( - file_state.platform, - file_state.contest_id, - file_state.language, - file_state.problem_id - ) + setup.setup_contest(file_state.platform, file_state.contest_id, file_state.problem_id) return true end diff --git a/lua/cp/scraper.lua b/lua/cp/scraper.lua index 0d334d6..5a973e5 100644 --- a/lua/cp/scraper.lua +++ b/lua/cp/scraper.lua @@ -4,8 +4,8 @@ local utils = require('cp.utils') local function syshandle(result) if result.code ~= 0 then + vim.print(('<%s>'):format(result.stderr)) local msg = 'Scraper failed: ' .. (result.stderr or 'Unknown error') - logger.log(msg, vim.log.levels.ERROR) return { success = false, error = msg } end @@ -114,7 +114,7 @@ function M.scrape_contest_metadata(platform, contest_id, callback) on_exit = function(result) if not result or not result.success then logger.log( - ('Failed to scrape metadata for %s contest %s.'):format(platform, contest_id), + ("Failed to scrape metadata for %s contest '%s'."):format(platform, contest_id), vim.log.levels.ERROR ) return @@ -122,7 +122,7 @@ function M.scrape_contest_metadata(platform, contest_id, callback) local data = result.data or {} if not data.problems or #data.problems == 0 then logger.log( - ('No problems returned for %s contest %s.'):format(platform, contest_id), + ("No problems returned for %s contest '%s'."):format(platform, contest_id), vim.log.levels.ERROR ) return @@ -161,7 +161,7 @@ function M.scrape_all_tests(platform, contest_id, callback) end if ev.error and ev.problem_id then logger.log( - ('Failed to load tests for %s/%s: %s'):format(contest_id, ev.problem_id, ev.error), + ("Failed to load tests for problem '%s': %s"):format(contest_id, ev.problem_id, ev.error), vim.log.levels.WARN ) return diff --git a/lua/cp/setup.lua b/lua/cp/setup.lua index 4c6d03f..e4705f5 100644 --- a/lua/cp/setup.lua +++ b/lua/cp/setup.lua @@ -40,9 +40,8 @@ end ---@param platform string ---@param contest_id string ----@param language string|nil ---@param problem_id string|nil -function M.setup_contest(platform, contest_id, language, problem_id) +function M.setup_contest(platform, contest_id, problem_id) local config = config_module.get_config() if not vim.tbl_contains(config.scrapers, platform) then logger.log(('Scraping disabled for %s.'):format(platform), vim.log.levels.WARN) @@ -101,10 +100,7 @@ end function M.setup_problem(problem_id, language) local platform = state.get_platform() if not platform then - logger.log( - 'No platform set. run :CP [--{lang=,debug}]', - vim.log.levels.ERROR - ) + logger.log('No platform set.', vim.log.levels.ERROR) return end @@ -160,7 +156,7 @@ function M.setup_problem(problem_id, language) end) end -function M.navigate_problem(direction, language) +function M.navigate_problem(direction) if direction == 0 then return end @@ -171,10 +167,7 @@ function M.navigate_problem(direction, language) local current_problem_id = state.get_problem_id() if not platform or not contest_id or not current_problem_id then - logger.log( - 'No platform configured. Use :CP [--{lang=,debug}] first.', - vim.log.levels.ERROR - ) + logger.log('No platform configured.', vim.log.levels.ERROR) return end @@ -200,7 +193,7 @@ function M.navigate_problem(direction, language) end require('cp.ui.panel').disable() - M.setup_contest(platform, contest_id, language, problems[new_index].id) + M.setup_contest(platform, contest_id, problems[new_index].id) end return M