Re: [PATCH] Tab complete EXECUTE FUNCTION for CREATE (EVENT) TRIGGER

Michael Paquier <michael@paquier.xyz>

From: Michael Paquier <michael@paquier.xyz>
To: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, David Fetter <david@fetter.org>, pgsql-hackers@postgresql.org
Date: 2018-10-25T11:39:09Z
Lists: pgsql-hackers
On Thu, Oct 25, 2018 at 12:25:33PM +0100, Dagfinn Ilmari Mannsåker wrote:
> I did that initially, but because COMPLETE_WITH() requres constant
> arguments, I had to repeat the whole list with just changing PROCEDURE
> to FUNCTION, which I thought was undesirably repetitive.  If there's a
> more concise alternative to the below, or the consensus is that saving
> one TAB press is worth it, I'll change it.
> 
>     else if (HeadMatches("CREATE", "TRIGGER") && TailMatches("ON", MatchAny))
>         if (pset.sversion >= 110000)
>             COMPLETE_WITH("NOT DEFERRABLE", "DEFERRABLE", "INITIALLY",
>                           "REFERENCING", "FOR", "WHEN (", "EXECUTE FUNCTION");
>         else
>             COMPLETE_WITH("NOT DEFERRABLE", "DEFERRABLE", "INITIALLY",
>                           "REFERENCING", "FOR", "WHEN (", "EXECUTE PROCEDURE");

[thinking]

To keep the code simple, you could do something like that, by checking
the head keywords for a match with CREATE TRIGGER, and then move all the
existing conditions within it:
else if (HeadMatches("CREATE", "TRIGGER", MatchAny))
{
    char *execute_keyword;

    if (pset.sversion >= 110000)
        execute_keyword = "EXECUTE FUNCTION";
    else
        execute_keyword = "EXECUTE PROCEDURE";

    if (TailMatches("CREATE", "TRIGGER", MatchAny))
        COMPLETE_WITH("BEFORE", "AFTER", "INSTEAD OF");
    [...]
    else if (the other existing conditions)
        blah and use execute_keyword in the lists;
}

If we do the automatic completion of both words at the same time, let's
put only in a single place the version-based switch.  This method costs
an extra match check on the header keywords when CREATE TRIGGER matches,
but it allows all the other checks to skip steps, which is actually a
win for the rest.
--
Michael

Commits

  1. Add tab completion of EXECUTE FUNCTION for CREATE TRIGGER in psql

  2. Improve tab completion of CREATE EVENT TRIGGER in psql

  3. Improve tab completion for ANALYZE, EXPLAIN, and VACUUM.