Rename of a class moves its file and leaves require_relative on the old path
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 22/100
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.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.
- Lingua principale
- Ruby
- Stelle
- 2k
- Fork
- 284
- Merge medio
- 11h 11m
- PR unite (30g)
- 10
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Shopify/ruby-lsp
-
Dependencies view: `getParent` loops forever on untitled documents, extension host runs out of memoryForse già presa @efegokdemir l’ha presa 1 giorno fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
Linux file system with square brackets in the directory/filename are failing to be indexedForse già presa @andriytyurnikov l’ha presa 205 giorni fa. Apertabug help-wanted pinned
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Shopify/ruby-lsp#3503 · 8 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Paths need to be escapedForse già presa @Vraiment l’ha presa 6 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 25/100
I maintainer di solito rispondono entro 1 giorno
-
check-labels intermittently fails due to the organization IP allow listForse già presa @soutaro l’ha presa 9 giorni fa. Aperta
Shopify/ruby-lsp#4219 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
'Kernel#require': cannot load such file -- bundler (LoadError)Forse già presa @efegokdemir l’ha presa 1 giorno fa. Apertabug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 38/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di Shopify/ruby-lsp
Issue simili
-
area/web interface
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
mastodon/mastodon#41009 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
yegor256/ellipsized#131 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100