mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parent
f45bed0a6e
commit
ad8842c06d
2 changed files with 33 additions and 12 deletions
|
@ -40,6 +40,24 @@ module IRB
|
||||||
|
|
||||||
BASIC_WORD_BREAK_CHARACTERS = " \t\n`><=;|&{("
|
BASIC_WORD_BREAK_CHARACTERS = " \t\n`><=;|&{("
|
||||||
|
|
||||||
|
def self.retrieve_files_to_require_from_load_path
|
||||||
|
@@files_from_load_path ||= $LOAD_PATH.flat_map { |path|
|
||||||
|
begin
|
||||||
|
Dir.glob("**/*.{rb,#{RbConfig::CONFIG['DLEXT']}}", base: path)
|
||||||
|
rescue Errno::ENOENT
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
}.uniq.map { |path|
|
||||||
|
path.sub(/\.(rb|#{RbConfig::CONFIG['DLEXT']})\z/, '')
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.retrieve_files_to_require_relative_from_current_dir
|
||||||
|
@@files_from_current_dir ||= Dir.glob("**/*.{rb,#{RbConfig::CONFIG['DLEXT']}}", base: '.').map { |path|
|
||||||
|
path.sub(/\.(rb|#{RbConfig::CONFIG['DLEXT']})\z/, '')
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
CompletionRequireProc = lambda { |target, preposing = nil, postposing = nil|
|
CompletionRequireProc = lambda { |target, preposing = nil, postposing = nil|
|
||||||
if target =~ /\A(['"])([^'"]+)\Z/
|
if target =~ /\A(['"])([^'"]+)\Z/
|
||||||
quote = $1
|
quote = $1
|
||||||
|
@ -55,26 +73,17 @@ module IRB
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
result = []
|
||||||
if tok && tok.event == :on_ident && tok.state == Ripper::EXPR_CMDARG
|
if tok && tok.event == :on_ident && tok.state == Ripper::EXPR_CMDARG
|
||||||
case tok.tok
|
case tok.tok
|
||||||
when 'require'
|
when 'require'
|
||||||
result = $LOAD_PATH.flat_map { |path|
|
result = retrieve_files_to_require_from_load_path.select { |path|
|
||||||
begin
|
|
||||||
Dir.glob("**/*.{rb,#{RbConfig::CONFIG['DLEXT']}}", base: path)
|
|
||||||
rescue Errno::ENOENT
|
|
||||||
[]
|
|
||||||
end
|
|
||||||
}.uniq.map { |path|
|
|
||||||
path.sub(/\.(rb|#{RbConfig::CONFIG['DLEXT']})\z/, '')
|
|
||||||
}.select { |path|
|
|
||||||
path.start_with?(actual_target)
|
path.start_with?(actual_target)
|
||||||
}.map { |path|
|
}.map { |path|
|
||||||
quote + path
|
quote + path
|
||||||
}
|
}
|
||||||
when 'require_relative'
|
when 'require_relative'
|
||||||
result = Dir.glob("**/*.{rb,#{RbConfig::CONFIG['DLEXT']}}", base: '.').map { |path|
|
result = retrieve_files_to_require_relative_from_current_dir.select { |path|
|
||||||
path.sub(/\.(rb|#{RbConfig::CONFIG['DLEXT']})\z/, '')
|
|
||||||
}.select { |path|
|
|
||||||
path.start_with?(actual_target)
|
path.start_with?(actual_target)
|
||||||
}.map { |path|
|
}.map { |path|
|
||||||
quote + path
|
quote + path
|
||||||
|
|
|
@ -61,6 +61,11 @@ module TestIRB
|
||||||
%w['irb/init 'irb/ruby-lex].each do |word|
|
%w['irb/init 'irb/ruby-lex].each do |word|
|
||||||
assert_include candidates, word
|
assert_include candidates, word
|
||||||
end
|
end
|
||||||
|
# Test cache
|
||||||
|
candidates = IRB::InputCompletor::CompletionProc.("'irb", "require ", "")
|
||||||
|
%w['irb/init 'irb/ruby-lex].each do |word|
|
||||||
|
assert_include candidates, word
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_complete_require_relative
|
def test_complete_require_relative
|
||||||
|
@ -70,6 +75,13 @@ module TestIRB
|
||||||
%w['lib/irb/init 'lib/irb/ruby-lex].each do |word|
|
%w['lib/irb/init 'lib/irb/ruby-lex].each do |word|
|
||||||
assert_include candidates, word
|
assert_include candidates, word
|
||||||
end
|
end
|
||||||
|
# Test cache
|
||||||
|
candidates = Dir.chdir(__dir__ + "/../..") do
|
||||||
|
IRB::InputCompletor::CompletionProc.("'lib/irb", "require_relative ", "")
|
||||||
|
end
|
||||||
|
%w['lib/irb/init 'lib/irb/ruby-lex].each do |word|
|
||||||
|
assert_include candidates, word
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue