Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into ha/allow-multiple…
Browse files Browse the repository at this point in the history
…-irbrb-files
  • Loading branch information
hahmed committed Feb 19, 2024
2 parents 4885d71 + ee83068 commit 09e4c67
Show file tree
Hide file tree
Showing 68 changed files with 1,280 additions and 592 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@ jobs:
with:
engine: cruby-truffleruby
min_version: 2.7

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler-cache: true
- name: Run rubocop
run: bundle exec rubocop
irb:
needs: ruby-versions
name: rake test ${{ matrix.ruby }} ${{ matrix.with_latest_reline && '(latest reline)' || '' }}
Expand Down
32 changes: 32 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
AllCops:
TargetRubyVersion: 3.0
DisabledByDefault: true
SuggestExtensions: false

Layout/TrailingWhitespace:
Enabled: true

Layout/TrailingEmptyLines:
Enabled: true

Layout/IndentationConsistency:
Enabled: true

Layout/CaseIndentation:
Enabled: true
EnforcedStyle: end

Layout/CommentIndentation:
Enabled: true

Layout/IndentationStyle:
Enabled: true

Layout/SpaceAroundKeyword:
Enabled: true

Layout/SpaceBeforeComma:
Enabled: true

Layout/SpaceAfterComma:
Enabled: true
2 changes: 1 addition & 1 deletion COMPARED_WITH_PRY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Feel free to chip in and update this table - we appreciate your help!
| Supported Rubies | `>= 2.0` | `>= 2.7` | |
| Source code browsing | `show-source` | `show_source` | IRB's `show_source` can't display C source. See [#664](https://github.com/ruby/irb/issues/664) |
| Document browsing | `ri` | `show_doc` | |
| Live help system | `help` or `command_name --help` | `show_cmds` | IRB doesn't support detailed descriptions for individual commands yet |
| Live help system | `help` or `command_name --help` | `help` | IRB doesn't support detailed descriptions for individual commands yet |
| Open methods in editors | `edit` | `edit` | |
| Syntax highlighting | Yes | Yes | |
| Command shell integration | Yes | No | Currently, there's no plan to support such features in IRB |
Expand Down
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ gem "rake"
gem "test-unit"
gem "test-unit-ruby-core"

gem "rubocop"

gem "tracer" if !is_truffleruby
gem "debug", github: "ruby/debug", platforms: [:mri, :mswin]

if RUBY_VERSION >= "3.0.0" && !is_truffleruby
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,19 @@ Hello World

## Commands

The following commands are available on IRB. You can get the same output from the `show_cmds` command.
The following commands are available on IRB. You can get the same output from the `help` command.

```txt
Help
help List all available commands. Use `help <command>` to get information about a specific command.
IRB
exit Exit the current irb session.
exit! Exit the current process.
irb_load Load a Ruby file.
irb_require Require a Ruby file.
source Loads a given file in the current session.
irb_info Show information about IRB.
show_cmds List all available commands and their description.
history Shows the input history. `-g [query]` or `-G [query]` allows you to filter the output.
Workspace
Expand Down Expand Up @@ -145,13 +148,12 @@ Debugging
info Start the debugger of debug.gem and run its `info` command.
Misc
edit Open a file with the editor command defined with `ENV["VISUAL"]` or `ENV["EDITOR"]`.
edit Open a file or source location.
measure `measure` enables the mode to measure processing time. `measure :off` disables it.
Context
help [DEPRECATED] Enter the mode to look up RI documents.
show_doc Enter the mode to look up RI documents.
ls Show methods, constants, and variables. `-g [query]` or `-G [query]` allows you to filter out the output.
ls Show methods, constants, and variables.
show_source Show the source code of a given method or constant.
whereami Show the source code around binding.irb again.
Expand Down Expand Up @@ -227,7 +229,7 @@ end

To learn about these features, please refer to `debug.gem`'s [commands list](https://github.com/ruby/debug#debug-command-on-the-debug-console).

In the `irb:rdbg` session, the `show_cmds` command will also display all commands from `debug.gem`.
In the `irb:rdbg` session, the `help` command will also display all commands from `debug.gem`.

### Advantages Over `debug.gem`'s Console

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ task :test_in_isolation do
ENV["TEST"] = test_file
begin
Rake::Task["test"].execute
rescue => e
rescue
failed = true
msg = "Test '#{test_file}' failed when being executed in isolation. Please make sure 'rake test TEST=#{test_file}' passes."
separation_line = '=' * msg.length
Expand Down
29 changes: 19 additions & 10 deletions lib/irb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

require_relative "irb/init"
require_relative "irb/context"
require_relative "irb/extend-command"
require_relative "irb/command"

require_relative "irb/ruby-lex"
require_relative "irb/statement"
Expand Down Expand Up @@ -811,7 +811,7 @@
#
# === Commands
#
# Please use the `show_cmds` command to see the list of available commands.
# Please use the `help` command to see the list of available commands.
#
# === IRB Sessions
#
Expand Down Expand Up @@ -886,7 +886,7 @@ def IRB.start(ap_path = nil)

# Quits irb
def IRB.irb_exit(*)
throw :IRB_EXIT
throw :IRB_EXIT, false
end

# Aborts then interrupts irb.
Expand Down Expand Up @@ -979,13 +979,21 @@ def run(conf = IRB.conf)
end

begin
catch(:IRB_EXIT) do
if defined?(RubyVM.keep_script_lines)
keep_script_lines_backup = RubyVM.keep_script_lines
RubyVM.keep_script_lines = true
end

forced_exit = catch(:IRB_EXIT) do
eval_input
end
ensure
RubyVM.keep_script_lines = keep_script_lines_backup if defined?(RubyVM.keep_script_lines)
trap("SIGINT", prev_trap)
conf[:AT_EXIT].each{|hook| hook.call}

context.io.save_history if save_history
Kernel.exit if forced_exit
end
end

Expand Down Expand Up @@ -1074,16 +1082,17 @@ def each_top_level_statement
loop do
code = readmultiline
break unless code

if code != "\n"
yield build_statement(code), @line_no
end
yield build_statement(code), @line_no
@line_no += code.count("\n")
rescue RubyLex::TerminateLineInput
end
end

def build_statement(code)
if code.match?(/\A\n*\z/)
return Statement::EmptyInput.new
end

code.force_encoding(@context.io.encoding)
command_or_alias, arg = code.split(/\s/, 2)
# Transform a non-identifier alias (@, $) or keywords (next, break)
Expand Down Expand Up @@ -1227,7 +1236,7 @@ def handle_exception(exc)
lines.map{ |l| l + "\n" }.join
}
# The "<top (required)>" in "(irb)" may be the top level of IRB so imitate the main object.
message = message.gsub(/\(irb\):(?<num>\d+):in `<(?<frame>top \(required\))>'/) { "(irb):#{$~[:num]}:in `<main>'" }
message = message.gsub(/\(irb\):(?<num>\d+):in (?<open_quote>[`'])<(?<frame>top \(required\))>'/) { "(irb):#{$~[:num]}:in #{$~[:open_quote]}<main>'" }
puts message
puts 'Maybe IRB bug!' if irb_bug
rescue Exception => handler_exc
Expand Down Expand Up @@ -1514,7 +1523,7 @@ class Binding
# See IRB for more information.
def irb(show_code: true)
# Setup IRB with the current file's path and no command line arguments
IRB.setup(source_location[0], argv: [])
IRB.setup(source_location[0], argv: []) unless IRB.initialized?
# Create a new workspace using the current binding
workspace = IRB::WorkSpace.new(self)
# Print the code around the binding if show_code is true
Expand Down
60 changes: 0 additions & 60 deletions lib/irb/cmd/edit.rb

This file was deleted.

23 changes: 0 additions & 23 deletions lib/irb/cmd/help.rb

This file was deleted.

55 changes: 3 additions & 52 deletions lib/irb/cmd/nop.rb
Original file line number Diff line number Diff line change
@@ -1,53 +1,4 @@
# frozen_string_literal: false
#
# nop.rb -
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
#
# frozen_string_literal: true

module IRB
# :stopdoc:

module ExtendCommand
class CommandArgumentError < StandardError; end

class Nop
class << self
def category(category = nil)
@category = category if category
@category
end

def description(description = nil)
@description = description if description
@description
end

private

def string_literal?(args)
sexp = Ripper.sexp(args)
sexp && sexp.size == 2 && sexp.last&.first&.first == :string_literal
end
end

def self.execute(irb_context, *opts, **kwargs, &block)
command = new(irb_context)
command.execute(*opts, **kwargs, &block)
rescue CommandArgumentError => e
puts e.message
end

def initialize(irb_context)
@irb_context = irb_context
end

attr_reader :irb_context

def execute(*opts)
#nop
end
end
end

# :startdoc:
end
# This file is just a placeholder for backward-compatibility.
# Please require 'irb' and inheirt your command from `IRB::Command::Base` instead.
Loading

0 comments on commit 09e4c67

Please sign in to comment.