Re: Support tab completion for upper character inputs in psql - Mailing list pgsql-hackers

From Dagfinn Ilmari Mannsåker
Subject Re: Support tab completion for upper character inputs in psql
Date
Msg-id 87wniezq0u.fsf@wibble.ilmari.org
Whole thread Raw
In response to Re: Support tab completion for upper character inputs in psql  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Support tab completion for upper character inputs in psql  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Support tab completion for upper character inputs in psql  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Tom Lane <tgl@sss.pgh.pa.us> writes:

> I wrote:
>> =?utf-8?Q?Dagfinn_Ilmari_Manns=C3=A5ker?= <ilmari@ilmari.org> writes:
>>> First, as noted in the test, it doesn't preserve the case of the input
>>> for keywords appended to the query result.  This is easily fixed by
>>> using `pg_strdup_keyword_case()`, per the first attached patch.
>
>> I thought about that, and intentionally didn't do it, because it
>> would also affect the menus produced by tab completion.
>> ...
>> We could do something hacky like matching case only when there's
>> no longer any matching object names, but that might be too magic.
>
> I experimented with that, and it actually doesn't seem as weird
> as I feared.  See if you like this ...

That's a reasonable compromise, and the implementation is indeed less
hacky than one might have feared.  Although I think putting the
`num_keywords` variable before `num_other` would read better.

Going through the uses of COMPLETE_WITH(_SCHEMA)_QUERY_PLUS, I noticed a
few that had the keywords in lower case, which is fixed in the attached
patch (except the hardcoded data types, which aren't really keywords).
While I was there, I also added completion of "AUTHORIZATION" after
"SHOW SESSSION", which is necessary since there are variables starting
with "session_".

>             regards, tom lane

Cheers,
- ilmari

From 9cc255e0cdddeda3d655c1265d698b1f6027aec6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org>
Date: Tue, 1 Feb 2022 13:13:07 +0000
Subject: [PATCH] Make all tab completion keywords upper case.

So they stand out from the object names in the same tab completion
menu.

Also fix tab completion of SHOW SESSION AUTHORIZATION in the face of
config variables starting with session_.
---
 src/bin/psql/tab-complete.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index b2ec50b4f2..d2744cdb6f 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -2059,7 +2059,7 @@ psql_completion(const char *text, int start, int end)
         COMPLETE_WITH("SET", "RESET");
     else if (Matches("ALTER", "SYSTEM", "SET|RESET"))
         COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_alter_system_set_vars,
-                                 "all");
+                                 "ALL");
     else if (Matches("ALTER", "SYSTEM", "SET", MatchAny))
         COMPLETE_WITH("TO");
     /* ALTER VIEW <name> */
@@ -4039,16 +4039,18 @@ psql_completion(const char *text, int start, int end)
     /* Complete with a variable name */
     else if (TailMatches("SET|RESET") && !TailMatches("UPDATE", MatchAny, "SET"))
         COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_set_vars,
-                                 "constraints",
-                                 "transaction",
-                                 "session",
-                                 "role",
-                                 "tablespace",
-                                 "all");
+                                 "CONSTRAINTS",
+                                 "TRANSACTION",
+                                 "SESSION",
+                                 "ROLE",
+                                 "TABLESPACE",
+                                 "ALL");
     else if (Matches("SHOW"))
         COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_show_vars,
-                                 "session authorization",
-                                 "all");
+                                 "SESSION AUTHORIZATION",
+                                 "ALL");
+    else if (Matches("SHOW", "SESSION"))
+        COMPLETE_WITH("AUTHORIZATION");
     /* Complete "SET TRANSACTION" */
     else if (Matches("SET", "TRANSACTION"))
         COMPLETE_WITH("SNAPSHOT", "ISOLATION LEVEL", "READ", "DEFERRABLE", "NOT DEFERRABLE");
-- 
2.30.2


pgsql-hackers by date:

Previous
From: Bharath Rupireddy
Date:
Subject: Re: Add checkpoint and redo LSN to LogCheckpointEnd log message
Next
From: gkokolatos@pm.me
Date:
Subject: Plug minor memleak in pg_dump