On Fri, Nov 23, 2018 at 04:32:31PM -0500, Tom Lane wrote: > Kyotaro HORIGUCHI <horiguchi.kyot...@lab.ntt.co.jp> writes: > > I was reminded that I was often annoyed with identifying the code > > that made a word-completion, by hearing the same complaint from a > > collegue of mine just now. > > Something like the attached that tweaks completion_matches calls > > lets psql emit the line number where a word-completion > > happens. The output can be split out using redirection so that it > > doesn't break into the conversation on console. > > > (make -s COPT=-DTABCOMPLETION_DEBUG install) > > $ psql postgres 2>~debug.out > > =# alt[tab]er [tab]t[tab]ab[tab] [tab] > > > You can see the following output in another bash session. > > $ tail -f ~/debug.out > > [1414][1435][1435][1435][1431] > > Every number enclosed by brackets is the line number in > > tab-complete.c, where completion happens. > > > Is this useful? Any suggestions, thoughts? > > Hm. I can see the value of instrumenting tab-complete when you're trying > to debug why it did something, but this output format seems pretty terse > and unreadable. Can we get it to print the completion text as well? > I'm imagining something more like > > 1414: "er " > 1435: "" > 1435: "ab" > 1435: "" > 1431: "" > > Perhaps there's room as well to print the context that the match looked > at: > > 1414: "alt" -> "er " > 1435: "alter " -> "" > 1435: "alter t" -> "ab" > > etc. > > regards, tom lane
Is this something along the lines of what you had in mind? Best, David. -- David Fetter <david(at)fetter(dot)org> http://fetter.org/ Phone: +1 415 235 3778 Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate
>From 712244a029c0f30fe1195a1400aee85541aa4b6b Mon Sep 17 00:00:00 2001 In-Reply-To: <1227.1543008...@sss.pgh.pa.us> References: <1227.1543008...@sss.pgh.pa.us> From: David Fetter <da...@fetter.org> Date: Fri, 23 Nov 2018 14:55:17 -0800 Subject: [PATCH] v0002 Surface tab completions for debugging To access: make -s COPT=-DTABCOMPLETION_DEBUG --- src/bin/psql/tab-complete.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 9dbd555166..8b81c90d19 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -60,6 +60,32 @@ extern char *filename_completion_function(); #define completion_matches rl_completion_matches #endif +/* + * By enabling the following definition the source line number is emitted to + * stderr for every completion attempt. You can isolate them from console + * interaction by redirecting stderr into a file. + */ +#ifdef TABCOMPLETION_DEBUG +#ifdef HAVE_RL_COMPLETION_MATCHES +#define org_completion_matches rl_completion_matches +#else +#define org_completion_matches completion_matches +#endif + +static char **completion_debug(int line, const char *text, char **list) +{ + fprintf(stderr, "[%d: (%s", line, text); + for (int i = 0; list && list[i]; ++i) + fprintf(stderr, ", %s", list[i]); + fprintf(stderr, ")]\n"); + return list; +} + +#undef completion_matches +#define completion_matches(text, func) \ + completion_debug(__LINE__, (text), org_completion_matches((text),(func))) +#endif + /* word break characters */ #define WORD_BREAKS "\t\n@$><=;|&{() " -- 2.19.1