godotengine / godot-vscode-plugin

Godot development tools for VSCode
MIT License
1.53k stars 151 forks source link

Add scene preview panel #413

Closed DaelonSuzuka closed 1 year ago

DaelonSuzuka commented 2 years ago

This adds a panel to the activity bar that shows a tree preview of the currently selected scene file.

https://user-images.githubusercontent.com/18042232/186282657-50ba98f8-f8c1-49ae-80f3-4846aafd4fe2.mp4

Things that need fixing in this PR:

future improvements (not this PR): j/k these are all in this PR now:

atirut-w commented 2 years ago

I think this should be in the document outline but alas, guess the doc outline is an LSP thing.

DaelonSuzuka commented 2 years ago

I think this should be in the document outline but alas, guess the doc outline is an LSP thing.

I don't understand how the two are related at all.

atirut-w commented 2 years ago

I don't understand how the two are related at all.

I am talking about the outline section under the document tab. Sounds like a good place to put the scene tree preview in.

DaelonSuzuka commented 2 years ago

Oh, in the Explorer section in the Primary Sidebar? I interpreted it as the documentation pages that are provided by the LSP.

Yeah, this is basically a document outline for a scene file, so I can see the argument for putting it there. Personally, that's a useless location since if I want to see files, I only want to see files. I always hide Open Editors, Timeline, Outline, anything that's in that category except the file Explorer.

Luckily, you can just drag any sidebar containers to any section you want, so it would be one mouseclick to move it there if that's what you like.

In addition to "because I don't want it there" (which I will admit is not a great reason!), I also think the default location should be its own category to improve user discoverability. If the default location for this thing is minimized at the bottom of the Explorer tab, how many people will even notice that it was added? Adding a Godot category provides an immediately visible, obvious default location for this and other features that I hope I can work on soon.

By the way, screenshots of the new Godot category icon:

ShareX_UmRWhXzotA

DaelonSuzuka commented 2 years ago

I figured the easiest way to explain the new features was with a series of short video clips:

Scene Preview Pinning Clicking the pushpin button locks the currently displayed scene. This makes it easier to use the Scene Preview as a reference while working on scripts. https://user-images.githubusercontent.com/18042232/187405484-23d2d276-df3c-45be-89a1-5df363892838.mp4
Switch between a scene and a related script In C/C++, pressing `alt+o` will switch from `foo.c` to `foo.h` and vice-versa. I replicated the same functionality between a script and a related scene. https://user-images.githubusercontent.com/18042232/187405998-ec54168e-d959-4e58-a43d-1927e2ac9040.mp4
Display Scene Preview when viewing related script Using the same mechanism as above, the Scene Preview will show you the scene file that matches the script you have open. https://user-images.githubusercontent.com/18042232/187409272-c1104d6d-875f-45cc-9ad5-d6930dcbb024.mp4
Tooltips with syntax highlighting Hovering over a node in the scene tree will now show you a tooltip of that node's entire definition. https://user-images.githubusercontent.com/18042232/187406391-cdaeba42-3e46-4f5b-aee9-951d210f6012.mp4

Nodes in the Scene Preview now have several context menu options:

Right Click > Copy Node Path This menu option will copy the path of the selected node, relative to the root of the current scene. If the node has been marked as Unique, the unique node path will be copied instead (`%NodeName`). https://user-images.githubusercontent.com/18042232/187405535-482146a7-a791-4582-80b6-f6f6fe730d62.mp4
Right Click > Go to Definition This menu option will jump to and highlight the definition of the selected node. https://user-images.githubusercontent.com/18042232/187407085-ee616f24-aac4-48d6-8d24-edd5f5c528fb.mp4
Right Click > Open Scene This menu option is only available on PackedScene nodes, aka instances of other scenes. Selecting this will open the scene file that the selected node is an instance of. https://user-images.githubusercontent.com/18042232/187407398-d9cdd907-36e1-4dde-9192-6be3ec1dd7a5.mp4
DaelonSuzuka commented 2 years ago

I will probably add a couple more settings, to let the user tweak some of these advanced behaviors.

In the same vein, it's probably appropriate to add some commands to allow manually invoking features.

I very desperately wanted to put icons on the far right of each tree item to indicate it's visibility, whether it has a script attached, if it's been marked unique, etc etc. For some blasted reason, this appears to be literally impossible with the current vscode TreeView API. It's possible to add buttons that are hidden until you move your mouse over them, but there's no way to get permanently visible icons like in the Godot Editor's Scene Tree.

Something like this is probably the best I'll be able to do: image

DaelonSuzuka commented 2 years ago

I added a configuration that will let the user pick how aggressively the Scene Preview will search for a "related scene" when opening a script. The options are:

The default setting is sameFolder, because I figure that will be helpful and relatively intuitive(aka, not magic), and has a limited chance of grabbing a totally unrelated scene.

I also figured out a relatively clean way to show more information about a given Node. Right now it's just whether there's a script attached and if the node is Unique, but I can add more later if something seems useful.

image

And, since it can show that there's a script attached, why not let you jump directly to that script?

https://user-images.githubusercontent.com/18042232/189290577-7482af72-aba1-4917-bdde-24c4787b10f8.mp4

DaelonSuzuka commented 2 years ago

I think I'm done with this for now.

DaelonSuzuka commented 2 years ago

I want it on the record that I did spend several hours trying to convince Prettier to format to our style, and all I accomplished was getting it to stop working entirely.

Calinou commented 2 years ago

I want it on the record that I did spend several hours trying to convince Prettier to format to our style, and all I accomplished was getting it to stop working entirely.

I'm OK with changing the formatting to be more standard across what other popular VS Code extensions are doing. This should be done in a future PR though (and after all prominent PRs are merged to avoid conflicts).

DaelonSuzuka commented 2 years ago

I'm OK with changing the formatting to be more standard across what other popular VS Code extensions are doing. This should be done in a future PR though (and after all prominent PRs are merged to avoid conflicts).

Whatever style choice is fine with me, I just want the freaking tools to do what they're supposed to. I've used clang-format on C code for like 8 years now, and haven't had 1/100th the issues that Prettier has given me.

Calinou commented 2 years ago

I've used clang-format on C code for like 8 years now, and haven't had 1/100th the issues that Prettier has given me.

This is one of the reasons I prefer using just ESLint instead of ESLint + Prettier. Less tools means less moving parts that can potentially break :slightly_smiling_face:

The downside is that formatting is not as strict when using just ESLint.

DaelonSuzuka commented 2 years ago

Honestly, the entire type/javascript experience has been right in line with trying to make Prettier behave. There's some stuff that I like, but boy am I glad I'm not a web developer...

DaelonSuzuka commented 2 years ago

@Calinou Are there actually still changes requested? I'm pretty sure I resolved everything that I saw.

Nukiloco commented 1 year ago

What is the current progress on this PR? This seems like a great feature for Godot vscode! Also does this PR also do the inspector, or is this just only for the scene?

DaelonSuzuka commented 1 year ago

What is the current progress on this PR? This seems like a great feature for Godot vscode!

@Nukiloco Sorry for the radio silence here. I think everybody's just busy, either with Godot 4 Beta activity or other life stuff. I really appreciate your interest here, and hope to get the active PRs cleaned up soon.

Also does this PR also do the inspector, or is this just only for the scene?

Can you rephrase the question here? I'm not sure what you mean by "inspector".

atirut-w commented 1 year ago

Can you rephrase the question here? I'm not sure what you mean by "inspector".

I think he meant node inspectors. You know, where you changer node properties like position, exported var, etc.?

AlfishSoftware commented 6 months ago

I very desperately wanted to put icons on the far right of each tree item to indicate it's visibility, whether it has a script attached, if it's been marked unique, etc etc.

Have you tried using emoji? If text is supported, it might work. For example, you could use "📜 Node" instead of "S | Node". Some suggestions:

DaelonSuzuka commented 5 months ago

@AlfishSoftware

I did use emojis before in an earlier version, but I also need (some of) them to be clickable buttons. I may come back and revise this to split some tags into emojis and some into buttons.