Files
codex/codex-rs/tui/src/slash_command_settings.rs
T
Benjamin Carlsson 59edd0d512 Complete named settings for TUI slash commands (#63036)
## Why

Slash-command completion only suggested positional arguments, leaving users
to recall named flags and their accepted values.

## What changed

Suggest flags for `/model`, `/permissions`, `/title`, `/statusline`, and
`/mcp login` using the same flag definitions as command parsing. Tab
completes known values in both `--name=value` and `--name value` forms.
For example, `/model --speed=f` completes to `/model --speed=flex`.

Named completion also works in multiline drafts and filters out flags
already present in the command.

## Testing

Add composer tests for both value forms, multiline completion, duplicate
flags, and quoted arguments, plus a snapshot of the `/model` flag popup.

GitOrigin-RevId: f874f67c4601012252775e811ddf496dbc6c4817
2026-11-21 20:41:19 +00:00

37 lines
1.2 KiB
Rust

//! Named slash-command settings shared by submission and composer completion.
use crate::slash_command::SlashCommand;
type Names = &'static [&'static str];
pub(crate) struct Settings {
pub(crate) values: Names,
pub(crate) switches: Names,
pub(crate) booleans: Names,
}
pub(crate) fn for_command(command: SlashCommand) -> Settings {
let (values, switches, booleans): (Names, Names, Names) = match command {
SlashCommand::Model => (&["--reasoning", "--speed"], &[], &[]),
SlashCommand::Permissions => (&["--approval-policy", "--reviewer"], &[], &[]),
SlashCommand::Title => (&[], &["--clear"], &[]),
SlashCommand::Statusline => (&[], &["--clear"], &["colors"]),
SlashCommand::Mcp => (&["--environment"], &[], &[]),
_ => (&[], &[], &[]),
};
Settings {
values,
switches,
booleans,
}
}
pub(crate) fn value_choices(command: SlashCommand, name: &str) -> &'static [&'static str] {
match (command, name) {
(SlashCommand::Permissions, "--approval-policy") => &["untrusted", "on-request", "never"],
(SlashCommand::Permissions, "--reviewer") => &["user", "auto_review"],
(SlashCommand::Model, "--speed") => &["standard", "flex"],
_ => &[],
}
}