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

Dynamic autocompletion #60

Merged
merged 5 commits into from
Jul 26, 2016
Merged

Dynamic autocompletion #60

merged 5 commits into from
Jul 26, 2016

Conversation

setnicka
Copy link
Contributor

I implemented dynamic autocompletion mechanism.

Now there is a new item type "PcItemDynamic" which takes function as
parameter.

When it comes to autocomplete at this position, the function is called,
the whole line is given to it (for example if autocompletion depend on
previous autocompleted field) and functio should return possible strings
how to continue.

Example usage:

  • listing some dynamic key-value storage
  • listing files in directory

Now there is a new item type "PcItemDynamic" which takes function as
parameter.

When it comes to autocomplete at this position, the function is called,
the whole line is given to it (for example if autocompletion depend on
previous autocompleted field) and functio should return possible strings
how to continue.

Example usage:
 * listing some dynamic key-value storage
 * listing files in directory
@setnicka
Copy link
Contributor Author

Tested on Debian 5.4.0-3 and Win10, it seems working fine :-)

@chzyer
Copy link
Owner

chzyer commented Jun 25, 2016

@setnicka
I think we should use a new interface to make sure that it's backward compatibility?

@setnicka
Copy link
Contributor Author

setnicka commented Jun 28, 2016

@chzyer
Yes, it would be better. But this will probably yields to duplicate almost every function in completer_helper.go (because we will need to have old version od PrefixCompleter struct and new DynamicPrefixCompleter struct).

Or have you better idea?

And is there reason to use PrefixCompleterInterface interface outside this module?

To serve it to dynamic autocompletion functions. Previously passed line
was only following segment (which doesn't work).
@chzyer
Copy link
Owner

chzyer commented Jul 10, 2016

Hi! @setnicka , sorry for the lated reply.
How about this:

type DynamicPrefixCompleterInterface interface {
    PrefixCompleterInterface
    IsDynamic() bool
    GetDynamicNames(line []rune) [][]rune
}

In function Do, we just assert whether PrefixCompleterInterface is DynamicPrefixCompleterInterface.
And please add a new function instead of changing the declaration of Do. :)
Thanks!

@chzyer
Copy link
Owner

chzyer commented Jul 10, 2016

BTW, Dynamic autocompletion is really a very cool feature!

…in Do function

Do function was split into doInternal with changed declaration and Do
with original declaration.
@setnicka
Copy link
Contributor Author

setnicka commented Jul 19, 2016

Sorry for lated reply too (summer trips, camps, etc).

I added DynamicPrefixCompleterInterface like you suggested and yes, it looks good for me now :-)

Plus I split Do function into doInternal with added parameter and original Do with the original declaration.

@setnicka
Copy link
Contributor Author

Is there something I should fix/modify, or it can be merged?

@chzyer
Copy link
Owner

chzyer commented Jul 22, 2016

Not yet. Sorry about that.
I just want to review the code more deeply, I will got some time at weekend :)

@setnicka
Copy link
Contributor Author

Ok, it's fine, thank you :-)

@chzyer chzyer merged commit cffdf64 into chzyer:master Jul 26, 2016
@chzyer
Copy link
Owner

chzyer commented Jul 26, 2016

👍 It looks very cool!

@gotwarlost
Copy link

There is a lot of cool stuff in this code that I wish the docs would explain and give examples for. Every time I think I need something, I come across a type that already seems to do it (fair warning: I have exactly 1 day exposure to this code).

I'll figure out what everything does (eventually :) - there is a lot of stuff). Would you be open to accepting a PR with godoc additions and examples only?

@chzyer
Copy link
Owner

chzyer commented Sep 7, 2016

@gotwarlost
That's welcome :)

lunixbochs pushed a commit to lunixbochs/readline that referenced this pull request May 4, 2017
* Dynamic autocompletion implemented

Now there is a new item type "PcItemDynamic" which takes function as
parameter.

When it comes to autocomplete at this position, the function is called,
the whole line is given to it (for example if autocompletion depend on
previous autocompleted field) and functio should return possible strings
how to continue.

Example usage:
 * listing some dynamic key-value storage
 * listing files in directory

* Dynamic autocompletion: Updated example

* Dynamic autocompletion: Internal Do() is passing the original full line

To serve it to dynamic autocompletion functions. Previously passed line
was only following segment (which doesn't work).

* Dynamic autocompletion: New dynamic interface added + type assertion in Do function

Do function was split into doInternal with changed declaration and Do
with original declaration.
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.

3 participants