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

Implement completion NoMatching #1833

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

Conversation

raphaelvigee
Copy link

Re #1828

Was only able to get it to work on zsh & fish. bash not supported, was not able to test powershell

@CLAassistant
Copy link

CLAassistant commented Oct 19, 2022

CLA assistant check
All committers have signed the CLA.

@raphaelvigee raphaelvigee force-pushed the no-matching branch 3 times, most recently from c00a315 to 217ca52 Compare October 20, 2022 12:23
Copy link
Collaborator

@marckhouzam marckhouzam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @raphaelvigee.
Could you provide a small test program that uses the new directive so I can figure out how the user would use this?

fish_completions.go Outdated Show resolved Hide resolved

__%[1]s_debug "nospace: $nospace, nofiles: $nofiles"
__%[1]s_debug "nospace: $nospace, nofiles: $nofiles, nomatching: $nomatching"

# If we want to prevent a space, or if file completion is NOT disabled,
# we need to count the number of valid completions.
# To do so, we will filter on prefix as the completions we have received
# may not already be filtered so as to allow fish to match on different
# criteria than the prefix.
if test $nospace -ne 0; or test $nofiles -eq 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a special case which the comment may not have made very clear.

Let's take file completion. We only want to trigger file completion if there are no other completions available (from the point of view of the user). This is not normally what fish does, but it is how the other shells behave so we decided to standardize on that.

However, if the program does not filter on prefix (to allow fuzzy matching), it will always return some completions and we will not be able to know if fish will match any of them or not; so, we would not know if there are no real completions and couldn't tell if we should trigger file completion. Therefore, in this case, we turn off fuzzy matching and explicitly match on prefix; if there are no completions left, we know to turn on file completion.

A similar scenario applies to the nospace directive. You can refer to #1249 for details.

This means that in this case, we cannot do fuzzy completion, or it would break the request from the program to do file completion and/or nospace completion.

I don't know if that was clear, so don't hesitate to ask for clarification.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum I see, what do you suggest changing the logic to in that case ?

zsh_completions.go Outdated Show resolved Hide resolved
fish_completions.go Outdated Show resolved Hide resolved
@marckhouzam
Copy link
Collaborator

Thanks @raphaelvigee. Could you provide a small test program that uses the new directive so I can figure out how the user would use this?

To be honest, I still don't understand what the PR is trying to achieve. Fuzzy matching works for me on both zsh and fish right now.

Could it be that fuzzy matching does not work for you for fish because FileCompletion or NoSpace are requested? Which is a current limitation as explained in #1833 (comment)

@github-actions
Copy link

The Cobra project currently lacks enough contributors to adequately respond to all PRs. This bot triages issues and PRs according to the following rules:

  • After 60d of inactivity, lifecycle/stale is applied. - After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied and the PR is closed.
    You can:
  • Make a comment to remove the stale label and show your support. The 60 days reset. - If a PR has lifecycle/rotten and is closed, comment and ask maintainers if they'd be interested in reopening.

@raphaelvigee
Copy link
Author

@marckhouzam Sorry I missed that, i m pretty sure zsh does prefix matching, which is what this PR is trying to change to fuzzy matching, but i ll double check

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.

None yet

3 participants