Several problems in tab-completions for SET/RESET

Lists: pgsql-hackers
From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Several problems in tab-completions for SET/RESET
Date: 2016-01-28 12:32:11
Message-ID: CAHGQGwFoPWQBdn0vMPKqKvSE=EDij1kMNHZ7cq=+2kg2AF1sdg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

I found that the following tab-completions for SET/RESET which
worked properly before doesn't work properly now in the master.

1. ALTER SYSTEM SET|RESET <tab> lists nothing.
2. ALTER DATABASE xxx SET <tab> lists nothing.
3. ALTER DATABASE xxx SET yyy <tab> lists nothing.
4. ALTER DATABASE xxx SET datestyle TO <tab> lists nothing.

Attached patch fixes those problems.

Regards,

--
Fujii Masao

Attachment Content-Type Size
fix_tab_complete_for_set.patch text/x-patch 2.4 KB

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Several problems in tab-completions for SET/RESET
Date: 2016-01-28 13:15:39
Message-ID: CAB7nPqQj=Q7myfuegRFQBjOWh96k9OFvJdgcK+EkimwHNb-VZw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Jan 28, 2016 at 9:32 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
> I found that the following tab-completions for SET/RESET which
> worked properly before doesn't work properly now in the master.
>
> 1. ALTER SYSTEM SET|RESET <tab> lists nothing.
> 2. ALTER DATABASE xxx SET <tab> lists nothing.
> 3. ALTER DATABASE xxx SET yyy <tab> lists nothing.
> 4. ALTER DATABASE xxx SET datestyle TO <tab> lists nothing.
>
> Attached patch fixes those problems.

- else if (Matches4("ALTER", "SYSTEM", "SET|RESET", MatchAny))
+ else if (Matches3("ALTER", "SYSTEM", "SET|RESET"))
Good catch.

- else if (Matches2("SET", MatchAny))
+ else if (TailMatches2("SET", MatchAny) &&
+ !TailMatches4("UPDATE|DOMAIN", MatchAny,
MatchAny, MatchAny) &&
+ !TailMatches1("TABLESPACE|SCHEMA") &&
+ !ends_with(prev_wd, ')') &&
+ !ends_with(prev_wd, '='))
COMPLETE_WITH_CONST("TO");
This gets... unreadable.

In order to maximize the amount of Matches() used, wouldn't it be
better to complete a bit more the list of completions directly in
ALTER DATABASE? This would make the code more readable.
--
Michael


From: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Several problems in tab-completions for SET/RESET
Date: 2016-01-28 13:50:00
Message-ID: CAD21AoDPGH+6RxQoFUwXAnU_CvYWvKV0eA+fxuX+eK5QtbLYag@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Jan 28, 2016 at 10:15 PM, Michael Paquier
<michael(dot)paquier(at)gmail(dot)com> wrote:
> On Thu, Jan 28, 2016 at 9:32 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>> I found that the following tab-completions for SET/RESET which
>> worked properly before doesn't work properly now in the master.
>>
>> 1. ALTER SYSTEM SET|RESET <tab> lists nothing.
>> 2. ALTER DATABASE xxx SET <tab> lists nothing.
>> 3. ALTER DATABASE xxx SET yyy <tab> lists nothing.
>> 4. ALTER DATABASE xxx SET datestyle TO <tab> lists nothing.
>>
>> Attached patch fixes those problems.
>
> - else if (Matches4("ALTER", "SYSTEM", "SET|RESET", MatchAny))
> + else if (Matches3("ALTER", "SYSTEM", "SET|RESET"))
> Good catch.
>
> - else if (Matches2("SET", MatchAny))
> + else if (TailMatches2("SET", MatchAny) &&
> + !TailMatches4("UPDATE|DOMAIN", MatchAny,
> MatchAny, MatchAny) &&
> + !TailMatches1("TABLESPACE|SCHEMA") &&
> + !ends_with(prev_wd, ')') &&
> + !ends_with(prev_wd, '='))
> COMPLETE_WITH_CONST("TO");

This change breaks tab completion for ALTER TABLE ... SET
[WITH/LOGGED/UNLOGGED].

It think it should be
> + else if (Matches2("SET", MatchAny) &&

Related to it, I found tab completion for ALTER TABLE .. SET WITH,
which doesn't working well.
Patch is attached.

Regards,

--
Masahiko Sawada

Attachment Content-Type Size
tab_completion_for_alter_table_set_with.patch text/x-patch 608 bytes

From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Several problems in tab-completions for SET/RESET
Date: 2016-01-29 02:53:51
Message-ID: CAHGQGwHcD9hmW56Yo0-HuKtKaOLchvSa5V6OaiPDPpKxJ48LDw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Jan 28, 2016 at 10:15 PM, Michael Paquier
<michael(dot)paquier(at)gmail(dot)com> wrote:
> On Thu, Jan 28, 2016 at 9:32 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>> I found that the following tab-completions for SET/RESET which
>> worked properly before doesn't work properly now in the master.
>>
>> 1. ALTER SYSTEM SET|RESET <tab> lists nothing.
>> 2. ALTER DATABASE xxx SET <tab> lists nothing.
>> 3. ALTER DATABASE xxx SET yyy <tab> lists nothing.
>> 4. ALTER DATABASE xxx SET datestyle TO <tab> lists nothing.
>>
>> Attached patch fixes those problems.
>
> - else if (Matches4("ALTER", "SYSTEM", "SET|RESET", MatchAny))
> + else if (Matches3("ALTER", "SYSTEM", "SET|RESET"))
> Good catch.
>
> - else if (Matches2("SET", MatchAny))
> + else if (TailMatches2("SET", MatchAny) &&
> + !TailMatches4("UPDATE|DOMAIN", MatchAny,
> MatchAny, MatchAny) &&
> + !TailMatches1("TABLESPACE|SCHEMA") &&
> + !ends_with(prev_wd, ')') &&
> + !ends_with(prev_wd, '='))
> COMPLETE_WITH_CONST("TO");
> This gets... unreadable.
>
> In order to maximize the amount of Matches() used, wouldn't it be
> better to complete a bit more the list of completions directly in
> ALTER DATABASE? This would make the code more readable.

Thanks for the review!

I removed the above and added the following for that case.

+ /* Complete ALTER DATABASE|FUNCTION|ROLE|USER ... SET <name> */
+ else if (Matches2("ALTER", "DATABASE|FUNCTION|ROLE|USER") &&
+ TailMatches2("SET", MatchAny))
+ COMPLETE_WITH_LIST2("FROM CURRENT", "TO");

Attached is the updated version of the patch.
I also added the change that Sawada suggested, to the patch.

Regards,

--
Fujii Masao

Attachment Content-Type Size
fix_tab_complete_for_set_v2.patch text/x-patch 2.9 KB

From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Several problems in tab-completions for SET/RESET
Date: 2016-01-29 02:55:19
Message-ID: CAHGQGwFdBi6iRYJL7gt4qqOY_VgzxYRZ7kFQ+8FUM0n=5K=kig@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Jan 28, 2016 at 10:50 PM, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> wrote:
> On Thu, Jan 28, 2016 at 10:15 PM, Michael Paquier
> <michael(dot)paquier(at)gmail(dot)com> wrote:
>> On Thu, Jan 28, 2016 at 9:32 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>>> I found that the following tab-completions for SET/RESET which
>>> worked properly before doesn't work properly now in the master.
>>>
>>> 1. ALTER SYSTEM SET|RESET <tab> lists nothing.
>>> 2. ALTER DATABASE xxx SET <tab> lists nothing.
>>> 3. ALTER DATABASE xxx SET yyy <tab> lists nothing.
>>> 4. ALTER DATABASE xxx SET datestyle TO <tab> lists nothing.
>>>
>>> Attached patch fixes those problems.
>>
>> - else if (Matches4("ALTER", "SYSTEM", "SET|RESET", MatchAny))
>> + else if (Matches3("ALTER", "SYSTEM", "SET|RESET"))
>> Good catch.
>>
>> - else if (Matches2("SET", MatchAny))
>> + else if (TailMatches2("SET", MatchAny) &&
>> + !TailMatches4("UPDATE|DOMAIN", MatchAny,
>> MatchAny, MatchAny) &&
>> + !TailMatches1("TABLESPACE|SCHEMA") &&
>> + !ends_with(prev_wd, ')') &&
>> + !ends_with(prev_wd, '='))
>> COMPLETE_WITH_CONST("TO");
>
> This change breaks tab completion for ALTER TABLE ... SET
> [WITH/LOGGED/UNLOGGED].

Thanks for the review!
Fixed.

> It think it should be
>> + else if (Matches2("SET", MatchAny) &&
>
> Related to it, I found tab completion for ALTER TABLE .. SET WITH,
> which doesn't working well.
> Patch is attached.

Please see the latest patch that I posted upthread.
I included your patch in that patch.

Regards,

--
Fujii Masao


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Several problems in tab-completions for SET/RESET
Date: 2016-01-29 04:02:20
Message-ID: CAB7nPqRHRGNv9N9r6R2xCCjY5kcDSpap41FTBErSpWcOv7HKtw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Jan 29, 2016 at 11:53 AM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
> I removed the above and added the following for that case.
>
> + /* Complete ALTER DATABASE|FUNCTION|ROLE|USER ... SET <name> */
> + else if (Matches2("ALTER", "DATABASE|FUNCTION|ROLE|USER") &&
> + TailMatches2("SET", MatchAny))
> + COMPLETE_WITH_LIST2("FROM CURRENT", "TO");
>
> Attached is the updated version of the patch.

"ALTER FUNCTION foo(bar)" suggests OWNER TO, RENAME TO and SET SCHEMA.
I think that we had better suggesting SET instead of SET SCHEMA, and
add SCHEMA in the list of things suggested by SET.

"ALTER DATABASE foodb SET foo_param" should suggest TO/= but that's
not the case. After adding TO/= manually, a list of values is
suggested though. Same problem with ALTER ROLE and ALTER FUNCTION.

> I also added the change that Sawada suggested, to the patch.

OK.
--
Michael


From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Several problems in tab-completions for SET/RESET
Date: 2016-02-01 04:21:54
Message-ID: CAHGQGwFNKk_RBajobAr2UjEWSFi8JFEmtmatWn6O38vN==_uVA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Jan 29, 2016 at 1:02 PM, Michael Paquier
<michael(dot)paquier(at)gmail(dot)com> wrote:
> On Fri, Jan 29, 2016 at 11:53 AM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>> I removed the above and added the following for that case.
>>
>> + /* Complete ALTER DATABASE|FUNCTION|ROLE|USER ... SET <name> */
>> + else if (Matches2("ALTER", "DATABASE|FUNCTION|ROLE|USER") &&
>> + TailMatches2("SET", MatchAny))
>> + COMPLETE_WITH_LIST2("FROM CURRENT", "TO");
>>
>> Attached is the updated version of the patch.

Thanks for the review!

> "ALTER FUNCTION foo(bar)" suggests OWNER TO, RENAME TO and SET SCHEMA.
> I think that we had better suggesting SET instead of SET SCHEMA, and
> add SCHEMA in the list of things suggested by SET.

Maybe, and it should suggest other keywords like RESET. That's it's better to
overhaul the tab-completion of ALTER FUNCTION. But that's not the task of
this patch. IMO it's better to fix that as a separate patch.

> "ALTER DATABASE foodb SET foo_param" should suggest TO/= but that's
> not the case. After adding TO/= manually, a list of values is
> suggested though. Same problem with ALTER ROLE and ALTER FUNCTION.

Fixed. Attached is the updated version of the patch.

Regards,

--
Fujii Masao

Attachment Content-Type Size
fix_tab_complete_for_set_v3.patch text/x-patch 2.9 KB

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Several problems in tab-completions for SET/RESET
Date: 2016-02-01 06:14:44
Message-ID: CAB7nPqQm4CAGznvsv45GyKcMfp+yiJu8E_gR9DmMOy-LFCDWSg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Feb 1, 2016 at 1:21 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
> On Fri, Jan 29, 2016 at 1:02 PM, Michael Paquier
> <michael(dot)paquier(at)gmail(dot)com> wrote:
>> On Fri, Jan 29, 2016 at 11:53 AM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>>> I removed the above and added the following for that case.
>>>
>>> + /* Complete ALTER DATABASE|FUNCTION|ROLE|USER ... SET <name> */
>>> + else if (Matches2("ALTER", "DATABASE|FUNCTION|ROLE|USER") &&
>>> + TailMatches2("SET", MatchAny))
>>> + COMPLETE_WITH_LIST2("FROM CURRENT", "TO");
>>>
>>> Attached is the updated version of the patch.
>
> Thanks for the review!
>
>> "ALTER FUNCTION foo(bar)" suggests OWNER TO, RENAME TO and SET SCHEMA.
>> I think that we had better suggesting SET instead of SET SCHEMA, and
>> add SCHEMA in the list of things suggested by SET.
>
> Maybe, and it should suggest other keywords like RESET. That's it's better to
> overhaul the tab-completion of ALTER FUNCTION. But that's not the task of
> this patch. IMO it's better to fix that as a separate patch.

Er, OK... I thought that both problems seem rather linked per the
$subject but I can send an extra patch on this thread if necessary.
Never mind.

>> "ALTER DATABASE foodb SET foo_param" should suggest TO/= but that's
>> not the case. After adding TO/= manually, a list of values is
>> suggested though. Same problem with ALTER ROLE and ALTER FUNCTION.
>
> Fixed. Attached is the updated version of the patch.

+ /* Complete ALTER DATABASE|FUNCTION|ROLE|USER ... SET <name> */
+ else if (HeadMatches2("ALTER", "DATABASE|FUNCTION|ROLE|USER") &&
+ TailMatches2("SET", MatchAny))
+ COMPLETE_WITH_LIST2("FROM CURRENT", "TO");
Small thing: adding "=" to the list of things that can be completed?

Except that the rest looks fine to me.
--
Michael


From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Several problems in tab-completions for SET/RESET
Date: 2016-02-01 12:15:20
Message-ID: CAHGQGwFo--wp9NQMxd53uaaUkEkvzJ9RBRa81yAjH+HfSMb1wg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Feb 1, 2016 at 3:14 PM, Michael Paquier
<michael(dot)paquier(at)gmail(dot)com> wrote:
> On Mon, Feb 1, 2016 at 1:21 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>> On Fri, Jan 29, 2016 at 1:02 PM, Michael Paquier
>> <michael(dot)paquier(at)gmail(dot)com> wrote:
>>> On Fri, Jan 29, 2016 at 11:53 AM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>>>> I removed the above and added the following for that case.
>>>>
>>>> + /* Complete ALTER DATABASE|FUNCTION|ROLE|USER ... SET <name> */
>>>> + else if (Matches2("ALTER", "DATABASE|FUNCTION|ROLE|USER") &&
>>>> + TailMatches2("SET", MatchAny))
>>>> + COMPLETE_WITH_LIST2("FROM CURRENT", "TO");
>>>>
>>>> Attached is the updated version of the patch.
>>
>> Thanks for the review!
>>
>>> "ALTER FUNCTION foo(bar)" suggests OWNER TO, RENAME TO and SET SCHEMA.
>>> I think that we had better suggesting SET instead of SET SCHEMA, and
>>> add SCHEMA in the list of things suggested by SET.
>>
>> Maybe, and it should suggest other keywords like RESET. That's it's better to
>> overhaul the tab-completion of ALTER FUNCTION. But that's not the task of
>> this patch. IMO it's better to fix that as a separate patch.
>
> Er, OK... I thought that both problems seem rather linked per the
> $subject but I can send an extra patch on this thread if necessary.
> Never mind.
>
>>> "ALTER DATABASE foodb SET foo_param" should suggest TO/= but that's
>>> not the case. After adding TO/= manually, a list of values is
>>> suggested though. Same problem with ALTER ROLE and ALTER FUNCTION.
>>
>> Fixed. Attached is the updated version of the patch.
>
> + /* Complete ALTER DATABASE|FUNCTION|ROLE|USER ... SET <name> */
> + else if (HeadMatches2("ALTER", "DATABASE|FUNCTION|ROLE|USER") &&
> + TailMatches2("SET", MatchAny))
> + COMPLETE_WITH_LIST2("FROM CURRENT", "TO");
> Small thing: adding "=" to the list of things that can be completed?

If we do that, we also should change the tab-completion for SET command
so that "=" is suggested. But I'm afraid that which might decrease that
tab-completion.

Imagine the case of "SET work_mem <tab>". If "TO" and "=" are suggested,
we need to type either "T" or "=" and then <tab> to input the setting value.
Otherwise, "SET work_mem <tab>" suggests only "TO" and we can input
the setting value by just typing <tab> again.
This extra step is very small, but SET command is usually used very often,
so I'd like to avoid such extra step.

Regards,

--
Fujii Masao


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Several problems in tab-completions for SET/RESET
Date: 2016-02-01 12:23:38
Message-ID: CAB7nPqT-E3+q4OHtgqZPLJmvfy4hBibotcnHVPAa9NpnO8Ca2A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Feb 1, 2016 at 9:15 PM, Fujii Masao wrote:
> If we do that, we also should change the tab-completion for SET command
> so that "=" is suggested. But I'm afraid that which might decrease that
> tab-completion.
>
> Imagine the case of "SET work_mem <tab>". If "TO" and "=" are suggested,
> we need to type either "T" or "=" and then <tab> to input the setting value.
> Otherwise, "SET work_mem <tab>" suggests only "TO" and we can input
> the setting value by just typing <tab> again.
> This extra step is very small, but SET command is usually used very often,
> so I'd like to avoid such extra step.

OK, that's fine.
--
Michael


From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Several problems in tab-completions for SET/RESET
Date: 2016-02-01 13:22:31
Message-ID: CAHGQGwGANT0dt_UE+vjco_fE3wQL6AhKOtLaTxVyt8K9jkuqVA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Feb 1, 2016 at 9:23 PM, Michael Paquier
<michael(dot)paquier(at)gmail(dot)com> wrote:
> On Mon, Feb 1, 2016 at 9:15 PM, Fujii Masao wrote:
>> If we do that, we also should change the tab-completion for SET command
>> so that "=" is suggested. But I'm afraid that which might decrease that
>> tab-completion.
>>
>> Imagine the case of "SET work_mem <tab>". If "TO" and "=" are suggested,
>> we need to type either "T" or "=" and then <tab> to input the setting value.
>> Otherwise, "SET work_mem <tab>" suggests only "TO" and we can input
>> the setting value by just typing <tab> again.
>> This extra step is very small, but SET command is usually used very often,
>> so I'd like to avoid such extra step.
>
> OK, that's fine.

Pushed. Thanks!

Regards,

--
Fujii Masao


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Several problems in tab-completions for SET/RESET
Date: 2016-02-02 03:01:36
Message-ID: CAB7nPqTP9JA7qvsUgoKCB5UWaEsW5PJRkfNobbQxcTa4b2=sYA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Feb 1, 2016 at 10:22 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:

> Pushed. Thanks!
>

OK. And attached is the promised patch for ALTER FUNCTION.
--
Michael

Attachment Content-Type Size
psql-tab-alter-func.patch text/x-diff 1.8 KB