hint: show the matching usage template for multi-form commands

A parse error in `add index …` showed the `add column` usage:
`add` and `drop` are multi-form commands, and both the
ambient hint and the submit-time usage block picked the
first-listed form unconditionally.

New `grammar::usage_key_for_input` disambiguates by the form
word after the entry keyword — `column` / `index` / `table` /
`relationship`, or the leading digit of `add 1:n …`. The
ambient hint now shows that one form; `render_usage_block`
shows the committed form's usage and falls back to the whole
family only for a bare `add` / `drop` with no form chosen.
This commit is contained in:
claude@clouddev1
2026-05-19 08:37:17 +00:00
parent 5dc0421bd2
commit 151ed084a3
3 changed files with 71 additions and 3 deletions
+12 -1
View File
@@ -1812,7 +1812,18 @@ fn parse_error_message(err: &ParseError) -> String {
/// `drop` show every variant. Otherwise the fallback lists every
/// entry keyword alphabetically.
fn render_usage_block(input: &str) -> String {
if let Some((_word, catalog_keys)) = crate::dsl::grammar::usage_keys_for_input(input) {
// A multi-form command that has committed to a form
// (`add index …`) shows only that form's usage; a bare
// multi-form entry word (`add`) shows the whole family.
let catalog_keys: Vec<&'static str> =
crate::dsl::grammar::usage_key_for_input(input)
.map(|key| vec![key])
.or_else(|| {
crate::dsl::grammar::usage_keys_for_input(input)
.map(|(_word, all)| all.to_vec())
})
.unwrap_or_default();
if !catalog_keys.is_empty() {
let mut out = String::from("usage:");
for key in catalog_keys {
let template = crate::friendly::translate(key, &[]);