I have started developing a plugin that creates a code graph containing all the GDScript files in a project. Although I found tools that can create graphs with Python scripts, I wanted to be able to access this graph directly in the Godot editor. I also wanted to learn how to create Godot plugins.
The aim is to provide an overview of all the scripts in the project, showing what they contain and how they are connected.
Currently, the plugin adds a ‘code graph’ dock to the bottom bar of the inspector containing a GraphEdit.
Clicking the refresh button scans the project to find GDScript files. For each file found, a GraphNode is added and labels are created for each enum, constant, property, signal and method of the script. The name, type and value (if applicable) are displayed.
From the limited testing I have done so far, this is working correctly.
What isn’t implemented yet are the connections between scripts. This adds a whole new layer of complexity, as I cannot use the built-in methods of the Script class to determine which functions or properties a given script calls from another script.
The solution I am considering is to use RegEx to match the ‘access method or property’ pattern, and then use another RegEx to find out what method or property is being accessed. However, this sounds complicated, as there are a bunch of different cases, such as:
- $Child.method()
- child_reference.method()
- get_node(“Child”).method()
- array[child].method()
- ClassName.method()
- child_reference.method.call()
And probably more. Other than using RegEx, I am out of ideas. I can’t write in C++, so I have to stick to GDScript for this.
I also want to find out what resources each script loads or preloads. I will probably try using RegEx for this too.
I have only spent a few hours on it so far, and I am not sure how much time I will be able to dedicate to this or how complicated adding the connections between the scripts will be.
I think it would be great to be able to see the overall structure of the code directly in the Godot editor. The project is open source, so anyone who wants to contribute is welcome to do so — especially since I’m not a professional programmer! https://github.com/quokt/godot-code-graph-plugin
