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

Handle (white)space in command mode autocompletion #434

Closed
Samonitari opened this issue Jul 15, 2019 · 7 comments · Fixed by #2005
Closed

Handle (white)space in command mode autocompletion #434

Samonitari opened this issue Jul 15, 2019 · 7 comments · Fixed by #2005
Labels
A-quickmenu Area: Quickmenu-related, i.e. QuickOpen, WIldmenu, Command Palette menus A-vim Area: Vim/modal editing A-vim-cmdline bug Something isn't working I-daily-editor-blocker An issue blocking use of the editor as a day-to-day editor

Comments

@Samonitari
Copy link

Autocompletition in command mode doesn't handle etries with spaces correctly.

  1. When dropping a filesystem based suggestion (in favour of another one: ie, choosing another) for command (e, chdir) parameters, only the last word (or Word?) gets deleted.
    command_mode_space_bug
    The command mode's state machine should delete the currently selected completition entry when a discard transition occours.

  2. When selecting an entry with spaces, it doesn't get escaped (like it did in Oni), and argument will be invalid for the command - for example chdir fails to folders with spaces in them (on Windows at least)

@bryphe bryphe added the bug Something isn't working label Jul 15, 2019
@bryphe bryphe added the I-daily-editor-blocker An issue blocking use of the editor as a day-to-day editor label Jul 31, 2019
@manu-unter
Copy link
Collaborator

manu-unter commented Jul 31, 2019

  1. The wrong insertion is probably caused by the fact that we determine the position at which to insert the autocompletion by going backwards through the entered string and looking for the first space we find. See

    let getCommandLineCompletionsMeet = (str: string, position: int) => {

    (bryphe provided me with this insight :) )
    I'm not sure if this is the logic we want - are there commands that include multiple spaces which are not part of a path? Otherwise we might be able to just take the first space instead?
    FWIW, original vim keeps track of the autocomplete starting point itself and doesn't retroactively calculate it. It might be necessary that we do the same, see xp->xp_pattern in https://github.com/onivim/libvim/blob/07e5aa155c887b8efbe023544c26f680a221abf1/src/ex_getln.c#L5556

  2. About the missing escaping: We seem to use vimCommandLineGetCompletions from libvim, which in turn directly hooks into expand_cmdline. The native vim flow has a lot of complexity around it which also makes sure that things like ~ are retained correctly in the suggestions, unnecessary prefixes are left out and other variables are expanded. This is more understandable by comparing screenshots:
    Native vim
    image
    Oni2
    image
    Some of these things seem to happen inside showmatches after expand_cmdline in the native flow - I think we might need to add these steps in a similar form to our vimCommandLineGetCompletions to get the same behavior. I'm unsure which parts exactly though since I can't quite figure out where exactly the escaping etc. happens. Will need some more investigations and drawing things up to figure this out.
    Edit: I think I found the relevant pieces. Adding a step similar to
    https://github.com/onivim/libvim/blob/07e5aa155c887b8efbe023544c26f680a221abf1/src/ex_getln.c#L5212
    should make sure that the string is escaped correctly. I'm not totally clear on the flow paths across that file though, so there might be some other missing pieces.

@Samonitari
Copy link
Author

Samonitari commented Aug 1, 2019

  1. I'm not sure if this is the logic we want - are there commands that include multiple spaces which are not part of a path? Otherwise we might be able to just take the first space instead?
    FWIW, original vim keeps track of the autocomplete starting point itself and doesn't retroactively calculate it. It might be necessary that we do the same

I thought almost this when I said "The command mode's state machine should delete the currently selected completition entry when a discard transition occours."
I meant to say (quite clumsily), that if you keep track of the currently selected autocompletion entry you can remove it accurately too. But the reason behind it was sane - do NOT try to calculate (guess) the point after-the-fact, but store some information when choosing an entry.
Quite possibly choosing the vim approach (store the starting point) is better.

I thought about implementing this, as this seemed a possibly good first issue but: I do not know Reason.
Maybe if you think the first part can be solved as a stand alone issue, I'll give it a shot.

@glennsl glennsl added A-quickmenu Area: Quickmenu-related, i.e. QuickOpen, WIldmenu, Command Palette menus A-vim Area: Vim/modal editing labels Nov 18, 2019
ericluap added a commit to ericluap/oni2 that referenced this issue Apr 3, 2020
bryphe added a commit that referenced this issue Jun 25, 2020
…ce (#2005)

* Refactor command line completion to testable unit

* Initial test cases

* Formatting

* Tweak completion timing for more vim-wildmenu-like behavior

* Formatting
@bryphe bryphe reopened this Jun 25, 2020
@bryphe
Copy link
Member

bryphe commented Jun 25, 2020

Issues 1) and 2) called out at the root issue should be fixed with #2005

However, the escaping didn't seem necessary in my testing - let me know if you have case that is failing w/ the latest that I can try.

@Samonitari
Copy link
Author

On first skimming, it seems fine!
I plan to spend some more time with oni2 in the weekend though, so I'll report if I've found some missed parts!

@bryphe
Copy link
Member

bryphe commented Jun 26, 2020

Great news! Thank you @Samonitari

@Samonitari
Copy link
Author

Unfortunately there is still a quirk.
Issue 1) is fixed,
Issue 2) is half okay - on linux I won't get autocompiletion of the contents, if I select a folder with whitespaces in its name.
On Windows this doesn't seem to happen

@Samonitari
Copy link
Author

Samonitari commented Jul 8, 2021

I just checked this after reporting #3751, and this has been fixed since some time ago. (issue-for-an-issue as the old Babylonian saying goes 😆 )
Original sub-issue 2) is gone on linux also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-quickmenu Area: Quickmenu-related, i.e. QuickOpen, WIldmenu, Command Palette menus A-vim Area: Vim/modal editing A-vim-cmdline bug Something isn't working I-daily-editor-blocker An issue blocking use of the editor as a day-to-day editor
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants