Issue730

Title tab completion
Priority wish Status chatting
Superseder Nosy List davidspeck, florian, jendrik, malte
Assigned To Keywords
Optional summary

Created on 2017-05-18.14:09:34 by malte, last changed by florian.

Messages
msg11690 (view) Author: florian Date: 2024-09-13.12:31:22
We are still fighting several bugs related to tab completion. For some of them, we narrowed down the problem to an issue with argcomplete and mad a bug report there. Here is a summary:

1) "./fast-downward.py $DOWNWARD_BENCHMARKS/<tab>" will not generate any suggestions on zsh.
The reason is that we use the argcomplete FilesCompleter here which in turn forwards the call to bash. This call fails for a reason we could not identify. The completion works in bash but this is not due to the FilesCompleter working there but because the crash leading to a fall-back in bash which happens to complete file names.

Related bug report: https://github.com/kislyuk/argcomplete/issues/502
SO question: https://stackoverflow.com/q/78978949/892961

2) "./fast-downward.py ~/<tab>" replaces "~/" with "\~/" on zsh.
The reason here is that paths starting with ~ are generated as suggestions and then handed off to the zsh function "_describe" which should display them to the user. On that level, the suggestions are escaped, so for example spaces in paths are correctly escaped. There are options to _describe that prevent escaping for a specific prefix but place in the code where _describe is called is a general part of argcomplete. First of all, we cannot modify this code and second, the code doesn't know which arguments are paths and which prefix they use.

Related bug report: https://github.com/kislyuk/argcomplete/issues/503

3) "python3 ./fast-downward.py x y --translate-options <tab>" generates all suggestions twice on zsh (not sure about bash).
This might be related to some preprocessing that zsh does. The completion is done twice, once for "python3 ./fast-downward.py" and once for "./fast-downward.py". It is not clear if the problem lies with argcomplete, zsh, or some combination of it.

Related bug report: https://github.com/kislyuk/argcomplete/issues/505

4) "python3 fast-downward.py /e<TAB>" makes "/e" disappear
This is related to point 3) above and has something to do with the fact that argcomplete tries to detect if the completion uses python in the call, or calls the script directly. The call uses Python, but this is not recognized correctly, so it tries to detect if the called script is a Python script. Since the script is given as "fast-downward.py" not "./fast-downward.py" and the current working directory is not on the PATH, this also fails and no suggestions are generated.

Related bug report: https://github.com/kislyuk/argcomplete/issues/504

5) "./fast-downward.py x y --internal-plan-file <tab>" produces no suggestions
Here, we explicitly exit the search component with an exit code of 1 to fall back to the default behavior of generating file names. But this is not consistently supported by argcomplete. It looks like we have no good way to distinguish "please display no suggestions" from "please use the default completer at this point". We can configure one of the choices but not use one for some situations and the other for other situations. Cases where it looks like this is working at the moment are actually caused by other bugs.


For me, the problems in 1) and 2) are annoying enough that the offset any benefit from the completion in other contexts, so I would not activate tab completion as long as those issues are there. The question is how we want to proceed now and what we should do with the code changes in the pull request. It would be sad to lose them but at the same time, they don't seem ready to merge and it is not clear how we can get them ready.
msg11684 (view) Author: florian Date: 2024-07-31.11:42:11
For what it's worth: I submitted a bug report to the Ubuntu package maintainers to let them know about the version incompatibility. In time, hopefully this will get fixed by increasing the version in the package.
https://bugs.launchpad.net/ubuntu/+source/python-argcomplete/+bug/2075315
msg11660 (view) Author: florian Date: 2024-07-20.10:21:45
And here is the commit that removes the default suggestions on zsh
(the code before this version was always suggesting filenames, even
in cases where we explicitly report that there is only one possible
completion). It is included in release 3.2.

https://github.com/kislyuk/argcomplete/commit/cb5fc3863b7ed6feeed126ca2b9464ed2018e9a1#diff-befd6cede7c58a607b529775f336dcf436da76a6c725097110127ecaa62294b5L144
msg11659 (view) Author: florian Date: 2024-07-20.10:16:52
For future reference, here is the commit that fixes compatibility with Python 3.11.9+, 3.12.3+, 3.13+. It is included in release 3.3 of argcomplete but not in 3.1. Unfortunately, 3.1 is the default installation via apt in Ubuntu 24.04 which comes with Python 3.12.3:
https://github.com/kislyuk/argcomplete/commit/54a4846b3a774cd9037167898f3cce38ba9d58e8
msg11651 (view) Author: davidspeck Date: 2024-07-19.11:55:36
We have implemented tab completion based on argcomplete. It is fully functional for the build.py, 
translate.py and the driver options of fast-downward.py. For the search options, we have implemented tab 
completion for the search binary directly, which is called, and the suggestions are forwarded.

The search binary implements correct case distinction and returns the correct suggestions except for the 
search configuration. We do not provide recommendations for the search configuration at the moment because 
it is a larger project in itself, requiring us to modify the parser to work with partial strings.

Instructions for setting up tab completion for the different components are added to a new file called 
TABCOMPLETION.md.

Pull request: https://github.com/aibasel/downward/pull/226

Argcomplete can be installed via apt and pip. The installation via apt gives version 1.8 on Ubuntu 22.04 
and version 3.1 on Ubuntu 24.04. Both of these version can cause different problems such that some aspect 
of the tab completion does not work fully. In particular, version 3.1 is incompatible with python 3.12 
which is the default on Ubuntu 24.04. Version 1.8 on Ubuntu 22.04 is not new enough such that we can 
forward translator options to the driver.

Argcomplete supports local and global activation for tab completion. We opt to recommend local activation 
because it is less intrusive and we encountered an issue with global activation in zsh: file names where 
always suggested in addition to the desired options.
msg9185 (view) Author: malte Date: 2020-01-30.19:59:32
Thanks for the pointer! For what it's worth, I didn't find implementing the tab completion difficult at all for the repo tool, but that of course doesn't mean we shouldn't consider alternatives.
msg9184 (view) Author: jendrik Date: 2020-01-30.19:01:11
I just stumbled over https://argcomplete.readthedocs.io, which we could use at least for the Python options.
msg6371 (view) Author: malte Date: 2017-05-18.14:09:34
It would be nice to have tab completion for the planner. This can be considered
separately for the driver script and the search component.

I have some experience with implementing tab completion for our repo tool, so if
someone is interested in handling this but would like some advice, I'm happy to
provide it.
History
Date User Action Args
2024-09-13 12:31:22floriansetmessages: + msg11690
2024-07-31 11:42:11floriansetmessages: + msg11684
2024-07-20 10:21:45floriansetmessages: + msg11660
2024-07-20 10:16:52floriansetnosy: + florian
messages: + msg11659
2024-07-19 11:55:36davidspecksetnosy: + davidspeck
messages: + msg11651
2020-01-30 19:59:32maltesetmessages: + msg9185
2020-01-30 19:01:12jendriksetnosy: + jendrik
messages: + msg9184
2017-05-18 14:09:34maltecreate