Rename of a class moves its file and leaves require_relative on the old path
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 22/100
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.documentChangesand the resource operationscreate,renameanddelete, and it applies thedocumentChangesof a reply in order. - The workspace has a
Gemfilewithout gems, itsGemfile.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
- Start ruby-lsp in the workspace, and wait until the progress "Ruby LSP: indexing files" ends.
- Open
lib/store.rbandlib/use.rb. - Send
textDocument/prepareRenameand thentextDocument/renametoShop, at line 1, character 6 oflib/store.rb, counted from zero. - Apply the
documentChangesof the reply, and runruby -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
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Shopify/ruby-lsp
-
Dependencies view: `getParent` loops forever on untitled documents, extension host runs out of memoryPosiblemente ocupada @efegokdemir la tomó hace 2 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
Linux file system with square brackets in the directory/filename are failing to be indexedPosiblemente ocupada @andriytyurnikov la tomó hace 206 días. Abiertobug help-wanted pinned
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Shopify/ruby-lsp#3503 · 8 comentarios · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Paths need to be escapedPosiblemente ocupada @Vraiment la tomó hace 7 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 25/100
Los mantenedores suelen responder en 1 día
-
check-labels intermittently fails due to the organization IP allow listPosiblemente ocupada @soutaro la tomó hace 10 días. Abierto
Shopify/ruby-lsp#4219 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
'Kernel#require': cannot load such file -- bundler (LoadError)Posiblemente ocupada @efegokdemir la tomó hace 2 días. Abiertobug
Dificultad 4/5 3-5 días Aptitud para principiantes 38/100
Los mantenedores suelen responder en 1 día
Todos los issues de Shopify/ruby-lsp
Issues similares
-
documentation
Dificultad 1/5 Menos de una hora Aptitud para principiantes 86/100
bridgetownrb/bridgetown#1130 ·
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
rapid7/metasploit-framework#22008 ·
Los mantenedores suelen responder en 2 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
stripe/stripe-ruby#1994 ·
Los mantenedores suelen responder en 1 día
-
[Fehler]: /abdeckstift wirft 500 — part_type aus der Phonemreduction-Umbenennung nicht mitgezogenAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
wort-schule/wort.schule#787 ·
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
lugassawan/swe-workbench#799 ·
Los mantenedores suelen responder en 1 día