mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/irb] Show lib name first because it's the most common use case
74d635758b
This commit is contained in:
parent
c5e8088c7e
commit
bc24af0f35
2 changed files with 12 additions and 4 deletions
|
@ -64,15 +64,18 @@ module IRB
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.retrieve_files_to_require_from_load_path
|
def self.retrieve_files_to_require_from_load_path
|
||||||
@@files_from_load_path ||= retrieve_gem_and_system_load_path.flat_map { |path|
|
@@files_from_load_path ||= retrieve_gem_and_system_load_path.map { |path|
|
||||||
begin
|
begin
|
||||||
Dir.glob("**/*.{rb,#{RbConfig::CONFIG['DLEXT']}}", base: path)
|
Dir.glob("**/*.{rb,#{RbConfig::CONFIG['DLEXT']}}", base: path)
|
||||||
rescue Errno::ENOENT
|
rescue Errno::ENOENT
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
}.uniq.map { |path|
|
}.inject([]) { |result, names|
|
||||||
path.sub(/\.(rb|#{RbConfig::CONFIG['DLEXT']})\z/, '')
|
shortest, *rest = names.map{ |n| n.sub(/\.(rb|#{RbConfig::CONFIG['DLEXT']})\z/, '') }.sort
|
||||||
}
|
result.unshift(shortest) if shortest
|
||||||
|
result.concat(rest)
|
||||||
|
result
|
||||||
|
}.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.retrieve_files_to_require_relative_from_current_dir
|
def self.retrieve_files_to_require_relative_from_current_dir
|
||||||
|
|
|
@ -68,6 +68,11 @@ module TestIRB
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_complete_require_library_name_first
|
||||||
|
candidates = IRB::InputCompletor::CompletionProc.("'cgi", "require ", "")
|
||||||
|
assert_equal candidates.first, "'cgi"
|
||||||
|
end
|
||||||
|
|
||||||
def test_complete_require_relative
|
def test_complete_require_relative
|
||||||
candidates = Dir.chdir(__dir__ + "/../..") do
|
candidates = Dir.chdir(__dir__ + "/../..") do
|
||||||
IRB::InputCompletor::CompletionProc.("'lib/irb", "require_relative ", "")
|
IRB::InputCompletor::CompletionProc.("'lib/irb", "require_relative ", "")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue