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

Refactor perform_completon #778

Merged
merged 1 commit into from
Nov 11, 2024

Conversation

tompng
Copy link
Member

@tompng tompng commented Nov 8, 2024

LineEditor#perform_completion was complicated.
When autocomplete is off, state is NORMAL, show_all_if_ambiguous is set, input is 1.ab[TAB]

L857: state change to COMPLETION
L874: calls complete_internal_proc to retrieve completion
L888: state change to MENU_WITH_PERFECT_MATCH
L889: calls perform_completion itself recursively
L874: calls complete_internal_proc just to set menu
L876: state change to PERFECT_MATCH

It turned out that CompletionState::COMPLETION was not needed at all.

This pull request simplifies the flow.
Fixes tab completion with completion-ignore-case.
Unintentionally fixes bug related to the complex flow. Typing 1.ab[TAB][DELETE_CHAR_OR_LIST] wrongly triggered show_document.

@tompng tompng force-pushed the simplify_complete_internal_proc branch 2 times, most recently from d45c432 to 0a1e254 Compare November 8, 2024 14:28
Flatten recursive method
Remove CompletionState::COMPLETE
@tompng tompng force-pushed the simplify_complete_internal_proc branch from 0a1e254 to 3a74d9b Compare November 8, 2024 14:30

unless Encoding.compatible?(target.encoding, item.encoding)
# Crash with Encoding::CompatibilityError is required by readline-ext/test/readline/test_readline.rb
# TODO: fix the test
Copy link
Member

Choose a reason for hiding this comment

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

Is the test still failing?

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -670,6 +670,19 @@ def self.vi_backward_word(line, byte_pointer)
[byte_size, width]
end

def self.common_prefix(list, ignore_case: false)
Copy link
Member

Choose a reason for hiding this comment

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

Just curious, what's the purpose of this method?

Copy link
Member Author

Choose a reason for hiding this comment

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

Calculates the common prefix of the list
common_prefix(["a.singleton_class", "a.singleton_method", "a.singleton_methods"]) returns
the common part prefix "a.singleton_"
Used in TAB completion

$ irb --noautocomplete
irb(main):001> a=''
=> ""
irb(main):002> a.sin[TAB]
↓
irb(main):002> a.singleton_

complete_internal_proc was doing this common prefix calculation (and also doing other things like filtering list and menu setup)
I split it to common_prefix (Pure string processing logic independent to line_editor) and filter_normalize_candidates (including completion logic).

Copy link
Member

Choose a reason for hiding this comment

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

I understand. Thank you!

Copy link
Member

@ima1zumi ima1zumi left a comment

Choose a reason for hiding this comment

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

LGTM~

@ima1zumi ima1zumi merged commit aa5b278 into ruby:master Nov 11, 2024
46 checks passed
matzbot pushed a commit to ruby/ruby that referenced this pull request Nov 11, 2024
(ruby/reline#778)

Flatten recursive method
Remove CompletionState::COMPLETE

ruby/reline@aa5b278f3d
@tompng tompng deleted the simplify_complete_internal_proc branch November 11, 2024 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants