Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement navigation, usage search and refactoring for visual scripts functions #11

Open
derkork opened this issue May 13, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@derkork
Copy link

derkork commented May 13, 2022

Describe the project you are working on

This is not really project specific. In every project you will eventually have the need to navigate and refactor your code and see which parts of your code are used by other code.

Describe the problem or limitation you are having in your project

There is currently no good way to refactor visual script functions. The only thing that is supported is renaming a function. If I add or remove parameters, this will break all usages of it. I cannot reorder parameters without deleting them. In addition I have no way of finding usages of my function. In the text editor I could do some search and replace, and while that still is a far cry from modern refactoring tools, it is at least an approach that would work.

Once I realize I have to change a function which is used in a dozen places, it is basically game over, because If i add or remove a parameter, all usage places of the function are broken and I will only find out at runtime if something is not working because the compiler will not tell me. Since I have no usage search I cannot even find these places easily.

Lastly, navigation is quite limited. I cannot easily jump from usage of a function to its declaration (like i can in the text editor).

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Enhancement: Proper function signature change refactoring

Add proper refactoring support for changing function signatures. This could be done either with the inspector (as it is done right now) or through a dedicated refactoring dialog. The refactoring must fix all usages of the to conform to the new signature where possible. It should be possible to change parameter names, types and order easily without losing information when I reorder parameters.

This would enormously improve the experience as in many cases the code remains in working condition and even in cases where manual rework is required, the editor can still help out by at least automatically fixing everything that is in its power.

Enhancement: Usage search for functions

In addition there needs to be a way to search for usages of a function, so I can fix all usages quickly should I have made a change that cannot be automatically fixed (e.g. like adding a new parameter or changing the type to something incompatible).

Without this, I need to manually go through all the graphs to find any use of my function and there is a good chance I miss one.

Enhancement: Improved code navigation

It would be tremendously helpful if i could jump from a function invocation to its declaration, so I can fix stuff quickly without having to manually open the respective graph and then have to search for the function if it contains more than one.

This would make working with visual scripts less cumbersome.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Refactoring

For refactoring, the user could right-click the function definition or any usage and have a "refactor" entry in the context menu:

image

Then the user should have a way of easily reordering renaming and changing parameter types:

image

All changes should be reflected in all usages of the function, e.g. if parameters are reordered, they should be reordered in the usages as well and the connections should be fixed to connect to the new port position. If a parameter is introduced between two others, the connections are also moved appropriately.

image

If a connection cannot be fixed and becomes invalid, it should be removed (e.g. when a parameter type is changing to something incompatible). If a new parameter is introduced the new port stays disconnected.

Usage search

Right-clicking on the function definition or any usage of a function should offer a context menu item allowing to search for usages of the function:

image

Clicking on this would open a list of all places where the function is used. In this list an entry can be double-clicked to go to the respective usage site. The usage site will be centered in the editor and briefly highlighted:

image

Quick navigation

Right-clicking on any usage of a function should offer a context menu to quickly jump to the definition of the function:

image

Selecting this entry will open the editor with the function definition and scroll to the function entry point, also briefly highlighting it:

image

If this enhancement will not be used often, can it be worked around with a few lines of script?

I think the changes are too complex to be implemented with a simple script. The whole visual scripting editor is done in C++ and its internal model is only known to the developers.

Is there a reason why this should be core and not an add-on in the asset library?

Since the editor itself is core and this requires certain data structures to keep track of nodes and connections and fixing up these I think it will have to be part of the core editor.

@sairam4123
Copy link

Offtopic: I think it's not just VisualScript needs a refactor, but I think GDScript also needs refactor, like it doesn't have "Find usages", "Refactor", "Generate Method", etc.

@derkork
Copy link
Author

derkork commented May 16, 2022

Offtopic: I think it's not just VisualScript needs a refactor, but I think GDScript also needs refactor, like it doesn't have "Find usages", "Refactor", "Generate Method", etc.

Yes that would be nice, however with GDScript this is almost impossible to reliably implement, simply because GDScript is not strongly typed and the editor would have to guess what to refactor then. With VisualScript it is a lot easier because you actually have the data structures and typing that would allow you to do these refactorings in the first place.

@Calinou
Copy link
Member

Calinou commented May 16, 2022

Offtopic: I think it's not just VisualScript needs a refactor, but I think GDScript also needs refactor, like it doesn't have "Find usages", "Refactor", "Generate Method", etc.

This is already being tracked in godotengine/godot-proposals#899.

@YuriSizov YuriSizov transferred this issue from godotengine/godot-proposals Aug 24, 2022
@YuriSizov YuriSizov added the enhancement New feature or request label Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants