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

Comments

@dcu
Copy link
Contributor

@dcu 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 xiaq added this to the 0.13.1 milestone Jan 2, 2020
@xiaq xiaq closed this in 3de813c Jan 2, 2020
@xiaq

This comment has been minimized.

Copy link
Member

@xiaq 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
This fixes #852.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.