Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Improve the break command support
  • Loading branch information
k0kubun committed Nov 19, 2022
commit e262fc277a0f6a614fa11857624fdd2d0915ef21
8 changes: 6 additions & 2 deletions lib/irb/cmd/break.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ module IRB

module ExtendCommand
class Break < Debug
def execute(*args)
super(['break', *args].join(' '))
def self.transform_args(args)
args&.dump
end

def execute(args = nil)
super(pre_cmds: "break #{args}")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/irb/cmd/continue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module IRB
module ExtendCommand
class Continue < Debug
def execute(*args)
super(['continue', *args].join(' '))
super(do_cmds: ["continue", *args].join(" "))
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/irb/cmd/debug.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Debug < Nop
].map { |file| /\A#{Regexp.escape(file)}:\d+:in `irb'\z/ }
IRB_DIR = File.expand_path('..', __dir__)

def execute(debug_command = nil)
def execute(pre_cmds: nil, do_cmds: nil)
unless binding_irb?
puts "`debug` command is only available when IRB is started with binding.irb"
return
Expand All @@ -26,8 +26,8 @@ def execute(debug_command = nil)
end

command = nil
if debug_command
command = ['irb', nil, debug_command]
if pre_cmds || do_cmds
command = ['irb', pre_cmds, do_cmds]
end

# To make debugger commands like `next` or `continue` work without asking
Expand Down
2 changes: 1 addition & 1 deletion lib/irb/cmd/finish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module IRB
module ExtendCommand
class Finish < Debug
def execute(*args)
super(['finish', *args].join(' '))
super(do_cmds: ["finish", *args].join(" "))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/irb/cmd/next.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module IRB
module ExtendCommand
class Next < Debug
def execute(*args)
super(['next', *args].join(' '))
super(do_cmds: ["next", *args].join(" "))
end
end
end
Expand Down
8 changes: 7 additions & 1 deletion lib/irb/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -545,10 +545,16 @@ def local_variables # :nodoc:
workspace.binding.local_variables
end

# Return a command name if it's aliased from the argument and it's not an identifier.
# Return true if it's aliased from the argument and it's not an identifier.
def symbol_alias?(command)
return nil if command.match?(/\A\w+\z/)
command_aliases.key?(command.to_sym)
end

# Return true if the command supports transforming args
def transform_args?(command)
command = command_aliases.fetch(command.to_sym, command)
ExtendCommandBundle.load_command(command)&.respond_to?(:transform_args)
end
end
end
4 changes: 2 additions & 2 deletions lib/irb/ruby-lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ def set_input(io, p = nil, context:, &block)
false
end
else
# Accept any single-line input starting with a non-identifier alias (ex: @, $)
# Accept any single-line input for symbol aliases or commands that transform args
command = code.split(/\s/, 2).first
if context.symbol_alias?(command)
if context.symbol_alias?(command) || context.transform_args?(command)
next true
end

Expand Down