Skip to content

Commit 788a0b9

Browse files
committed
Move method candidates sort into the :call branch
1 parent 93ca6a1 commit 788a0b9

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

lib/repl_type_completor/result.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,21 @@ def completion_candidates
7979
keys.sort
8080
end
8181
in [:call, name, type, self_call]
82-
(self_call ? type.all_methods : type.methods).map(&:to_s) - HIDDEN_METHODS
82+
methods = (self_call ? type.all_methods : type.methods).map(&:to_s) - HIDDEN_METHODS
83+
# Alphabetical order, but internal methods (leading underscore) last.
84+
# `_1[0] == '_'` because `start_with?('_')` raises EncodingError if the
85+
# method name's encoding is incompatible with US-ASCII.
86+
methods.sort_by { [_1[0] == '_' ? 1 : 0, _1] }
8387
in [:lvar_or_method, name, scope]
8488
scope.local_variables.sort | scope.self_type.all_methods.map(&:to_s).sort | RESERVED_WORDS
8589
else
8690
[]
8791
end
8892

89-
candidates = candidates.filter_map do
90-
_1 if _1.start_with?(name)
93+
candidates.filter_map do
94+
_1[name.size..] if _1.start_with?(name)
9195
rescue EncodingError
9296
end
93-
candidates.sort_by! { [_1.start_with?('_') ? 1 : 0, _1] } if @analyze_result.first == :call
94-
candidates.map { _1[name.size..] }
9597
rescue Exception => e
9698
ReplTypeCompletor.handle_exception(e)
9799
[]

0 commit comments

Comments
 (0)