Skip to content

Refactor perform_completon - #778

Merged
ima1zumi merged 1 commit into
ruby:masterfrom
tompng:simplify_complete_internal_proc
Nov 11, 2024
Merged

ima1zumi merged 1 commit into
ruby:masterfrom
tompng:simplify_complete_internal_proc

Conversation

@tompng

@tompng tompng commented Nov 8, 2024

Copy link
Copy Markdown
Member

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
Comment thread lib/reline/line_editor.rb

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
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Comment thread lib/reline/unicode.rb
[byte_size, width]
end

def self.common_prefix(list, ignore_case: false)

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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!

@ima1zumi ima1zumi left a comment

Copy link
Copy Markdown
Member

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
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants