Commit 1f75b454 authored by Michael Paquier's avatar Michael Paquier

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
parent 1784f278
...@@ -3430,28 +3430,48 @@ psql_completion(const char *text, int start, int end) ...@@ -3430,28 +3430,48 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH("DATA"); COMPLETE_WITH("DATA");
/* REINDEX */ /* REINDEX */
else if (Matches("REINDEX")) else if (Matches("REINDEX") ||
Matches("REINDEX", "(*)"))
COMPLETE_WITH("TABLE", "INDEX", "SYSTEM", "SCHEMA", "DATABASE"); 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, COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexables,
" UNION SELECT 'CONCURRENTLY'"); " 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, COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes,
" UNION SELECT 'CONCURRENTLY'"); " UNION SELECT 'CONCURRENTLY'");
else if (Matches("REINDEX", "SCHEMA")) else if (Matches("REINDEX", "SCHEMA") ||
Matches("REINDEX", "(*)", "SCHEMA"))
COMPLETE_WITH_QUERY(Query_for_list_of_schemas COMPLETE_WITH_QUERY(Query_for_list_of_schemas
" UNION SELECT 'CONCURRENTLY'"); " 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 COMPLETE_WITH_QUERY(Query_for_list_of_databases
" UNION SELECT 'CONCURRENTLY'"); " 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); 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); 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); 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); 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 */ /* SECURITY LABEL */
else if (Matches("SECURITY")) else if (Matches("SECURITY"))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment