Improve tab completion of ALTER TYPE in psql
authorMichael Paquier <[email protected]>
Mon, 15 Aug 2022 05:08:59 +0000 (14:08 +0900)
committerMichael Paquier <[email protected]>
Mon, 15 Aug 2022 05:08:59 +0000 (14:08 +0900)
This commit adds support for more tab completion in this command as of
"ALTER TYPE .. SET".  The completion of "RENAME VALUE" was separated
from the rest of the completions done for this command, so group
everything together.

Author: Vignesh C
Discussion: https://postgr.es/m/CALDaNm1u83jtD2wysdw9XwokEacSXEyUpELajEvOMgJTc3pQ7g@mail.gmail.com

src/bin/psql/tab-complete.c

index f265e043e958c1ceabb949c049176a59e702e050..62a39779b9d1ba629fa145f19b1a69f02e07568d 100644 (file)
@@ -2516,6 +2516,17 @@ psql_completion(const char *text, int start, int end)
        /* ALTER TYPE ALTER ATTRIBUTE <foo> */
        else if (Matches("ALTER", "TYPE", MatchAny, "ALTER", "ATTRIBUTE", MatchAny))
                COMPLETE_WITH("TYPE");
+       /* complete ALTER TYPE <sth> RENAME VALUE with list of enum values */
+       else if (Matches("ALTER", "TYPE", MatchAny, "RENAME", "VALUE"))
+               COMPLETE_WITH_ENUM_VALUE(prev3_wd);
+       /* ALTER TYPE <foo> SET */
+       else if (Matches("ALTER", "TYPE", MatchAny, "SET"))
+               COMPLETE_WITH("(", "SCHEMA");
+       /* complete ALTER TYPE <foo> SET ( with settable properties */
+       else if (Matches("ALTER", "TYPE", MatchAny, "SET", "("))
+               COMPLETE_WITH("ANALYZE", "RECEIVE", "SEND", "STORAGE", "SUBSCRIPT",
+                                         "TYPMOD_IN", "TYPMOD_OUT");
+
        /* complete ALTER GROUP <foo> */
        else if (Matches("ALTER", "GROUP", MatchAny))
                COMPLETE_WITH("ADD USER", "DROP USER", "RENAME TO");
@@ -2526,12 +2537,6 @@ psql_completion(const char *text, int start, int end)
        else if (Matches("ALTER", "GROUP", MatchAny, "ADD|DROP", "USER"))
                COMPLETE_WITH_QUERY(Query_for_list_of_roles);
 
-       /*
-        * If we have ALTER TYPE <sth> RENAME VALUE, provide list of enum values
-        */
-       else if (Matches("ALTER", "TYPE", MatchAny, "RENAME", "VALUE"))
-               COMPLETE_WITH_ENUM_VALUE(prev3_wd);
-
 /*
  * ANALYZE [ ( option [, ...] ) ] [ table_and_columns [, ...] ]
  * ANALYZE [ VERBOSE ] [ table_and_columns [, ...] ]