godotengine / godot-vscode-plugin

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

anyFolder does not work #664

Open LaraSQP opened 3 weeks ago

LaraSQP commented 3 weeks ago

Godot version

4.2.2

VS Code version

1.90

Godot Tools VS Code extension version

2.0.0

System information

Windows 10

Issue description

The specific error when trying to run the pinned GDScript is:

Can't find associated scene file for 'c:\someproject\scripts\world.gd

The scene is in folder 'c:\someproject\scenes\world.tscn

Note that the extension works as expected if both files are in the same folder.

Also, note that I have changed the settings below in both user and workspace settings.

Godot Tools › Scene Preview: Preview Related Scenes
Controls where the Scene Preview will search for related scenes when viewing a script file.
anyFolder 

This is a deal breaker. Probably my mistake. If so, apologies.

Any workaround or clue would be most appreciated.

Thank you all.

Steps to reproduce

As explained above.

Place both files in the same folder and it works.

Place each file in a separate folder and it does not work.

LaraSQP commented 3 weeks ago

Here is a minimum project that illustrates the bug.

TestProject.zip

When scene1.gd is pinned in VSCode, the project runs/debugs fine and stops at breakpoints, etc.

When scene2.gd is pinned in VSCode, the project does not run and the following error pops up.

Can't find associated scene file for 'd:\TestProject\b\scene2.gd'

This is the folder structure of the project.

📦 TestProject
├─ a
│  ├─ scene1.gd
│  ├─ scene1.tscn
│  └─ scene2.tscn
└─ b
   └─ scene2.gd

©generated by Project Tree Generator

DaelonSuzuka commented 3 weeks ago

This isn't really a bug. Determining the scene that's associated with a given script is nontrivial if it's not in the same folder.

Godot Tools › Scene Preview: Preview Related Scenes Controls where the Scene Preview will search for related scenes when viewing a script file.

Please note the emphasis: this setting is for the Scene Preview, and has no relation to launching scenes, pinned or otherwise.

Are you aware that you can just pin the scene you're interested in launching? You can either open the .tscn file and click the pin button in the upper right, or you can right click the file in the file explorer and select Pin Scene File.

LaraSQP commented 3 weeks ago

Thank you for the quick reply.

I have been playing with Godot Tools › Scene Preview: Preview Related Scenes but I see no way to have the extension perform any search. There is a combobox with anyFolder, sameFolder, and off. I understand now that this has no relation to launching scenes, thank you.

I'm aware I can pin the script (or the scene) but it does not address the problem.

It's possible I'm asking for a feature that does not exist. Does a script and its scene need to be in the same folder in order to run that script?

DaelonSuzuka commented 3 weeks ago

I'm aware I can pin the script (or the scene) but it does not address the problem.

I must not understand what you're trying to do, because to me this seems like a direct solution to your problem.

It's possible I'm asking for a feature that does not exist. Does a script and its scene need to be in the same folder in order to run that script?

Yeah, that's correct. There's no such thing as "running a script", all you can do is start the engine with a specific scene as the root/target. Given that there's no actual link from script -> scene, the best the extension can do is guess, so in order to prevent confusing and wrong behavior (eg, launching the wrong scene), this feature is restricted to matching filenames in the same folder.

LaraSQP commented 3 weeks ago

The problem is running a script whose scene is in another folder.

But I get it now. This is not a bug. I will close the ticket.

Thank you for your quick replies and patience.

DaelonSuzuka commented 3 weeks ago

The problem is running a script whose scene is in another folder.

Pin the scene file you want, then run the "debug pinned scene" command?

You can also use profiles in launch.json for this, by setting the "scene": "main|current|pinned|<path>" field to either pinned or to the path of the scene you want, and hitting F5.

LaraSQP commented 3 weeks ago

I have pinned the scene I want to run and all I get is this (below) no matter which scene I pin, the one with the script in the same folder or the one with the script in another folder.

Clipboard01

Clipboard02

DaelonSuzuka commented 3 weeks ago

Once again, the Scene Preview is completely unrelated, and pinning something in the Scene Preview has no effect on launching scenes.

LaraSQP commented 3 weeks ago

I thought that was the case but this is what you said above:

Pin the scene file you want, then run the "debug pinned scene" command?

This made me try to "Pin the scene file you want, then run the "debug pinned scene" command".

Nonetheless, sure, it's fine. It is not possible to run scenes with a script elsewhere, pinned or otherwise. I get it. No worries.

DaelonSuzuka commented 3 weeks ago

It is not possible to run scenes with a script elsewhere, pinned or otherwise.

Wrong.

Okay, let me try this one more time. Pinning the Scene Preview is NOT THE SAME as pinning the debug/launch target. That's why I explicitly told you to right click on the scene, which you did not do.

Click on either of these two things:

image

Look for the pin icon in these places:

image

This scene is now pinned and will be launched when you run the Godot Tools: Debug Pinned File command. It does not matter where BattleAvatar.gd is, because BattleAvatar.tscn is the debug target.

LaraSQP commented 3 weeks ago

Your patience is appreciated.

Perhaps the problem is that we see different things. I have none of the "pins" you have on scenes.

Clipboard01

The context menu entry Pin Scene File only appears on scripts, not on scenes.

DaelonSuzuka commented 3 weeks ago

Perhaps the problem is that we see different things. I have none of the "pins" you have on scenes.

Wow, that's a huge problem. Those options should definitely be available.

Let me investigate this and get back to you.

DaelonSuzuka commented 3 weeks ago

PR #665 renames the Scene Preview pin feature to lock, to help prevent confusion on that front.

LaraSQP commented 3 weeks ago

Thanks again. You rock

Is there a workaround or some such I could do for now?

DaelonSuzuka commented 3 weeks ago

I uninstalled the extension and reinstalled 2.0.0 from the marketplace just to confirm, and I have the option:

image

Is it possible you installed a development version of 2.0.0 from before the actual release? Can you try completely uninstalling the extension, restarting VSCode, and reinstalling it?

LaraSQP commented 3 weeks ago

I uninstalled the extension, restarted VSCode, and installed the extension again. No luck.

The screenshot below shows all the extensions I have on VSCode and the context menu for a .tscn file.

Clipboard01

DaelonSuzuka commented 3 weeks ago

Wow, I can't imagine how that's even possible...

I'll try to finish up some open PRs this week and get a 2.1.0 published, maybe that will shake something loose?

In the meantime I guess you can make a launch.json like this and then hit F5 to launch the debugger?

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "GDScript: Launch Project",
            "type": "godot",
            "request": "launch",
            "scene": "<path/to/scene.tscn>"
        }
    ]
}

(If you tell me this doesn't work / is missing then I will have no choice but to recommend an exorcism)

LaraSQP commented 3 weeks ago

The service of an exorcist is not required. It works using that launch file.

I will wait for 2.1.0 and let you know then.

Kudos.