Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Rename of a class moves its file and leaves require_relative on the old path

Aperta
#4,226 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@efegokdemir ci sta già lavorando.

Dal 8/10/2026.

  • #4227 di @efegokdemir — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
22/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
ruby
Ambito
tooling

Direzione di ricerca

Start with collect_file_renames in lib/ruby_lsp/requests/rename.rb, which adds the file move for a renamed constant, and reproduce with the two files lib/store.rb and lib/use.rb from the report. Check PR #4227 and #3639 first, since a fix is already open and the double move is a separate cause. Done means the rename reply either updates require_relative "store" or does not move the file, and the program still prints 2.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Ruby LSP Information
  • ruby-lsp 0.26.11 from the Homebrew formula, with Ruby 4.0.7 and Bundler 4.0.20 on Linux x86_64.
  • The client is a script that speaks LSP over stdio. It declares workspace.workspaceEdit.documentChanges and the resource operations create, rename and delete, and it applies the documentChanges of a reply in order.
  • The workspace has a Gemfile without gems, its Gemfile.lock, and two files.

lib/store.rb:

# Store keeps a count.
class Store
  attr_accessor :count

  def initialize
    @count = 0
  end

  # get returns the count.
  def get
    @count
  end

  # make returns a store with a count of two.
  def self.make
    s = Store.new
    s.count += 2
    s
  end
end

lib/use.rb:

require_relative "store"

# use returns the count of a new store.
def use
  Store.make.get
end

Before the rename, ruby -e 'require_relative "lib/use"; puts use' prints 2.

Reproduction steps
  1. Start ruby-lsp in the workspace, and wait until the progress "Ruby LSP: indexing files" ends.
  2. Open lib/store.rb and lib/use.rb.
  3. Send textDocument/prepareRename and then textDocument/rename to Shop, at line 1, character 6 of lib/store.rb, counted from zero.
  4. Apply the documentChanges of the reply, and run ruby -e 'require_relative "lib/use"; puts use'.

The reply rewrites Store at lines 2 and 16 of lib/store.rb and at line 5 of lib/use.rb, and ends with the move of the file:

{"kind": "rename", "oldUri": "file:///.../lib/store.rb", "newUri": "file:///.../lib/shop.rb"}

It leaves require_relative "store" at line 1 of lib/use.rb as it is, so the program no longer loads.

Code snippet or error message

.../lib/use.rb:1:in 'Kernel#require_relative': cannot load such file -- .../lib/store (LoadError)
	from .../lib/use.rb:1:in '<top (required)>'
	from -e:1:in 'Kernel#require_relative'
	from -e:1:in '<main>'

With the require changed to "shop" by hand, the command prints 2 again.

Cause

collect_file_renames in lib/ruby_lsp/requests/rename.rb adds the move of each file whose name matches the constant. No part of the rename edits a require_relative or a require of the moved file. The rename of 0.27.0.beta5, which uses Rubydex, has the same collect_file_renames.

The documentation of rename states that it renames "all occurrences of the entity under the cursor across the entire project". It does not mention the move of the file.

A documentSymbol request for lib/store.rb during the indexing job also makes the reply move the file twice, which #3639 explains. The second move fails, because the first one has already moved the file.

Lingua principale
Ruby
Stelle
2k
Fork
284
Merge medio
11h 11m
PR unite (30g)
10

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Shopify/ruby-lsp

Tutte le issue di Shopify/ruby-lsp

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.