godotengine / godot-vscode-plugin

Godot development tools for VSCode
MIT License
1.47k stars 148 forks source link

Problem with multiple editors open #669

Open TiagoGoddard opened 1 week ago

TiagoGoddard commented 1 week ago

Godot version

4.2.2

VS Code version

1.90.2

Godot Tools VS Code extension version

2.0.0

System information

Windows 11

Issue description

I'm making a multiplayer game using different godot projects (One for the game, one for the server), everything works regarding opening the scripts and etc, but on saving on my second project (server), it attempts to open/reload on the game project, resulting in errors:

 Attempt to open script 'file://<redacted>/server/scenes/gameplay/gameplay.gd' resulted in error 'Can't open file'.
  Failed loading resource: file://<redacted>/server/scenes/gameplay/gameplay.gd. Make sure resources have been imported by opening the project in the editor at least once.

Steps to reproduce

Have separate projects on separate folders, with at least 2 instances of godot running. Attempt to edit/save different scripts from different projects.

DaelonSuzuka commented 1 week ago

I would not recommend opening multiple Godot projects in one VSCode window. Language Server features like errors, go-to definition, etc cannot behave correctly in this situation due the design of the Godot editor and its Language Server.

In this case I believe what's happening is that VSCode is telling the language server that a file's contents have been changed, which causes the Language Server/Godot Editor to reload that file. However, since you have two projects open, VSCode is sending that message to reload FileA, but the LSP is targeting the other project, and has never heard of FileA.

The only workaround I can think of would be to open each project in a different VSCode window, and then enable the Headless LSP feature, which will cause the extension to spawn it's own isolated LSP in a child process.

For what it's worth, all of my multiplayer games are built as a single Godot project and I use Feature Tags and command line args to control what systems are enabled for the client/server.