Re: [PATCH] Tab complete EXECUTE FUNCTION for CREATE (EVENT) TRIGGER - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: [PATCH] Tab complete EXECUTE FUNCTION for CREATE (EVENT) TRIGGER
Date
Msg-id 20181025113909.GA1327@paquier.xyz
Whole thread Raw
In response to Re: [PATCH] Tab complete EXECUTE FUNCTION for CREATE (EVENT) TRIGGER  (ilmari@ilmari.org (Dagfinn Ilmari Mannsåker))
Responses Re: [PATCH] Tab complete EXECUTE FUNCTION for CREATE (EVENT) TRIGGER  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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

Attachment

pgsql-hackers by date:

Previous
From: ilmari@ilmari.org (Dagfinn Ilmari Mannsåker)
Date:
Subject: Re: [PATCH] Tab complete EXECUTE FUNCTION for CREATE (EVENT) TRIGGER
Next
From: Michael Paquier
Date:
Subject: Re: pg_stat_replication vs StandbyReplyMessage