summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomoya ishida <[email protected]>2023-10-13 01:54:04 +0900
committergit <[email protected]>2023-10-12 16:54:09 +0000
commit1126bd8c65ab077392b559fedd8f9b07303313c9 (patch)
treeab62eb78fb3fafee3c2767ffa4306266e627667a
parent10ba3fc302d68f977ce958b27a46ce0dab537f0c (diff)
[ruby/irb] Fix require path completion disturbing string method
completion (https://github.com/ruby/irb/pull/726) https://github.com/ruby/irb/commit/e42dc74ce0
-rw-r--r--lib/irb/completion.rb32
-rw-r--r--test/irb/test_completion.rb3
2 files changed, 18 insertions, 17 deletions
diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb
index 26215f6fe1..795a35bb2d 100644
--- a/lib/irb/completion.rb
+++ b/lib/irb/completion.rb
@@ -132,24 +132,22 @@ module IRB
break
end
end
- result = []
- if tok && tok.event == :on_ident && tok.state == Ripper::EXPR_CMDARG
- case tok.tok
- when 'require'
- result = retrieve_files_to_require_from_load_path.select { |path|
- path.start_with?(actual_target)
- }.map { |path|
- quote + path
- }
- when 'require_relative'
- result = retrieve_files_to_require_relative_from_current_dir.select { |path|
- path.start_with?(actual_target)
- }.map { |path|
- quote + path
- }
- end
+ return unless tok&.event == :on_ident && tok.state == Ripper::EXPR_CMDARG
+
+ case tok.tok
+ when 'require'
+ retrieve_files_to_require_from_load_path.select { |path|
+ path.start_with?(actual_target)
+ }.map { |path|
+ quote + path
+ }
+ when 'require_relative'
+ retrieve_files_to_require_relative_from_current_dir.select { |path|
+ path.start_with?(actual_target)
+ }.map { |path|
+ quote + path
+ }
end
- result
end
def completion_candidates(preposing, target, postposing, bind:)
diff --git a/test/irb/test_completion.rb b/test/irb/test_completion.rb
index 8402889400..19a6a4740a 100644
--- a/test/irb/test_completion.rb
+++ b/test/irb/test_completion.rb
@@ -79,6 +79,9 @@ module TestIRB
%w['irb/init 'irb/ruby-lex].each do |word|
assert_include candidates, word
end
+ # Test string completion not disturbed by require completion
+ candidates = IRB::RegexpCompletor.new.completion_candidates("'string ", "'.", "", bind: binding)
+ assert_include candidates, "'.upcase"
end
def test_complete_require_with_pathname_in_load_path