From 78636e41582eae4f46880d4a0469ed3832163ac5 Mon Sep 17 00:00:00 2001 From: tanghy Date: Fri, 3 Sep 2021 13:17:46 +0900 Subject: [PATCH v2] support tab-completion for single quote input with equal sign --- src/bin/psql/t/010_tab_completion.pl | 8 ++++++++ src/bin/psql/tab-complete.c | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/bin/psql/t/010_tab_completion.pl b/src/bin/psql/t/010_tab_completion.pl index 8695d22545..cfebb654d8 100644 --- a/src/bin/psql/t/010_tab_completion.pl +++ b/src/bin/psql/t/010_tab_completion.pl @@ -194,6 +194,14 @@ check_completion( clear_query(); +# check tab-completion after single quoted text input with equal sign. +check_completion( + "CREATE SUBSCRIPTION my_sub CONNECTION 'host=localhost port=5432 dbname=postgres' \t", + qr|PUBLICATION|, + "tab-completion after single quoted text input with equal sign"); + +clear_query(); + # COPY requires quoting # note: broken versions of libedit want to backslash the closing quote; # not much we can do about that diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 75b867685a..b9373e4712 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -5044,6 +5044,7 @@ get_previous_words(int point, char **buffer, int *nwords) int start, end; bool inquotes = false; + bool in_single_quote = false; int parentheses = 0; /* now find the first non-space which then constitutes the end */ @@ -5072,6 +5073,8 @@ get_previous_words(int point, char **buffer, int *nwords) inquotes = !inquotes; if (!inquotes) { + if (buf[start] == '\'') + in_single_quote = !in_single_quote; if (buf[start] == ')') parentheses++; else if (buf[start] == '(') @@ -5080,6 +5083,7 @@ get_previous_words(int point, char **buffer, int *nwords) break; } else if (parentheses == 0 && + !in_single_quote && strchr(WORD_BREAKS, buf[start - 1])) break; } -- 2.31.1.windows.1