pgsql: Teach psql's tab completion to consider the entire input string.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Teach psql's tab completion to consider the entire input string.
Date: 2015-12-20 18:28:34
Message-ID: E1aAiig-0007at-2k@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Teach psql's tab completion to consider the entire input string.

Up to now, the tab completion logic has only examined the last few words
of the current input line; "last few" being originally as few as four
words, but lately up to nine words. Furthermore, it only looked at what
libreadline considers the current line of input, which made it rather
myopic if you split your command across lines. This was tolerable,
sort of, so long as the match patterns were only designed to consider the
last few words of input; but with the recent addition of HeadMatches()
and Matches() matching rules, we really have to do better if we want
those to behave sanely.

Hence, change the code to break the entire line down into words, and to
include any previous lines in the command buffer along with the active
readline input buffer.

This will be a little bit slower than the previous coding, but some
measurements say that even a query of several thousand characters can be
parsed in a hundred or so microseconds on modern machines; so it's really
not going to be significant for interactive tab completion. To reduce
the cost some, I arranged to avoid the per-word malloc calls that used
to occur: all the words are now kept in one malloc'd buffer.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/d854118c8df8c413d069f7e88bb01b9e18e4c8ed

Modified Files
--------------
src/bin/psql/input.c | 13 ++-
src/bin/psql/input.h | 14 +--
src/bin/psql/mainloop.c | 2 +-
src/bin/psql/tab-complete.c | 208 ++++++++++++++++++++++++++-----------------
src/bin/psql/tab-complete.h | 8 +-
5 files changed, 150 insertions(+), 95 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2015-12-20 23:30:14 pgsql: Remove silly completion for "DELETE FROM tabname ...".
Previous Message Peter Eisentraut 2015-12-20 17:19:04 pgsql: psql: Review of new help output strings