Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tab completion for "~" does not work #28

Closed
nikitalita opened this issue Dec 3, 2020 · 8 comments
Closed

Tab completion for "~" does not work #28

nikitalita opened this issue Dec 3, 2020 · 8 comments
Labels
bug Something isn't working

Comments

@nikitalita
Copy link
Contributor

nikitalita commented Dec 3, 2020

On the current 1.1.4 release and on the current master, tab completion for "~" is not working. Tested in both Cmder and vanilla, and on a clean VM.

I had tried to debug this to figure out what was happening, but LOG() and ERR() were not outputting any messages in the logs when I put them in rl_module.cpp, and I have no idea how to set this up in a debugger since it's a program that injects a dll into a running process. Just out of curiosity, how do you have this set up for debugging?

@chrisant996
Copy link
Owner

chrisant996 commented Dec 5, 2020

LOG() and ERR() write to the log file, whose name is reported by clink info.

Yeah, debugging injection itself involves a few steps. I'll also add some info to the README.md file about how to debug injection.

But once it's injected, debugging is pretty easy: just attach the debugger to the CMD.exe process, and set a breakpoint in some Clink code. For example for tab completion rl_complete or rl_menu_complete could be good breakpoints.

Regarding tilde completion, can you expand on "is not working"?
Also, do you have expand-tilde enabled in the .inputrc file?

From the Readline docs:

     'expand-tilde'
          If set to 'on', tilde expansion is performed when Readline
          attempts word completion.  The default is 'off'.

@chrisant996
Copy link
Owner

I can reproduce the problem. I think the v1.x match pipeline rewrite may be missing tilde support. I'll look into it.

@chrisant996 chrisant996 added the bug Something isn't working label Dec 5, 2020
@chrisant996
Copy link
Owner

chrisant996 commented Dec 5, 2020

c2c9eb2 fixes tilde expansion.
f7f0f72 makes expand-tilde default to on since CMD doesn't understand tilde.

Tilde expansion had gotten broken in v1.1.3-alpha by one of the backward compatibility changes.

@nikitalita
Copy link
Contributor Author

nikitalita commented Dec 7, 2020

Sorry, but I can still reproduce. Building from your latest master and on 1.1.5, vanilla and Cmder, and on a clean VM. I added set expand-tilde on in .inputrc and made sure that it was being loaded by adding and testing a custom shortcut, and it still didn't work.

Thanks to your instructions, I was able to debug this time, but unfortunately, the readline library is a mess and I can't quite figure out where it's going wrong. I put breakpoint at every single point that mentioned tilde completion and here's as near as I can figure out:

When trying to expand a tilde, readline fails to return any completions in rl_complete_internal. It eventually returns to here:
rl_module.cpp
image

s_matches->is_completion_over(); returns '1', and since it thinks that the completion is over, filename_menu_completion_function() never gets called.

I checked and rl_complete_with_tilde_expansion is set to 1. It does this with or without set expand-tilde on in .inputrc.

@nikitalita
Copy link
Contributor Author

to be clear, the command I'm testing this with is typing cd ~ and then hitting tab.

@chrisant996
Copy link
Owner

chrisant996 commented Dec 7, 2020

to be clear, the command I'm testing this with is typing cd ~ and then hitting tab.

Ohhh! Yes, that won't work as-is. Because cd, md, and rd are handled by argmatcher lua scripts, not by Readline. Tilde support is implemented in Readline, not in Clink per se.

Try just about any command other than those, and tildes should work.

Probably the best solution is to make Clink's Lua APIs for file/dir globbing handle tilde internally, but maybe with a flag to allow a script to disable tilde support if the script has some reason.

Clink's match pipeline collects matches at the beginning of entering a word, rather than when invoking a completion command. The alternate_matches function converts the match pipeline results into a format Readline can consume, but the matches were already collected at a prior point in time.

Also, the Readline code uses an unusual formatting style: indent width 2, hard tab width 8. I think very few text editors can detect that style and render the files properly without some configuration help from the user (and e.g. VSCode simply doesn't support that style, period). That might make Readline code look especially messy, if the editor isn't configured for it.

@chrisant996 chrisant996 reopened this Dec 7, 2020
@chrisant996
Copy link
Owner

e32a23a adds tilde completion support in the cd, md, and rd command argmatchers.
e30364b adds tilde completion support in the exec.enable Clink setting.

Also some new Lua functions have been added to make it easy for any matcher to support tilde completion (though it's rare for an argmatcher to want/need tilde completion).

@chrisant996
Copy link
Owner

New 1.1.6 (pre) release is available with the more complete fixes that include cd etc support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants