Repository: godot
Issue: NativeScript cannot be used as an EditorNode with Script Class system
Labels: bug,topic:editor,topic:gdextension

### Godot version

3.4.2

### System information

Windows 11, GLES3, NVIDIA RTX 3090 (511.23)

### Issue description

GDScript can specify a `class_name` to allow itself to become an `EditorNode`. This is [documented on the GDScript basics page](https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_basics.html#doc-gdscript-basics-class-name). NativeScript cannot currently do this, apparently due to a bug in how `EditorData` gets the script base class name.

The workaround I am currently using is adding my class as [a custom type using an `EditorPlugin`](https://docs.godotengine.org/en/stable/tutorials/plugins/editor/making_plugins.html#a-custom-node).

I tracked the bug down to this line returning an empty string: https://github.com/godotengine/godot/blob/b7b2fd0634d0abb2f74c706826378b1727e83a57/editor/editor_data.cpp#L878

I was able to make a patch, but I do not know how to do this the _right_ way. It works for me. 🤷 (This applies on the `3.x` branch, but be mindful that this patch contains spaces, not tabs.)

```patch
diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp
index e1ac4e0be7..2aab710b5a 100644
--- a/editor/editor_data.cpp
+++ b/editor/editor_data.cpp
@@ -898,19 +898,18 @@ StringName EditorData::script_class_get_base(const String &p_class) const {
                return StringName();
        }

-       Ref<Script> base_script = script->get_base_script();
-       if (base_script.is_null()) {
-               return ScriptServer::get_global_class_base(p_class);
-       }
-
-       return script->get_language()->get_global_class_name(base_script->get_path());
+       return script->get_instance_base_type();
 }

 Variant EditorData::script_class_instance(const String &p_class) {
        if (ScriptServer::is_global_class(p_class)) {
-               Variant obj = ClassDB::instance(ScriptServer::get_global_class_native_base(p_class));
+               Ref<Script> script = script_class_load_script(p_class);
+               StringName native_base = ScriptServer::get_global_class_native_base(p_class);
+               if (native_base == String()) {
+                       native_base = script->get_instance_base_type();
+               }
+               Variant obj = ClassDB::instance(native_base);
                if (obj) {
-                       Ref<Script> script = script_class_load_script(p_class);
                        if (script.is_valid()) {
                                ((Object *)obj)->set_script(script.get_ref_ptr());
                        }
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index e7f163c5b9..b7a63daa87 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -4036,7 +4036,8 @@ Ref<Texture> EditorNode::get_class_icon(const String &p_class, const String &p_f
                }

                if (icon.is_null()) {
-                       icon = gui_base->get_icon(ScriptServer::get_global_class_base(name), "EditorIcons");
+                       StringName base_class = EditorNode::get_editor_data().script_class_get_base(p_class);
+                       icon = gui_base->get_icon(base_class, "EditorIcons");
                }

                return icon;
```

### Steps to reproduce

1. Create a NativeScript. Even [this basic example](https://docs.godotengine.org/en/stable/tutorials/scripting/gdnative/gdnative_c_example.html) will do.
2. Make sure to set the script class name so that the editor (supposedly) shows the node in the tree view.

![example-nativescript](https://user-images.githubusercontent.com/456942/151917209-8c302f87-273c-43a9-8813-eea5ae3b75b3.png)

3. Click the "Add Node" button.
4. The node does not appear in the list. 😢

### Minimal reproduction project

This project has everything setup (tested with `3.x` branch)! Just run `scons platform=...` and import it: [simple.zip](https://github.com/godotengine/godot/files/7976248/simple.zip)

The `SIMPLE` node appears in the "Add New Node" dialog with the above patch.