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

Do not cache the doc information written by user in the script in Inspector #71843

Merged
merged 1 commit into from
May 29, 2023

Conversation

Rindbee
Copy link
Contributor

@Rindbee Rindbee commented Jan 22, 2023

This helps to resolve (partially) #70217 , but doesn't completely resolve it.

1

The inspector will be updated when * appears after modification, and then the inspector will not be updated again after continuing to save.

Fixed (partially) #63997.

Needs another PR to have the latest doc data ready before updating the tree for a full fix. See #71843 (comment).

@anvilfolk
Copy link
Contributor

Why do you say it fixes it partially but not completely? It looks like it works fully!

Copy link
Contributor

@anvilfolk anvilfolk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since script classes aren't registered with ClassDB as far as I can tell, then this does exactly what it says on the tin. Stuff that is static, like native classes, can be cached. Scripts, on the other hand, will never be cached here and updated docs information will always be obtained.

This does mean more work with checking whether EditorHelp's thread is running, but it should be negligible.

Highly recommend merging :)

@Rindbee
Copy link
Contributor Author

Rindbee commented Apr 15, 2023

Why do you say it fixes it partially but not completely? It looks like it works fully!

GDScript::_update_doc() relies on data parsed during GDScript::reload(), so it should be called after GDScript::reload() to update the docs. But GDScript::update_exports() is not, it will be parsed separately, so it does not depend on GDScript::reload().

GDScript::reload() is currently called after the file is saved, while GDScript::update_exports() is not, and GDScript::update_exports() may eventually cause the property_list_changed signal to be emitted, which will casue EditorInspector::update_tree() to be called at the end of the frame.

script->update_exports();

if (changed) {
for (PlaceHolderScriptInstance *E : placeholders) {
E->update(propnames, values);
}
} else {
p_instance_to_update->update(propnames, values);

if (owner && owner->get_script_instance() == this) {
owner->notify_property_list_changed();
}

The call to EditorInspector::update_tree() does not seem to be directly related to GDScript::reload().

@anvilfolk
Copy link
Contributor

Oh, interesting! I wonder whether this is related to the issue I'm trying to track down, where if you have two different scripts attached to nodes, and all have documentation, when opening the project tooltips work for one script but not for the other.

I think this PR will fix the symptom though: empty docs lead to empty caches, but the script eventually should have docs registered in DocTools... maybe :)

Very cool detective work, this also gives me some more information to follow up on. Basically the issue seems to be that some forms of loading/using exports do not rely on reload(), which is what generates documentation. I believe that once #72095 is merged, we'll be able to get easier methods for generating documentation that don't rely on reload() :)

@Rindbee
Copy link
Contributor Author

Rindbee commented Apr 16, 2023

Yes, this PR hands over to other PRs the job of preparing the latest data for the document before calling EditorInspector::update_tree().

Considering the situation of #67203, perhaps it is better to cache separately?

@anvilfolk
Copy link
Contributor

I believe this would fix #63997 as well. I feel like part of the linked issue here is a duplicate of that one?

@Rindbee
Copy link
Contributor Author

Rindbee commented Apr 22, 2023

I believe this would fix #63997 as well. I feel like part of the linked issue here is a duplicate of that one?

Yes, both are essentially caching issues.

@anvilfolk
Copy link
Contributor

Just a quick thought - extension tends to refer to a file extension, like .txt. I'm not sure it's the most appropriate term for this. Maybe do not cache member doc data or something along those lines would be more accurate? It'd be neat to rename that - unless I'm totally misinterpreting the issue :)

I keep trying to get someone to look into this one and merge in the chat but no luck so far.

…pector

The doc information of the edited object is cached to reuse it in the next `EditorInspector::update_tree()` call.

This is not suitable for doc information written by users in the script because it is easily changed.
@Rindbee Rindbee changed the title Do not cache the extension information of scripts in Inspector Do not cache the doc information written by user in the script in Inspector May 1, 2023
@Rindbee
Copy link
Contributor Author

Rindbee commented May 1, 2023

Now it seems to generate script doc information in GDScript::reload().

// Done after compilation because it needs the GDScript object's inner class GDScript objects,
// which are made by calling make_scripts() within compiler.compile() above.
GDScriptDocGen::generate_docs(this, parser.get_tree());

So in order to update the doc information of the script in the Inspector, we need to call EditorInspector::update_tree() after the script is reloaded. This is the same as before.

@anvilfolk
Copy link
Contributor

anvilfolk commented May 2, 2023

Now it seems to generate script doc information in GDScript::reload().

// Done after compilation because it needs the GDScript object's inner class GDScript objects,
// which are made by calling make_scripts() within compiler.compile() above.
GDScriptDocGen::generate_docs(this, parser.get_tree());

So in order to update the doc information of the script in the Inspector, we need to call EditorInspector::update_tree() after the script is reloaded. This is the same as before.

Yes, I pulled out the documentation generation into its own class, which gets called in GDScript::reload() :) If we somehow manage to get access to the GDScript object, it's likely not too hard to make a method similar to GDScript::reload() that just docgens.

That feels like it could be a future PR though, doesn't need to be for this one!

@YuriSizov YuriSizov merged commit fc83a2e into godotengine:master May 29, 2023
@YuriSizov
Copy link
Contributor

Thanks!

@anvilfolk
Copy link
Contributor

Yessssssssssss, I am so happy!!! Everyone update their tooltips all the time now 🎉 🎉 🎉

Thanks @Rindbee!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants