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

Fix parsing arg for user commands #166

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Gelio
Copy link

@Gelio Gelio commented Nov 18, 2022

For user commands, the parsed arg was everything in the cmdline after the command name. This meant that for :DiffviewOpen origin/master --i, the arg was origin/master --i. The completions returned by getcompletion(cmdline, 'cmdline') returned the completions that are prefixed by the last argument (--i, for example --imply-local). Then, the filtering code attempted to filter the completions (["--imply-local"]) using origin/master --i, which did not match. For the arg, only the last argument (--i) should be used in this case for the filtering to return the correct completions.

The consequence was that completions for the 2nd and subsequent were not shown for user commands with complete functions in Lua.

This commit changes the cmdline parsing logic so that for user commands, only the last argument in the cmdline is parsed as the arg. This way the filtering logic correctly matches --imply-local as a valid completion for --i.

The following commands now show completions, whereas they did not show any completions before:

  • :DiffviewOpen origin/master --i
  • :Telescope live_grep pre
Peek.2022-11-18.12-51.mp4

image

I didn't notice anything break at first sight. Completions for other types of commands seems to be working.

Fixes #159

For user commands, the parsed `arg` was everything in the cmdline after
the command name. This meant that for `:DiffviewOpen origin/master --i`,
the `arg` was `origin/master --i`. The completions returned by
`getcompletion(cmdline, 'cmdline')` returned the completions that are
prefixed by the last argument (`--i`, for example `--imply-local`).
Then, the filtering code attempted to filter the completions
(`["--imply-local"]`) using `origin/master --i`, which did not match.
For the `arg`, only the last argument (`--i`) should be used in this
case for the filtering to return the correct completions.

The consequence was that completions for the 2nd and subsequent were not
shown for user commands with `complete` functions in Lua.

This commit changes the cmdline parsing logic so that for user commands,
only the last argument in the cmdline is parsed as the `arg`. This way
the filtering logic correctly matches `--imply-local` as a valid
completion for `--i`.

The following commands now show completions, whereas they did not show
any completions before:

* :DiffviewOpen origin/master --i
* :Telescope live_grep pre

Fixes gelguy#159
Gelio added a commit to Gelio/ubuntu-dotfiles that referenced this pull request Nov 18, 2022
Use my fork until the fix [0] is merged upstream.

[0]: gelguy/wilder.nvim#166
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Candidates for second and subsequent user command arguments are not shown
1 participant