Skip to content

boxes: Improve trigger sequence for generic_autocomplete #542

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

Merged
merged 1 commit into from
Jul 19, 2020

Conversation

preetmishra
Copy link
Member

Updated generic_autocomplete along with its autocomplete_mentions/streams to provide typeahead even when there are some characters before their respective trigger character.

Fixes #541 and #448 (partially).

@zulipbot zulipbot added the size: S [Automatic label added by zulipbot] label Mar 13, 2020
@neiljp neiljp added the PR needs review PR requires feedback to proceed label Mar 14, 2020
Copy link
Member

@kaustubh-nair kaustubh-nair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
Adding some test cases would be a good idea to ensure that something isn't amiss. :)

@zulipbot zulipbot added size: M [Automatic label added by zulipbot] and removed size: S [Automatic label added by zulipbot] labels Mar 14, 2020
@preetmishra
Copy link
Member Author

@kaustubh-nair Thanks for the review. I have pushed the amended tests now.

@zulipbot zulipbot added size: L [Automatic label added by zulipbot] and removed size: M [Automatic label added by zulipbot] labels Mar 17, 2020
@preetmishra
Copy link
Member Author

Update: I have added a refactor commit to make autocomplete_streams' signature consistent with autocomplete_mentions as per the suggestion of @kaustubh-nair. (#542 (review))

Copy link
Member

@sumanthvrao sumanthvrao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@preetmishra This looks fairly straightforward and much more consistent. The changes LGTM!

minor: Looks like the only place we are hard-coding the prefix string now is these group_typeaheads. Maybe we can do something along the same lines there as well.

@preetmishra
Copy link
Member Author

@sumanthvrao Thanks. I have pushed a new commit to address the latter point.

@preetmishra
Copy link
Member Author

The Travis CI build is failing with 'An error occurred while generating the build script.' for Install & pytest - Python 3 (OS X; xcode10). I tried to restart it with force push but it didn't work again.

@sumanthvrao
Copy link
Member

sumanthvrao commented Mar 23, 2020

@preetmishra thanks for addressing the minor feedback quickly. The additional commit LGTM!

@neiljp FYI :)

@preetmishra
Copy link
Member Author

Update: Rebased to include autocomplete_emojis, that was added in 2c30caf, in the PR as well.

@neiljp
Copy link
Collaborator

neiljp commented Apr 9, 2020

@preetmishra Sorry for not getting back to this; could you rebase?

@neiljp neiljp removed the PR needs review PR requires feedback to proceed label Apr 9, 2020
@preetmishra
Copy link
Member Author

@neiljp No problem; I have rebased the PR. :)

The first commit was a suggestion from @sumanthvrao to improve consistency. The next two are self-explanatory refactor commits that facilitate the new change.

@kaustubh-nair
Copy link
Member

@preetmishra I just noticed that you recently pushed a07c87d for refactoring generic_autocomplete. While it looks good but there is still a little bit of duplication. I had pushed similar changes to the footer PR.

I'd recommend holding off refactors to autocomplete methods for a while, since there are already so many of them in the footer PR. Adding them in different PRs will cause a lot of confusion.
That being said, if you want to make any changes, feel free to push to the autocomplete_footer branch on my fork. It would be better if we keep autocomplete refactors in the same place :)

@zulipbot zulipbot added size: M [Automatic label added by zulipbot] and removed size: L [Automatic label added by zulipbot] labels Apr 11, 2020
@preetmishra
Copy link
Member Author

@kaustubh-nair Thanks for taking a look. 👍

I see what you're suggesting. While keeping the refactors in the same PR sounds valid, the fact that this PR is comparatively small and easier to review makes it likely to be merged quickly. If that's the case, you can always rebase against master to incorporate the new changes.

I have updated the commit to make generic_autocomplete less redundant and more pythonic.

@kaustubh-nair
Copy link
Member

@preetmishra Sorry I did not make myself more clear - One of the major reasons to avoid the refactors at different places was so that both of us don't waste our time working on the same thing. I have a similar commit here which is used for the footer PR

@neiljp neiljp added the PR needs review PR requires feedback to proceed label May 8, 2020
@preetmishra preetmishra force-pushed the extend-typeahead branch 2 times, most recently from 0dbfdc9 to 27398fb Compare May 9, 2020 11:26
@zulipbot zulipbot added size: S [Automatic label added by zulipbot] and removed size: M [Automatic label added by zulipbot] labels Jun 15, 2020
@preetmishra
Copy link
Member Author

I have rebased the PR against the recent refactors that were pushed in #540. This should be independent and comparatively smaller to review now.

@neiljp
Copy link
Collaborator

neiljp commented Jul 5, 2020

@preetmishra Could you rebase? Also, the first commit is small now? I'll be interested to confirm how the code works for silent group mentions (which don't exist, by my understanding), and whether there are any strange cases where in vs startswith causes strange behavior

@neiljp neiljp removed the PR needs review PR requires feedback to proceed label Jul 5, 2020
@preetmishra
Copy link
Member Author

preetmishra commented Jul 5, 2020

@neiljp Thanks for the review. I have rebased the changes and shelved the first commit (see #542 (comment)).

Re strange cases, I didn't come across any strange case while testing it manually or analyzing its logic.

Copy link
Collaborator

@neiljp neiljp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@preetmishra This certainly remains an improvement in terms of where we can perform autocomplete, but at minimum we might want to consider if we want to treat the following and similar examples more consistently:

  • #@term -> #@*terminal* (# + @terminal)
  • @#a -> no matches (should we expect @ + #announce ?)
  • @@term -> no matches (should we expect @ + @terminal?)
  • :#a -> :#announce (: + #announce)
  • #:t -> no matches (should we expect#+ eg🎉`?)

@preetmishra preetmishra changed the title boxes: Improve trigger sequence for generic_autocomplete. [WIP] boxes: Improve trigger sequence for generic_autocomplete. Jul 9, 2020
This updates generic_autocomplete to trigger autocomplete functions even
when there are some other characters before their autocomplete prefixes.

The prefix lookup is done in a reversed order to find the last
autocomplete prefix used in the text. This is particularly useful in
cases where the text has more than one autocomplete prefix
(e.g. @#stream).

Tests amended.

Fixes zulip#541.
@zulipbot zulipbot added size: L [Automatic label added by zulipbot] and removed size: S [Automatic label added by zulipbot] labels Jul 13, 2020
@preetmishra
Copy link
Member Author

preetmishra commented Jul 13, 2020

@neiljp Thanks for catching that out! I have reworked the approach to find the last autocomplete prefix using a reverse lookup.

This should fix the inconsistencies that you reported (test cases are added) and should be more reliable.

@preetmishra preetmishra changed the title [WIP] boxes: Improve trigger sequence for generic_autocomplete. boxes: Improve trigger sequence for generic_autocomplete Jul 13, 2020
@preetmishra preetmishra added the PR needs review PR requires feedback to proceed label Jul 13, 2020
@neiljp
Copy link
Collaborator

neiljp commented Jul 19, 2020

@preetmishra This looks good - and if we refactor the code later the tests should ensure things keep working 👍 Merging this now 🎉

We could maybe make the code simpler and without the specific case for the silent mention, but we have a limited subset of autocomplete so this is fine for now. I'm not sure if eg. a sorted rfind of prefixes might work?

@neiljp neiljp merged commit cbf0280 into zulip:master Jul 19, 2020
@neiljp neiljp added this to the 0.5.2 milestone Jul 19, 2020
@preetmishra
Copy link
Member Author

Thanks for the merge! The sorted rfind of prefixes sounds appealing for refactoring. 🙌

@preetmishra preetmishra deleted the extend-typeahead branch July 19, 2020 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR needs review PR requires feedback to proceed size: L [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typeahead doesn't initiate with some characters before trigger character
5 participants