Improve tab completion for USER MAPPING

Started by Masahiko Sawadaover 9 years ago2 messages
#1Masahiko Sawada
sawada.mshk@gmail.com
1 attachment(s)

Hi all,

I found that the tab completion for USER MAPPING doesn't work fine.
For example,

The below is no problem.
postgres=# create user[TAB]
user user mapping for

But this doesn't work fine. (Note that there is a white space between
'user' and [TAB])
postgres=# create user [TAB]
hoge_user masahiko pg_signal_backend

After manual input of the 'mapping', 'for' is added by tab completion.
It means that the tab completion for 'mapping' is not working.

Patch attached.
Please review it.

Regards,

--
Masahiko Sawada

Attachments:

fix_tab_completion_for_user_mapping.patchapplication/octet-stream; name=fix_tab_completion_for_user_mapping.patchDownload
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index a62ffe6..f8b1dbc 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -921,8 +921,7 @@ static const pgsql_thing_t words_after_create[] = {
 	{"UNIQUE", NULL, NULL, THING_NO_DROP},		/* for CREATE UNIQUE INDEX ... */
 	{"UNLOGGED", NULL, NULL, THING_NO_DROP},	/* for CREATE UNLOGGED TABLE
 												 * ... */
-	{"USER", Query_for_list_of_roles},
-	{"USER MAPPING FOR", NULL, NULL},
+	{"USER", Query_for_list_of_roles "UNION ALL SELECT 'MAPPING FOR'"},
 	{"VIEW", NULL, &Query_for_list_of_views},
 	{NULL}						/* end of list */
 };
@@ -1355,7 +1354,7 @@ psql_completion(const char *text, int start, int end)
 			"GROUP", "INDEX", "LANGUAGE", "LARGE OBJECT", "MATERIALIZED VIEW", "OPERATOR",
 			"POLICY", "ROLE", "RULE", "SCHEMA", "SERVER", "SEQUENCE", "SYSTEM", "TABLE",
 			"TABLESPACE", "TEXT SEARCH", "TRIGGER", "TYPE",
-		"USER", "USER MAPPING FOR", "VIEW", NULL};
+		"USER", "VIEW", NULL};
 
 		COMPLETE_WITH_LIST(list_ALTER);
 	}
#2Kyotaro HORIGUCHI
horiguchi.kyotaro@lab.ntt.co.jp
In reply to: Masahiko Sawada (#1)
Re: Improve tab completion for USER MAPPING

Hi,

At Tue, 7 Jun 2016 00:03:57 +0900, Masahiko Sawada <sawada.mshk@gmail.com> wrote in <CAD21AoA-1eT4Oi4mkMiPsrA=UOCbUFj1AoHT1avUQHqkyXkFEg@mail.gmail.com>

I found that the tab completion for USER MAPPING doesn't work fine.
For example,

The below is no problem.
postgres=# create user[TAB]
user user mapping for

But this doesn't work fine. (Note that there is a white space between
'user' and [TAB])
postgres=# create user [TAB]
hoge_user masahiko pg_signal_backend

After manual input of the 'mapping', 'for' is added by tab completion.
It means that the tab completion for 'mapping' is not working.

Adding non-object in words_after_create is somewhat uneasy but it
will work. One problem with it is that the case of keywords shown
among object names don't comply with COMP_KEYWORD_CASE.

=# \set COMP_KEYWORD_CASE preserve-lower // default.
=# create user m<tab>
=# create user MAPPING FOR

I'm trying to fix this as a part of the following CF entry (now
it seems to have a bug leads to a crash, though..)

https://commitfest.postgresql.org/10/518/

regards,

--
Kyotaro Horiguchi
NTT Open Source Software Center

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers