Skip to content

Make sure last LSP client is disconnected before creating a new one. #912

Open
jstraceski wants to merge 3 commits intogodotengine:masterfrom
jstraceski:godot_reload_fix
Open

Make sure last LSP client is disconnected before creating a new one. #912
jstraceski wants to merge 3 commits intogodotengine:masterfrom
jstraceski:godot_reload_fix

Conversation

@jstraceski
Copy link
Contributor

The LSP client seems to have left over resources when restarting godot.
This causes CTRL-hover to fail after restarting godot because multiple textDocument/definition requests are sent.

Steps to reproduce issue:

  1. Open vscode extension.
  2. Open godot project.
  3. Within the vscode window CTRL-Click any object.
  4. Close + reopen godot.
  5. Within the vscode window CTRL-Click any object.

If you have a debuging window open you should see rx/tx similar to this:

[lsp.io] tx: {jsonrpc: '2.0', id: 4, method: 'textDocument/hover', params: {…}}
logger.ts:70
[lsp.io] tx: {jsonrpc: '2.0', id: 22, method: 'textDocument/hover', params: {…}}
logger.ts:70
[lsp.io] rx: {id: 4, jsonrpc: '2.0', result: {…}}
logger.ts:70
[lsp.io] tx: {jsonrpc: '2.0', method: '$/cancelRequest', params: {…}}
logger.ts:70
[lsp.io] tx: {jsonrpc: '2.0', id: 5, method: 'textDocument/definition', params: {…}}
logger.ts:70
[lsp.io] tx: {jsonrpc: '2.0', id: 23, method: 'textDocument/definition', params: {…}}
logger.ts:70
[lsp.io] tx: {jsonrpc: '2.0', id: 6, method: 'textDocument/hover', params: {…}}
logger.ts:70
[lsp.io] tx: {jsonrpc: '2.0', method: '$/cancelRequest', params: {…}}
logger.ts:70

This change disconnects io functions, and stops the last valid LSP client before making a new client.

(I did test this on godot > 4.5 but I have made some local changes so there is a chance that it is not required under the current stable godot version.)

@HolonProduction
Copy link
Member

Could you check whether your original issue was solved by #968

This PR looks alright as safeguard. But in concept create_new_client should only be called when the old client is in a state were it is disconnected and will never reconnect.

@Calinou Calinou added the bug label Feb 3, 2026
@Nallebeorn
Copy link

I tested a build of this branch, and it seems to fix #978. At least with the repro steps of restarting Godot that are described in the comments.

@Calinou
Copy link
Member

Calinou commented Feb 25, 2026

@HolonProduction Do you think this is safe to merge? If so, I can merge it and tag 2.6.2.

@HolonProduction
Copy link
Member

The client?.stop part makes sense to me. While client client.io is public, it really should be a private member and cleaning it up at this place breaks encapsulation to me.

I verified that just the client?.stop part fixes #978 it probably contains some code to unregister the client with VSCode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants