Accessing the class reference documentation via script

Godot Version

4.4 dev 2

Question

I want to access the class reference documentation for a specific class. Maybe something like this:

func get_documentation(class_name:String) -> String:
    # magically returns the documentation

I could try to get the documentation text node in the Godot editor itself, but that seems like a bit much work for getting some documentation.

func go_to_help(msg:String):
	if msg.contains("/"):
		msg='"'+msg.replace("res://","").replace('"',"").replace("'","")+'"'
	msg='class'+'_name:'+msg.replace('class'+'_name:',"")
	EditorInterface.get_script_editor().get_current_editor().go_to_help.emit(msg)

While this is useful, this is not quite what I needed.
I wanted to get the documentation of a class, not open it.

Then you can only choose from the following five options:

  1. Modify Godot, implementation method unknown
  2. Create GDExtension, the implementation method is unknown, but you can take a look at the source code of the orchestrator
  3. Analyze class documents by obtaining help nodes, then obtaining text, and finally parsing.
    Disadvantages: 1. Due to the absence of spaces in some areas, only a portion of the document can be obtained. 2. Manual parsing is required
  4. To parse class files, the implementation method is:load("C:/Users/shen/AppData/Local/Godot/editor_doc_cache.res")
    Disadvantages: 1. No translation, 2. This is a large array, you can open it yourself to see the details, 3. It needs to be manually parsed
  5. Give up
    Advantages: Fast and efficient

If you find a better implementation, please let me know

I might try the third method of searching for the correct node which has the text itself. I’m searching through the scene tree, and under Mainscreen, there are loads of different control Nodes. I have already looked through the first four and couldn’t find the correct Node yet (even with the help help open). This might take a bit longer…
grafik

It seems that you have chosen the same path as me. In fact, I have created a plugin to parse class documents and create help buttons.

Could you share a link to your plugin maybe? Or tell me specifically how you did it?

engine_script_editor = EditorInterface.get_script_editor()
engine_edit_tab=engine_script_editor.get_child(0).get_child(1).get_child(1).get_child(0)
for i in engine_edit_tab.get_children():
	if i.get_class()=="EditorHelp":
		var engine_edit_help:RichTextLabel=i.get_child(0)
        engine_edit_help.select_all()
		edit=engine_edit_help.get_selected_text()

Thank you for the code snippet! I added this to not have the selection persist:

engine_edit_help.deselect()

EDIT: Using the RichTextLabel.get_parsed_text() method seems to return slightly more useful output. It leaves in some of the tabs which are ignored by RichTextLabel.get_selected_text().

These RichTextLabels function in a weird way, where the text does not appear in the text field, but it does appear visually and can be selected. I would have liked to get the text with all of the BBCode formatting, but that seems to be impossible.
All of the text seems to be inserted using the append_text and push_* methods.
This is gonna be a bit harder it seems…
But thank you very much for helping me with this!

EDIT: Difference between get_parsed_text() and get_selected_text()

get_parsed_text()

Enumerationen

enum ContextMenuSlot:

	● CONTEXT_SLOT_SCENE_TREE = 0
	Context menu of Scene dock. _popup_menu() will be called with a list of paths to currently selected nodes, while option callback will receive the list of currently selected nodes.
	● CONTEXT_SLOT_FILESYSTEM = 1
	Context menu of FileSystem dock. _popup_menu() and option callback will be called with list of paths of the currently selected files.
	● CONTEXT_SLOT_FILESYSTEM_CREATE = 3
	The "Create..." submenu of FileSystem dock's context menu. _popup_menu() and option callback will be called with list of paths of the currently selected files.
	● CONTEXT_SLOT_SCRIPT_EDITOR = 2
	Context menu of Scene dock. _popup_menu() will be called with the path to the currently edited script, while option callback will receive reference to that script.

get_selected_text()

Enumerationen

enum ContextMenuSlot:

● CONTEXT_SLOT_SCENE_TREE = 0
Context menu of Scene dock. _popup_menu() will be called with a list of paths to currently selected nodes, while option callback will receive the list of currently selected nodes.
● CONTEXT_SLOT_FILESYSTEM = 1
Context menu of FileSystem dock. _popup_menu() and option callback will be called with list of paths of the currently selected files.
● CONTEXT_SLOT_FILESYSTEM_CREATE = 3
The "Create..." submenu of FileSystem dock's context menu. _popup_menu() and option callback will be called with list of paths of the currently selected files.
● CONTEXT_SLOT_SCRIPT_EDITOR = 2
Context menu of Scene dock. _popup_menu() will be called with the path to the currently edited script, while option callback will receive reference to that script.
1 Like