Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve help/show_cmds message during debugger integration #693

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/irb/cmd/show_cmds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ class ShowCmds < Nop
def execute(*args)
commands_info = IRB::ExtendCommandBundle.all_commands_info
commands_grouped_by_categories = commands_info.group_by { |cmd| cmd[:category] }

if irb_context.with_debugger
# Remove the original "Debugging" category
commands_grouped_by_categories.delete("Debugging")
# Remove the `help` command as it's delegated to the debugger
commands_grouped_by_categories["Context"].delete_if { |cmd| cmd[:display_name] == :help }
# Add an empty "Debugging (from debug.gem)" category at the end
commands_grouped_by_categories["Debugging (from debug.gem)"] = []
end

longest_cmd_name_length = commands_info.map { |c| c[:display_name].length }.max

output = StringIO.new
Expand All @@ -29,6 +39,11 @@ def execute(*args)
output.puts
end

# Append the debugger help at the end
if irb_context.with_debugger
output.puts DEBUGGER__.help
end

Pager.page_content(output.string)
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/irb/statement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def suppresses_echo?
end

def should_be_handled_by_debugger?
IRB::ExtendCommand::DebugCommand > @command_class
require_relative 'cmd/help'
st0012 marked this conversation as resolved.
Show resolved Hide resolved
require_relative 'cmd/debug'
IRB::ExtendCommand::DebugCommand > @command_class || IRB::ExtendCommand::Help == @command_class
end

def evaluable_code
Expand Down
33 changes: 33 additions & 0 deletions test/irb/test_debug_cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,39 @@ def bar
assert_include(output, "InputMethod: RelineInputMethod")
end

def test_help_command_is_delegated_to_the_debugger
write_ruby <<~'ruby'
binding.irb
ruby

output = run_ruby_file do
type "debug"
type "help"
type "continue"
end

assert_include(output, "### Frame control")
end

def test_show_cmds_display_different_content_when_debugger_is_enabled
write_ruby <<~'ruby'
# disable pager
STDIN.singleton_class.define_method(:tty?) { false }
binding.irb
ruby

output = run_ruby_file do
type "debug"
type "show_cmds"
type "continue"
end

# IRB's commands should still be listed
assert_match(/show_cmds\s+List all available commands and their description\./, output)
# debug gem's commands should be appended at the end
assert_match(/Debugging \(from debug\.gem\)\s+### Control flow/, output)
end

def test_input_is_evaluated_in_the_context_of_the_current_thread
write_ruby <<~'ruby'
current_thread = Thread.current
Expand Down