Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto
#4,226 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@efegokdemir ya está trabajando en esto.

Desde el 8/10/2026.

  • #4227 de @efegokdemir — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
22/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
ruby
Área
tooling

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Ruby
Estrellas
2k
Forks
284
Merge medio
11 h 11 min
PR fusionados (30 d)
10

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Shopify/ruby-lsp

Todos los issues de Shopify/ruby-lsp

Issues similares

Más issues de Ruby

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.