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

CompletionType::List does not support completion candidates that are shorter than the input #748

Closed
sharkdp opened this issue Nov 28, 2023 · 5 comments · Fixed by #750
Closed
Labels

Comments

@sharkdp
Copy link

sharkdp commented Nov 28, 2023

Thank you for maintaining this crate — we use it in Numbat and it works great.

We want to implement a feature where a user could type something like \hbar in the REPL, press Tab and it would be replaced by . This seems to work fine when using CompletionType::Circular, but it does not work for CompletionType::List. Words will only be replaced if they are longer than the input. This is probably due to this check:

if lcp.len() > s.line.pos() - start {

Would it be possible to support this use case?

Remark: that check above should probably use lcp.unicode_width() instead of lcp.len() (?).

@gwenn
Copy link
Collaborator

gwenn commented Nov 29, 2023

Not strictly related to the issue but to your remark:

that check above should probably use lcp.unicode_width() instead of lcp.len() (?).

s.line.pos() and start are byte offsets so the difference between them is a number of bytes.
So lcp.len() seems right.
But maybe we should compare s.line[start..s.line.pos()].width() and lcp.width() instead.
I will try to do some tests...

@gwenn
Copy link
Collaborator

gwenn commented Dec 2, 2023

Ok,
If I remember correctly, I used replxx (or linenoise-ng) as a reference implementation.
But then I didn't backported this change:

if ( ( longestCommonPrefix > itemLength ) || ( completionsCount == 1 ) ) {

And the associated comment perfectly matches your issue:

Support replacement completions, e.g. substitute symbolic names (\alpha) with proper symbols (α).

@gwenn
Copy link
Collaborator

gwenn commented Dec 2, 2023

Could you please give #750 a try ?

@gwenn gwenn closed this as completed in #750 Dec 5, 2023
@gwenn
Copy link
Collaborator

gwenn commented Dec 5, 2023

Version 13.0.0 released.

@sharkdp
Copy link
Author

sharkdp commented Dec 5, 2023

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants