2021年2月13日(土) 11:52 Michael Paquier <mich...@paquier.xyz>:

> On Fri, Feb 12, 2021 at 10:32:14AM +0900, Ian Lawrence Barwick wrote:
> > In the documentation, the "[ NO ]" option is listed in the synopsis for
> > ALTER TRIGGER and ALTER FUNCTION, but not the others.
> > Trivial patch attached.
>
> There are two flavors to cover for 6 commands per gram.y, and you are
> covering all of them.  So this looks good to me.  I'll apply and
> backpatch in a bit.


Thanks! (Apologies for the preceding blank mail).

It is worth noting that tab-complete.c does a bad
> job in completing those clauses.
>

Indeed it does. Not the most exciting of use cases, though I imagine it
might come in handy for anyone developing an extension, and the
existing implementation is inconsistent (in place for ALTER INDEX,
and partially for ALTER MATERIALIZED VIEW, but not the others).
Patch suggestion attached.

Regards

Ian Barwick


-- 
EnterpriseDB: https://www.enterprisedb.com
commit 5ffe7228c6789cbf29084daae6aa8f4638996a98
Author: Ian Barwick <i...@2ndquadrant.com>
Date:   Mon Feb 15 15:27:25 2021 +0900

    psql: improve [ NO ] DEPENDS tab completion support

diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 1e1c315bae..f99564937d 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -1614,14 +1614,24 @@ psql_completion(const char *text, int start, int end)
 	/* ALTER AGGREGATE,FUNCTION,PROCEDURE,ROUTINE <name> */
 	else if (Matches("ALTER", "AGGREGATE|FUNCTION|PROCEDURE|ROUTINE", MatchAny))
 		COMPLETE_WITH("(");
-	/* ALTER AGGREGATE,FUNCTION,PROCEDURE,ROUTINE <name> (...) */
-	else if (Matches("ALTER", "AGGREGATE|FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny))
+	/* ALTER AGGREGATE <name> (...) */
+	else if (Matches("ALTER", "AGGREGATE", MatchAny, MatchAny))
 	{
 		if (ends_with(prev_wd, ')'))
 			COMPLETE_WITH("OWNER TO", "RENAME TO", "SET SCHEMA");
 		else
 			COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
 	}
+	/* ALTER FUNCTION,PROCEDURE,ROUTINE <name> (...) */
+	else if (Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny))
+	{
+		if (ends_with(prev_wd, ')'))
+			COMPLETE_WITH("OWNER TO", "RENAME TO", "SET SCHEMA",
+						  "DEPENDS ON EXTENSION", "NO DEPENDS ON EXTENSION");
+		else
+			COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
+	}
+
 	/* ALTER PUBLICATION <name> */
 	else if (Matches("ALTER", "PUBLICATION", MatchAny))
 		COMPLETE_WITH("ADD TABLE", "DROP TABLE", "OWNER TO", "RENAME TO", "SET");
@@ -1735,7 +1745,8 @@ psql_completion(const char *text, int start, int end)
 	/* ALTER INDEX <name> */
 	else if (Matches("ALTER", "INDEX", MatchAny))
 		COMPLETE_WITH("ALTER COLUMN", "OWNER TO", "RENAME TO", "SET",
-					  "RESET", "ATTACH PARTITION", "DEPENDS", "NO DEPENDS",
+					  "RESET", "ATTACH PARTITION",
+					  "DEPENDS ON EXTENSION", "NO DEPENDS ON EXTENSION",
 					  "ALTER COLLATION");
 	else if (Matches("ALTER", "INDEX", MatchAny, "ATTACH"))
 		COMPLETE_WITH("PARTITION");
@@ -1782,10 +1793,6 @@ psql_completion(const char *text, int start, int end)
 					  "buffering =",	/* GiST */
 					  "pages_per_range =", "autosummarize ="	/* BRIN */
 			);
-	else if (Matches("ALTER", "INDEX", MatchAny, "NO", "DEPENDS"))
-		COMPLETE_WITH("ON EXTENSION");
-	else if (Matches("ALTER", "INDEX", MatchAny, "DEPENDS"))
-		COMPLETE_WITH("ON EXTENSION");
 	/* ALTER INDEX <name> ALTER COLLATION */
 	else if (Matches("ALTER", "INDEX", MatchAny, "ALTER", "COLLATION"))
 	{
@@ -1919,7 +1926,7 @@ psql_completion(const char *text, int start, int end)
 
 	/* ALTER MATERIALIZED VIEW <name> */
 	else if (Matches("ALTER", "MATERIALIZED", "VIEW", MatchAny))
-		COMPLETE_WITH("ALTER COLUMN", "CLUSTER ON", "DEPENDS ON EXTENSION",
+		COMPLETE_WITH("ALTER COLUMN", "CLUSTER ON", "DEPENDS ON EXTENSION", "NO DEPENDS ON EXTENSION",
 					  "OWNER TO", "RENAME", "RESET (", "SET");
 	/* ALTER MATERIALIZED VIEW xxx RENAME */
 	else if (Matches("ALTER", "MATERIALIZED", "VIEW", MatchAny, "RENAME"))
@@ -1997,7 +2004,7 @@ psql_completion(const char *text, int start, int end)
 
 	/* ALTER TRIGGER <name> ON <name> */
 	else if (Matches("ALTER", "TRIGGER", MatchAny, "ON", MatchAny))
-		COMPLETE_WITH("RENAME TO");
+		COMPLETE_WITH("RENAME TO", "DEPENDS ON EXTENSION", "NO DEPENDS ON EXTENSION");
 
 	/*
 	 * If we detect ALTER TABLE <name>, suggest sub commands

Reply via email to