Completion of require_relative path is wrong when `Dir.pwd != __dir__`

Open
#766 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
ruby
Domain
cli

Research direction

Reproduce the issue with main.rb and foo/foobar.rb, then trace IRB's require_relative completion behavior while Dir.pwd differs from dir. Verify the completion uses the directory of the loaded file and produces 'foobar rather than 'foo/foobar.

Written by the indexing model from the issue text.

Description

Description

Prepare these directory and files

$ mkdir foo
$ echo binding.irb > foo/foobar.rb
$ echo "require'./foo/foobar.rb'" > main.rb

Then execute ruby main.rb

$ ruby main.rb
From: /Users/tomoya.ishida/Desktop/tmp/foo/bar.rb @ line 1 :

 => 1: binding.irb

irb(main):002> require_relative 'f
                                'foo/foobar

The completion should be 'foobar, not 'foo/foobar.
require_relative will load relative path from __dir__, not from pwd.

Result of irb_info

Ruby version: 3.2.2
IRB version: irb 1.9.0 (2023-11-11)
InputMethod: RelineInputMethod with Reline 0.4.0
Completion: Autocomplete, RegexpCompletor
RUBY_PLATFORM: arm64-darwin22
LANG env: ja_JP.UTF-8
East Asian Ambiguous Width: 1

Terminal Emulator

Terminal.app

Setting Files

No

Dominant language
Ruby
Stars
477
Forks
165
Avg merge
1d 19h
Merged PRs (30d)
5

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ruby/irb

All issues in ruby/irb

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.