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

panic: runtime error: slice bounds out of range #852

Closed
dcu opened this issue Aug 25, 2019 · 1 comment
Closed

panic: runtime error: slice bounds out of range #852

dcu opened this issue Aug 25, 2019 · 1 comment
Labels
Milestone

Comments

@dcu
Copy link
Contributor

dcu commented Aug 25, 2019

Copy and paste:

edit:completion:arg-completer[go] = [cmd, args]{
    arg=$args[(- (count $args) 1)]
    put $arg*
}

then go <tab>

I'm using the master version

@xiaq
Copy link
Member

xiaq commented Jan 2, 2020

The underlying crash has been fixed, but note that there are some problems with your example code:

  • Elvish does not use comma to separate arguments
  • You need to use @args to get all remaining arguments

So the correct code should be:

edit:completion:arg-completer[go] = [cmd @args]{
    arg=$args[(- (count $args) 1)]
    put $arg*
}

Also, you could just use $args[-1] to access the last element. So you can write:

edit:completion:arg-completer[go] = [cmd @args]{ put $args[-1]* }

Finally, in a completer you don't do filtering; the filtering is handled in a separate pass; see https://elv.sh/ref/edit.html#argument-completer. Maybe I should rename "completer" to "generator" to make this clearer.

xiaq added a commit that referenced this issue Jan 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants