summaryrefslogtreecommitdiff
path: root/lib/irb/completion.rb
diff options
context:
space:
mode:
authortomoya ishida <[email protected]>2024-04-11 01:52:47 +0900
committergit <[email protected]>2024-04-10 16:52:53 +0000
commit6a505d1b59cf326a8e004fc06e02f30222b17f3f (patch)
tree8ed520d1aee744158f154f4dd7733b6eb4d017e0 /lib/irb/completion.rb
parent9f6deaa6888a423720b4b127b5314f0ad26cc2e6 (diff)
[ruby/irb] Command implementation not by method
(https://github.com/ruby/irb/pull/824) * Command is not a method * Fix command test * Implement non-method command name completion * Add test for ExtendCommandBundle.def_extend_command * Add helper method install test * Remove spaces in command input parse * Remove command arg unquote in help command * Simplify Statement and handle execution in IRB::Irb * Tweak require, const name * Always install CommandBundle module to main object * Remove considering local variable in command or expression check * Remove unused method, tweak * Remove outdated comment for help command arg Co-authored-by: Stan Lo <[email protected]> --------- https://github.com/ruby/irb/commit/8fb776e379 Co-authored-by: Stan Lo <[email protected]>
Diffstat (limited to 'lib/irb/completion.rb')
-rw-r--r--lib/irb/completion.rb17
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb
index b3813e8939..8a1df11561 100644
--- a/lib/irb/completion.rb
+++ b/lib/irb/completion.rb
@@ -86,6 +86,14 @@ module IRB
)
end
+ def command_completions(preposing, target)
+ if preposing.empty? && !target.empty?
+ IRB::ExtendCommandBundle.command_names.select { _1.start_with?(target) }
+ else
+ []
+ end
+ end
+
def 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/, '')
@@ -103,9 +111,11 @@ module IRB
end
def completion_candidates(preposing, target, _postposing, bind:)
+ commands = command_completions(preposing, target)
result = ReplTypeCompletor.analyze(preposing + target, binding: bind, filename: @context.irb_path)
- return [] unless result
- result.completion_candidates.map { target + _1 }
+ return commands unless result
+
+ commands | result.completion_candidates.map { target + _1 }
end
def doc_namespace(preposing, matched, _postposing, bind:)
@@ -181,7 +191,8 @@ module IRB
result = complete_require_path(target, preposing, postposing)
return result if result
end
- retrieve_completion_data(target, bind: bind, doc_namespace: false).compact.map{ |i| i.encode(Encoding.default_external) }
+ commands = command_completions(preposing || '', target)
+ commands | retrieve_completion_data(target, bind: bind, doc_namespace: false).compact.map{ |i| i.encode(Encoding.default_external) }
end
def doc_namespace(_preposing, matched, _postposing, bind:)