You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A moved or renamed document is connected again to a language server that no longer matches it #1914
When a file whose document is connected is renamed or moved, the language server gets the document again at the new place, even if the file no longer matches it there. A connected test.foo, of a language server for *.foo files, that is renamed to test.txt stays open on that language server, although a request for test.txt then matches no language server.
How it happens
LSPFileListener.onFileRenameAfter disconnects the document of the earlier place and calls reconnectMovedDocument, which connects the file to a language server of the same definition (for a definition with instances, the instance chosen for the new place). Nothing checks that the definition still matches the file: its mappings (file type, language, file name patterns and document matchers) and the client features' isEnabled(file).
A test on main renames a connected test.foo to test.txt: the language server still synchronizes the file afterwards, while getLanguageServers finds no language server for it.
#1911 reuses that reconnect for a document that the move of its file missed, and for an open file whose connection dropped because the file moved. Its third fix asks again through a request instead, which matches the file again.
Possible fix
Match the file again before connecting it at its new place, for example by connecting it through a request for the definition, as the third fix of #1911 does with getLanguageServers(psiFile, null, null, serverDefinition). That also checks isEnabled() and the client features. For a definition that matches asynchronously, that request needs the fix of #1913 first.
I've reproduced it on main (18f9d5e): a test renames a connected test.foo to test.txt, and the language server for *.foo files opens it again. I'll connect a moved document through a request for its definition, as you suggest, once #1915 and #1911 are in, as it needs the asynchronous matching of #1915 and changes the same places as #1911.
If I don't get to it today, I can only go on with this and with #1911 on Friday, as I'm at a conference from tomorrow.
@d-biehl, #1911 is merged (2253ca0), so the switch you planned there can come with this one: once #1915 is in, the second request for a moved file in askAgainForTheInstanceOf can ask for its definition only, as getLanguageServers(psiFile, null, null, serverDefinition), which then takes a definition that matches the file asynchronously too, in place of the ordinary request that its before-starting filter keeps to the definition. That also ends the retries for other definitions that CodeRabbit asked about in #1911. The race with a scoped connection in its cleanup stays as we left it in its thread, and can be looked at again when the reconnection of a moved document goes through a request here.
Activity
d-biehl commentedon Nov 9, 2026
I've reproduced it on main (18f9d5e): a test renames a connected
test.foototest.txt, and the language server for*.foofiles opens it again. I'll connect a moved document through a request for its definition, as you suggest, once #1915 and #1911 are in, as it needs the asynchronous matching of #1915 and changes the same places as #1911.If I don't get to it today, I can only go on with this and with #1911 on Friday, as I'm at a conference from tomorrow.
lagergren commentedon Nov 9, 2026
@d-biehl, #1911 is merged (2253ca0), so the switch you planned there can come with this one: once #1915 is in, the second request for a moved file in
askAgainForTheInstanceOfcan ask for its definition only, asgetLanguageServers(psiFile, null, null, serverDefinition), which then takes a definition that matches the file asynchronously too, in place of the ordinary request that its before-starting filter keeps to the definition. That also ends the retries for other definitions that CodeRabbit asked about in #1911. The race with a scoped connection in its cleanup stays as we left it in its thread, and can be looked at again when the reconnection of a moved document goes through a request here.