Improve tab completion of REINDEX in psql

This allows the tab completion of REINDEX to handle an optional
parenthesized list of options.  This case is more complicated than
VACUUM or ANALYZE because of CONCURRENTLY and the different object types
to consider with the reindex.

Author: Justin Pryzby
Reviewed-by: Alexey Kondratov, Michael Paquier
Discussion: https://postgr.es/m/20200403182712.GR14618@telsasoft.com
This commit is contained in:
Michael Paquier 2020-08-11 14:37:38 +09:00
parent 1784f278a6
commit 1f75b45413
1 changed files with 29 additions and 9 deletions

View File

@ -3430,28 +3430,48 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH("DATA");
/* REINDEX */
else if (Matches("REINDEX"))
else if (Matches("REINDEX") ||
Matches("REINDEX", "(*)"))
COMPLETE_WITH("TABLE", "INDEX", "SYSTEM", "SCHEMA", "DATABASE");
else if (Matches("REINDEX", "TABLE"))
else if (Matches("REINDEX", "TABLE") ||
Matches("REINDEX", "(*)", "TABLE"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexables,
" UNION SELECT 'CONCURRENTLY'");
else if (Matches("REINDEX", "INDEX"))
else if (Matches("REINDEX", "INDEX") ||
Matches("REINDEX", "(*)", "INDEX"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes,
" UNION SELECT 'CONCURRENTLY'");
else if (Matches("REINDEX", "SCHEMA"))
else if (Matches("REINDEX", "SCHEMA") ||
Matches("REINDEX", "(*)", "SCHEMA"))
COMPLETE_WITH_QUERY(Query_for_list_of_schemas
" UNION SELECT 'CONCURRENTLY'");
else if (Matches("REINDEX", "SYSTEM|DATABASE"))
else if (Matches("REINDEX", "SYSTEM|DATABASE") ||
Matches("REINDEX", "(*)", "SYSTEM|DATABASE"))
COMPLETE_WITH_QUERY(Query_for_list_of_databases
" UNION SELECT 'CONCURRENTLY'");
else if (Matches("REINDEX", "TABLE", "CONCURRENTLY"))
else if (Matches("REINDEX", "TABLE", "CONCURRENTLY") ||
Matches("REINDEX", "(*)", "TABLE", "CONCURRENTLY"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexables, NULL);
else if (Matches("REINDEX", "INDEX", "CONCURRENTLY"))
else if (Matches("REINDEX", "INDEX", "CONCURRENTLY") ||
Matches("REINDEX", "(*)", "INDEX", "CONCURRENTLY"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes, NULL);
else if (Matches("REINDEX", "SCHEMA", "CONCURRENTLY"))
else if (Matches("REINDEX", "SCHEMA", "CONCURRENTLY") ||
Matches("REINDEX", "(*)", "SCHEMA", "CONCURRENTLY"))
COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
else if (Matches("REINDEX", "SYSTEM|DATABASE", "CONCURRENTLY"))
else if (Matches("REINDEX", "SYSTEM|DATABASE", "CONCURRENTLY") ||
Matches("REINDEX", "(*)", "SYSTEM|DATABASE", "CONCURRENTLY"))
COMPLETE_WITH_QUERY(Query_for_list_of_databases);
else if (HeadMatches("REINDEX", "(*") &&
!HeadMatches("REINDEX", "(*)"))
{
/*
* This fires if we're in an unfinished parenthesized option list.
* get_previous_words treats a completed parenthesized option list as
* one word, so the above test is correct.
*/
if (ends_with(prev_wd, '(') || ends_with(prev_wd, ','))
COMPLETE_WITH("VERBOSE");
}
/* SECURITY LABEL */
else if (Matches("SECURITY"))