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

JIT: Execute external command lazily based on the fallbacks order #42

Open
adaszko opened this issue Feb 3, 2024 · 0 comments
Open
Labels
enhancement New feature or request
Milestone

Comments

@adaszko
Copy link
Owner

adaszko commented Feb 3, 2024

For a grammar cmd (--foo | {{{ echo bar }}});, the {{{ echo bar }}} command is executed even when we're matching the first word (i.e. cmd <TAB>), which is premature. {{{ echo bar }}} should be executed lazily only after we know --foo hasn't matched.

The output currently produced:

__complgen_jit () {
    local -a matches=()
    local -a completions=("bar" "foo")
    compadd -Q -a completions
    compadd -O matches -a completions
    [[ ${#matches} -gt 0 ]] && return
}
__complgen_jit

whereas it should look more like (in this case for ZSH)

__complgen_jit () {
    local -a matches=()
    local -a completions=("foo")
    compadd -Q -a completions
    compadd -O matches -a completions
    [[ ${#matches} -gt 0 ]] && return

    completions=("${(@f)$(echo bar)}")
    compadd -Q -a completions
    compadd -O matches -a completions
    [[ ${#matches} -gt 0 ]] && return
}
__complgen_jit

This piece of code is responsible for generating those completions:

complgen/src/jit.rs

Lines 395 to 400 in 5e29dcb

// Complete `prefix` based on `state`.
let mut output: Vec<Completion> = Default::default();
for (input, _) in dfa.iter_transitions_from(state) {
get_completions_for_input(&input, prefix, shell, &mut output)?;
}
output.sort_unstable_by(|left, right| left.get_completion().cmp(&right.get_completion()));

@adaszko adaszko added the bug Something isn't working label Feb 3, 2024
@adaszko adaszko added this to the 1.0 milestone Feb 3, 2024
@adaszko adaszko added enhancement New feature or request and removed bug Something isn't working labels Feb 5, 2024
adaszko added a commit that referenced this issue Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant