Repository: godot
Issue: Creating a new Custom Resource class yields an error "hides a global script class", then the Inspector goes empty for custom resources
Labels: bug,topic:gdscript,topic:editor

### Godot version

4.0 stable

### System information

Windows 10

### Issue description

When writing a new script for a class that inherits from Resource, after writing a custom `class_name`, and BEFORE saving the script, the following error is thrown:

`... hides a global script class`.
![bug01](https://user-images.githubusercontent.com/248383/222191979-26d8951e-56b2-400e-a1c4-e5ed40ccc7f7.jpg)

After finishing creating the class and saving, the error is gone.

But then, **even with the error gone, when creating a Resource file for this resource, the inspector is empty**:

![EmptyInspector01](https://user-images.githubusercontent.com/248383/222192240-15106034-0a59-40ed-a1f8-014b763b31a9.jpg)

#### Solutions
- **RESTARTING** the editor solves it.
- If you hit save RIGHT AFTER writing the custom class_name, the error does not happen. But if you wait like a few seconds, then this issue happens. I can consistently reproduce it here.

#### Additional optional step
The next step is not necessarily needed, since the error already happens with the simplified first step. But sometimes it happens only after creating a typed array as follows:
Then creating a new Resource type that uses the previous resource in a way or another, also leaves the inspector empty:

![EmptyInspector02](https://user-images.githubusercontent.com/248383/222192393-e31468fc-ed62-4c0b-b5e2-e1da17f95040.jpg)



### Steps to reproduce
#### MAIN WAY TO REPRODUCE
- Create a new script that inherits from `Resource`, set a custom `class_name` and add one or two fields (basic types are enough).

```gdscript
extends Resource
class_name ItemAttribute

@export var attribute_type : String
@export var value : int
```

- DO NOT hit save after adding the fields, the error `hides a global script class` will appear. Now hit save. The error is gone.
- Create a Resource file for the `ItemAttribute` resource. Try to edit it, the inspector is empty.

The next step is not necessarily needed, since the error already happens with the simplified first step. But sometimes it happens only after creating a typed array as follows:

- Now create another `Resource` custom class, this time with a typed array with the previous resource type:

```gdscript
extends Resource
class_name InventoryItem

@export var item_name : String
@export var attributes : Array[ItemAttribute]
```

- Then create a Resource file, the inspector is empty.

#### SECONDARY WAY TO REPRODUCE
- Create a custom resource class, "save it fast" before the previous error triggers
- Create a resource file for it
- Now, add anything to the script, in order to break it, for example, a bunch of random characters `'320489304 [ p `
- Save and close the editor
- Open the editor, fix the script error
- The Resource inspector is empty, does not come back after fixing the script error

### Minimal reproduction project

If I share a project, the issue does not appear. It's only while creating the classes that the issue appear.