feat(commands): standalone :CP login/logout with auto-restore
Problem: `:CP login` and `:CP logout` only worked as `:CP <platform> login`. Users with an active platform or in a registered buffer had to type the platform name redundantly. Solution: Parse standalone `login`/`logout`/`signup` as action commands with `requires_context = true`, resolving the platform from state (or auto-restoring from the current buffer). Add `vim.cmd.redraw()` after auto-restore so the screen updates before any prompt. Add `login`/ `logout` to top-level completion when a platform is active.
This commit is contained in:
parent
e3c81e895a
commit
693d3bf172
3 changed files with 32 additions and 6 deletions
|
|
@ -453,6 +453,7 @@ COMMANDS *cp-commands*
|
|||
any previously saved credentials.
|
||||
If [platform] is omitted, uses the active platform.
|
||||
Examples: >
|
||||
:CP login
|
||||
:CP login atcoder
|
||||
:CP login codeforces
|
||||
<
|
||||
|
|
@ -460,6 +461,7 @@ COMMANDS *cp-commands*
|
|||
Remove stored credentials for a platform.
|
||||
If [platform] is omitted, uses the active platform.
|
||||
Examples: >
|
||||
:CP logout
|
||||
:CP logout atcoder
|
||||
<
|
||||
:CP {platform} signup
|
||||
|
|
|
|||
|
|
@ -326,6 +326,10 @@ local function parse_command(args)
|
|||
end
|
||||
end
|
||||
|
||||
if (first == 'login' or first == 'logout' or first == 'signup') and #args == 1 then
|
||||
return { type = 'action', action = first, requires_context = true, platform = nil }
|
||||
end
|
||||
|
||||
if #args == 1 then
|
||||
return {
|
||||
type = 'problem_jump',
|
||||
|
|
@ -378,6 +382,7 @@ function M.handle_command(opts)
|
|||
if not restore.restore_from_current_file() then
|
||||
return
|
||||
end
|
||||
vim.cmd.redraw()
|
||||
end
|
||||
|
||||
local setup = require('cp.setup')
|
||||
|
|
@ -421,20 +426,35 @@ function M.handle_command(opts)
|
|||
end
|
||||
vim.ui.open(url)
|
||||
elseif cmd.action == 'login' then
|
||||
if not check_platform_enabled(cmd.platform) then
|
||||
local p = cmd.platform or state.get_platform()
|
||||
if not p then
|
||||
logger.log('No platform active. Usage: :CP <platform> login', { level = vim.log.levels.ERROR })
|
||||
return
|
||||
end
|
||||
require('cp.credentials').login(cmd.platform)
|
||||
if not check_platform_enabled(p) then
|
||||
return
|
||||
end
|
||||
require('cp.credentials').login(p)
|
||||
elseif cmd.action == 'logout' then
|
||||
if not check_platform_enabled(cmd.platform) then
|
||||
local p = cmd.platform or state.get_platform()
|
||||
if not p then
|
||||
logger.log('No platform active. Usage: :CP <platform> logout', { level = vim.log.levels.ERROR })
|
||||
return
|
||||
end
|
||||
require('cp.credentials').logout(cmd.platform)
|
||||
if not check_platform_enabled(p) then
|
||||
return
|
||||
end
|
||||
require('cp.credentials').logout(p)
|
||||
elseif cmd.action == 'signup' then
|
||||
local url = constants.SIGNUP_URLS[cmd.platform]
|
||||
local p = cmd.platform or state.get_platform()
|
||||
if not p then
|
||||
logger.log('No platform active. Usage: :CP <platform> signup', { level = vim.log.levels.ERROR })
|
||||
return
|
||||
end
|
||||
local url = constants.SIGNUP_URLS[p]
|
||||
if not url then
|
||||
logger.log(
|
||||
("No signup URL available for '%s'"):format(cmd.platform),
|
||||
("No signup URL available for '%s'"):format(p),
|
||||
{ level = vim.log.levels.WARN }
|
||||
)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -43,6 +43,10 @@ end, {
|
|||
vim.list_extend(candidates, platforms)
|
||||
table.insert(candidates, 'cache')
|
||||
table.insert(candidates, 'pick')
|
||||
if platform then
|
||||
table.insert(candidates, 'login')
|
||||
table.insert(candidates, 'logout')
|
||||
end
|
||||
if platform and contest_id then
|
||||
vim.list_extend(
|
||||
candidates,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue