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

Hint debugger command in irb:rdbg session #768

Merged
merged 1 commit into from
Nov 23, 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
18 changes: 18 additions & 0 deletions lib/irb/debug.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ def DEBUGGER__.capture_frames(*args)
DEBUGGER__::ThreadClient.prepend(SkipPathHelperForIRB)
end

if !@output_modifier_defined && !DEBUGGER__::CONFIG[:no_hint]
irb_output_modifier_proc = Reline.output_modifier_proc
tompng marked this conversation as resolved.
Show resolved Hide resolved

Reline.output_modifier_proc = proc do |output, complete:|
unless output.strip.empty?
cmd = output.split(/\s/, 2).first

if DEBUGGER__.commands.key?(cmd)
output = output.sub(/\n$/, " # debug command\n")
end
end

irb_output_modifier_proc.call(output, complete: complete)
end

@output_modifier_defined = true
end

true
end

Expand Down
42 changes: 42 additions & 0 deletions test/irb/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,48 @@ def test_pager_page_content_doesnt_page_output_when_it_fits_in_the_screen
assert_match(/foobar/, screen)
end

def test_debug_integration_hints_debugger_commands
write_irbrc <<~'LINES'
IRB.conf[:USE_COLORIZE] = false
LINES
script = Tempfile.create(["debug", ".rb"])
script.write <<~RUBY
puts 'start IRB'
binding.irb
RUBY
script.close
start_terminal(40, 80, %W{ruby -I#{@pwd}/lib #{script.to_path}}, startup_message: 'start IRB')
write("debug\n")
write("n")
close

screen = result.join("\n").sub(/\n*\z/, "\n")
assert_include(screen, "irb:rdbg(main):002> n # debug command")
ensure
File.unlink(script) if script
end

def test_debug_integration_doesnt_hint_non_debugger_commands
write_irbrc <<~'LINES'
IRB.conf[:USE_COLORIZE] = false
LINES
script = Tempfile.create(["debug", ".rb"])
script.write <<~RUBY
puts 'start IRB'
binding.irb
RUBY
script.close
start_terminal(40, 80, %W{ruby -I#{@pwd}/lib #{script.to_path}}, startup_message: 'start IRB')
write("debug\n")
write("foo")
close

screen = result.join("\n").sub(/\n*\z/, "\n")
assert_include(screen, "irb:rdbg(main):002> foo\n")
ensure
File.unlink(script) if script
end

private

def write_irbrc(content)
Expand Down