Hi hackers,
After spending some time in tab-complete.c responding to a bug report, I had very strong urge to find a way to make it a bit easier to maintain. Do you think it would be an improvement if we changed all the code that looks a bit like this:
/* Complete CREATE TRIGGER <name> BEFORE|AFTER with an event */
else if (pg_strcasecmp(prev4_wd, "CREATE") == 0 &&
pg_strcasecmp(prev3_wd, "TRIGGER") == 0 &&
(pg_strcasecmp(prev_wd, "BEFORE") == 0 ||
pg_strcasecmp(prev_wd, "AFTER") == 0))
{
static const char *const list_CREATETRIGGER_EVENTS[] =
{"INSERT", "DELETE", "UPDATE", "TRUNCATE", NULL};
COMPLETE_WITH_LIST(list_CREATETRIGGER_EVENTS);
}
... into code that looks a bit like this?
/* Complete CREATE TRIGGER <name> BEFORE|AFTER with an event */
else if (MATCHES4("CREATE", "TRIGGER", "<name>", "BEFORE|AFTER"))
COMPLETE_WITH_LIST4("INSERT", "DELETE", "UPDATE", "TRUNCATE");
See attached a proof-of-concept patch. It reduces the size of tab-complete.c by a bit over a thousand lines. I realise that changing so many lines just to refactor code may may be a difficult sell! But I think this would make it easier to improve the tab completion code in future, and although it's large it's a superficial and mechanical change.
--