Commit graph

14675 commits

Author SHA1 Message Date
tomoya ishida
ff599aea7c [ruby/irb] Fix % escape in prompt format
(https://github.com/ruby/irb/pull/927)

08eee25d28
2024-04-18 14:46:55 +00:00
Lorenzo Zabot
2e978c2cb3 [ruby/irb] Prompt specifiers documentation improvements
(https://github.com/ruby/irb/pull/926)

e8ea8f253d
2024-04-18 10:33:23 +00:00
David Rodriguez
bc652d7568
[rubygems/rubygems] Never write credentials to lockfiles
e8a363713e
2024-04-18 11:07:09 +09:00
Kenichi Kamiya
a3b7a7bc21
[ruby/reline] Remove unused variable
(https://github.com/ruby/reline/pull/684)

ce30c23730
2024-04-18 11:07:09 +09:00
Nobuyoshi Nakada
0f1ef19fcd
[ruby/optparse] Fix typo [ci skip]
0aec9adfc5
2024-04-18 10:27:19 +09:00
Nobuyoshi Nakada
88a88b56c7
[ruby/optparse] [DOC] Package files for RDoc
b49cb996af
2024-04-18 10:27:19 +09:00
Ben Fritsch
6ac8f6a10e
[ruby/ipaddr] Add IPAddr.cidr to return ip address in cidr notation
f5b006741f
2024-04-18 10:27:19 +09:00
ParadoxV5
48846d6b8d add #2709’s new RBIs to .gemspec 2024-04-17 20:45:25 +00:00
tomoya ishida
ca764062b0 [ruby/irb] Remove internal-only methods from Command::Base
(https://github.com/ruby/irb/pull/922)

* Remove internal-only methods from Command::Base

Command#ruby_args and Command#unwrap_string_literal are used for default command's argument backward compatibility.
Moved these methods to another module to avoid being used from custom commands.

* Update lib/irb/command/edit.rb

---------

7405a841e8

Co-authored-by: Stan Lo <stan001212@gmail.com>
2024-04-17 18:36:30 +00:00
Mike Dalessio
98c84ef42c [rubygems/rubygems] Excluding local platform from lockfile should not affect musl vs gnu case
This case is for not locking things like `arm-darwin-23` when the
lockfile already includes `arm-darwin`, so that we don't infinitely keep
redundant versioned platforms in the lockfile when not necessary.

We detect this with `Gem::Platform#===`. For example,
`Gem::Platform.new("arm-darwin-23") === Gem::Platform.new("arm-darwin")`
but they're not `==`.

However, in the case of `-musl` vs `-gnu`, those act as the platform
"version", but `===` is not commutative for them. This is explained in
`===` docs.

We only want to exclude the local platform in situations when
`Gem::Platform#===` is actually commutative.

8099c4face
2024-04-17 18:17:12 +00:00
Kevin Newton
d186eb36a4 [ruby/prism] Add a reflection API for determining the fields of a node
f3f9950a74
2024-04-17 13:54:29 -04:00
tomoya ishida
15b659ca93 [ruby/reline] Refactor nomultiline and multiline mode difference
(https://github.com/ruby/reline/pull/653)

* Support multiline input in Reline.readline internally, reduce multiline-singleline branch

* Add readline(singleline) prompt test with force inserting multiline text

97846095d7
2024-04-17 16:12:20 +00:00
Kevin Newton
f72436f835 [ruby/prism] Inline pm_state_stack 2024-04-17 10:36:52 -04:00
Nobuyoshi Nakada
09638741ba [Feature #20335] Thread.each_caller_location arguments
Accecpt the same arguments as `caller` and `caller_locations`.
2024-04-17 18:47:07 +09:00
tomoya ishida
79df0f135e [ruby/reline] Refactor history move and history search
(https://github.com/ruby/reline/pull/651)

90e43e01d4
2024-04-16 14:06:22 +00:00
Mari Imaizumi
8e341d81c9 [ruby/reline] Bump version to 0.5.2
(https://github.com/ruby/reline/pull/682)

17d12cc511
2024-04-16 12:42:57 +00:00
Mari Imaizumi
639449fe8d [ruby/reline] Implement changing editing mode
(https://github.com/ruby/reline/pull/681)

501b9a6c5f
2024-04-16 11:58:49 +00:00
Mari Imaizumi
0a4e3f23e6 [ruby/reline] Remove not implemented method
(https://github.com/ruby/reline/pull/680)

84762fc588
2024-04-15 13:31:38 +00:00
tomoya ishida
43f4da3ebf [ruby/reline] Fix vi_to_column which was broken
(https://github.com/ruby/reline/pull/679)

9e93ad52e7
2024-04-15 13:15:58 +00:00
Nobuyoshi Nakada
fc363944b4 [ruby/optparse] bump up to 0.5.0
f5018a8b1c
2024-04-15 05:06:46 +00:00
Koichi Sasada
9180e33ca3 show warning for unused block
With verbopse mode (-w), the interpreter shows a warning if
a block is passed to a method which does not use the given block.

Warning on:

* the invoked method is written in C
* the invoked method is not `initialize`
* not invoked with `super`
* the first time on the call-site with the invoked method
  (`obj.foo{}` will be warned once if `foo` is same method)

[Feature #15554]

`Primitive.attr! :use_block` is introduced to declare that primitive
functions (written in C) will use passed block.

For minitest, test needs some tweak, so use
ea9caafc07
for `test-bundled-gems`.
2024-04-15 12:08:07 +09:00
Mari Imaizumi
339128b190 [ruby/reline] Refactored Default Key Bindings
(https://github.com/ruby/reline/pull/678)

* Reduce duplicate method

* Configured default key mapping with Readline when the method exists

* Remove undefined methods

155f7047bb
2024-04-14 17:33:51 +00:00
tomoya ishida
1648c4436e [ruby/reline] Refactor waiting_proc and waiting_operator_proc
(https://github.com/ruby/reline/pull/649)

* Fix waiting_proc precedence

* Fix waiting_operator bugs

* Add waiting_proc and vi_waiting_operator test

* Fix vi waiting operator arg number

vi_arg and vi_waiting_operator_arg should be multiplied

* Implement `yy` copies whole line in vi_command mode

* Simplify incremental search cancel test

* Add complex vi test with waiting_proc and vi_waiting_operator, split test input

777dffae1c
2024-04-14 14:28:15 +00:00
Stan Lo
04ba96e619 [ruby/irb] Allow defining custom commands in IRB
(https://github.com/ruby/irb/pull/886)

This is a feature that has been requested for a long time. It is now
possible to define custom commands in IRB.

Example usage:

```ruby
require "irb/command"

class HelloCommand < IRB::Command::Base
  description "Prints hello world"
  category "My commands"
  help_message "It doesn't do more than printing hello world."

  def execute
    puts "Hello world"
  end
end

IRB::Command.register(:hello, HelloCommand)
```

888643467c
2024-04-14 11:01:43 +00:00
Michael J. Giarlo
76b10f2ee1 [ruby/reline] Support menu-complete-backward command for upward
navigation
(https://github.com/ruby/reline/pull/677)

Fixes https://github.com/ruby/reline/pull/675

This commit extracts the upward navigation condition in `LineEditor#input_key` to a new private method, and adds a new alias. This change allows Reline to support upward navigation in when a user has configured `inputrc` to map Shift-Tab to `menu-complete-backward`, a common setting in Bash (>= 4.x).

Instead of special-casing upward navigation in `LineEditor#input_key`, we now allow it to be processed by the branch that calls `process_key`. The extracted method no longer includes the editing mode check since this check is already made by `#wrap_method_call` by the time `#completion_journey_up` (or `#menu_complete_backward`) is called. Since upward navigation is happening in a method other than `#input_key` now, the `completion_occurs` variable that used to be local to `#input_key` is changed to an instance variable so that the new method can change its value. (I see many examples of mutating such instance variables in `LineEditor`, so I assumed this would be an uncontroversial change consistent with the coding practices already in place.)

Test coverage of this change has been added to the emacs and vi `KeyActor` tests.

Many thanks to @ima1zumi for their very helpful comments on #675 which encouraged me to contribute this work!

2ccdb374a4
2024-04-14 09:13:20 +00:00
Stan Lo
0924ff2d39 [ruby/prism] Fix parser translation's heredoc whitespace calculation
Given this example:

```rb
<<~HEREDOC
  #{x}
HEREDOC
```

Both the parser gem and Prism's translation layer would generate the following AST:

```
s(:dstr,
  s(:begin,
    s(:int, 1)),
  s(:str, " a\n"))
```

However, the parser gem inserts a empty string node into this node's location, like:

```
<Parser::Source::Map::Heredoc:0x0000000104ce73b8
 @expression=#<Parser::Source::Range (string) 0...10>,
 @heredoc_body=#<Parser::Source::Range (string) 11...20>,
 @heredoc_end=#<Parser::Source::Range (string) 20...27>,
 @node=s(:dstr,
  s(:str, ""),
  s(:begin,
    s(:int, 1)),
  s(:str, " a\n"))>
```

This is required to calculate the correct whitespace for the heredoc body.

We need to adjust the translation layer to account for this.

With this fix, we also won't need to ignore the tilde heredoc fixture anymore.

e7372e3ba5
2024-04-12 13:55:35 +00:00
David Marshall
a64a42ae38 [rubygems/rubygems] bundle add --glob continued- quote glob value invocation in specs, add banner text for CLI recommending single quotes
6d2cf955f9
2024-04-12 13:31:43 +00:00
David Marshall
c4b5f3f142 [rubygems/rubygems] bundler CLI option for add gem --glob=
Bundler online documentation says that if the gem is located within a subdirectory of a git repository,
you can use the `:glob` option to specify the location of its .gemspec

`gem 'cf-copilot', git: 'https://github.com/cloudfoundry/copilot', glob: 'sdk/ruby/*.gemspec'`

This change allows for equivalent functionality from the bundler CLI

`bundle add cf-copilot --git=https://github.com/cloudfoundry/copilot --glob=sdk/ruby/*.gemspec`

91052e5868
2024-04-12 13:31:43 +00:00
Stan Lo
f1d9e895b9 [ruby/irb] Pass statements to Context#evaluate
(https://github.com/ruby/irb/pull/920)

This has a few benefits:

- We can keep hiding the evaluation logic inside the Context level, which
  has always been the convention until #824 was merged recently.
- Although not an official API, gems like `debug` and `mission_control-jobs`
  patch `Context#evaluate` to wrap their own logic around it. This implicit
  contract was broken after #824, and this change restores it.

In addition to the refactor, I also converted some context-level evaluation
tests into integration tests, which are more robust and easier to maintain.

b32aee4068
2024-04-12 12:01:03 +00:00
Cody Cutrer
c5e661b1d7 [rubygems/rubygems] Fix installing plugins via relative paths
This affected both CLI and Gemfile installs

a0d101a8df
2024-04-11 19:35:28 +00:00
Kevin Newton
cd516ebd20 [ruby/prism] Add Location#chop
5dd57f4b84
2024-04-11 18:53:30 +00:00
Stan Lo
38e3819be6 [ruby/irb] Add a workaround to make IRB work with debug's tests
(https://github.com/ruby/irb/pull/919)

eb442c4dda
2024-04-10 23:16:32 +00:00
Stan Lo
d75dc39880 [ruby/irb] Centralize rstrip calls
(https://github.com/ruby/irb/pull/918)

97898b6251
2024-04-10 17:33:44 +00:00
tomoya ishida
6a505d1b59 [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 <stan001212@gmail.com>

---------

8fb776e379

Co-authored-by: Stan Lo <stan001212@gmail.com>
2024-04-10 16:52:53 +00:00
Taketo Takashima
f9f25d0ed0 [ruby/ipaddr] Added IPAddr#wildcard_mask
2093cebc1d
2024-04-10 10:30:53 +00:00
Mari Imaizumi
6846b98576 [ruby/reline] Bump version to 0.5.1
(https://github.com/ruby/reline/pull/672)

d348df90d2
2024-04-09 13:47:23 +00:00
Nobuyoshi Nakada
8217fbf4bd [ruby/tmpdir] Display the offending parent path in the exception
7751b12e97
2024-04-08 11:05:40 +00:00
Masataka Pocke Kuwabara
76914d474d Fix error when default gem is loaded from -r option
This patch fixes an error when a default gem that will be migrated to
a bundled gem is loaded from `-r` option.

Problem
===

`bundle exec ruby -rostruct -e ''` unexpectedly raises the following error:

```console
$ ruby -v
ruby 3.4.0dev (2024-04-08T02:39:00Z master 6f7e8e278f) [arm64-darwin21]
$ bundle init && bundle install
$ bundle exec ruby -rostruct -e ''
/Users/kuwabara.masataka/.rbenv/versions/trunk/lib/ruby/3.4.0+0/bundled_gems.rb:111:in 'Gem::BUNDLED_GEMS.warning?': undefined method 'find' for nil (NoMethodError)

      caller = caller_locations(3, 3).find {|c| c&.absolute_path}
                                     ^^^^^
        from /Users/kuwabara.masataka/.rbenv/versions/trunk/lib/ruby/3.4.0+0/bundled_gems.rb:75:in 'block (2 levels) in Kernel#replace_require'
```

Solution
===

This patch uses a safe navigation operator to fix this problem. By this
change, the command will show the warning message correctly.

```console
$ bundle exec ruby -rostruct -e ''
warning: ostruct was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0. Add ostruct to your Gemfile or gemspec.
```
2024-04-08 15:48:26 +09:00
Mari Imaizumi
c2d02a6ac2 [ruby/reline] Continue processing even if terminfo database couldn't
be found
(https://github.com/ruby/reline/pull/673)

Fix https://github.com/ruby/reline/issues/447 https://github.com/ruby/reline/issues/543

This problem occurs when Fiddle can be loaded, curses can be loaded, and TERM is not registered in Terminfo.
It should also occur at hardcopy terminals and when Terminfo information is low, but no such reports have been received.

Reline should not abort the process because of missing Terminfo.
Reline proceeds with `Reline::Terminfo.enabled? == false` when fiddle or curses cannot be loaded.
And does the same when Terminfo is present but TERM is not.
ebab2875f1/lib/reline/terminfo.rb (L156-L160)

You can check the operation with `TERM=foo bundle exec bin/console`.

4ce247ce2b
2024-04-06 09:24:53 +00:00
Kevin Newton
f2ac26d914 [ruby/prism] Bump to v0.25.0
4da514456f
2024-04-05 21:44:06 +00:00
Joshua Broughton
f87e60f1f4 [ruby/irb] Filter backtrace before format in handle_exception
(https://github.com/ruby/irb/pull/916)

handle_exception now applies the filter_backtrace to exception
backtraces prior to formatting the lines with Exception#full_message

This fixes a bug in upstream projects, notably Rails, where the
backtrace filtering logic expects the lines to be formatted as
Exception#backtrace.

805ee008f9

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
2024-04-05 16:25:52 +00:00
tomoya ishida
4e48d2724e
[ruby/reline] Thread safe readline
(https://github.com/ruby/reline/pull/669)

Block until other Reline.readline or Reline.readmultiline finish

ebab2875f1
2024-04-05 09:34:28 +09:00
tomoya ishida
4cbe4e49c7
[ruby/reline] Always call finalize and deprep
(https://github.com/ruby/reline/pull/668)

91b030caa4
2024-04-05 09:34:28 +09:00
Kevin Newton
f45c9dbe87 [ruby/prism] Fix up some comments in the parser compiler
e2147cddd8
2024-04-04 15:29:10 -04:00
tomoya ishida
8088c88d01
[ruby/reline] Handle INT signal correctly, remove handle_cleared
because clear(C-l) is not a signal
(https://github.com/ruby/reline/pull/646)

3debb0ae2f
2024-04-04 17:18:47 +09:00
tomoya ishida
80e31663f3
[ruby/reline] Fix audoindent including "\v", escape "\v" for
rendering
(https://github.com/ruby/reline/pull/648)

9c51c577ca
2024-04-04 17:18:47 +09:00
Hiroshi SHIBATA
0930231361 [rubygems/rubygems] Allow to use String keys some of configuration
ee0bef2786
2024-04-04 11:30:02 +09:00
Hiroshi SHIBATA
0be7133b7f [rubygems/rubygems] Re-order configuraiton keys
b2a88983db
2024-04-04 11:30:01 +09:00
Hiroshi SHIBATA
25e28559c1 Ignore warnings on the bundled gems repo 2024-04-03 18:07:31 +09:00
Hiroshi SHIBATA
e651395210 Warn pstore for Ruby 3.5 2024-04-02 18:34:10 +09:00