Skip to content

Commit 0a07ae7

Browse files
committed
Editor: Fix documentation for built-in scripts
1 parent 1cf573f commit 0a07ae7

File tree

6 files changed

+79
-24
lines changed

6 files changed

+79
-24
lines changed

editor/connections_dialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ ConnectDialog::~ConnectDialog() {
924924

925925
Control *ConnectionsDockTree::make_custom_tooltip(const String &p_text) const {
926926
// If it's not a doc tooltip, fallback to the default one.
927-
if (p_text.is_empty() || p_text.contains("::")) {
927+
if (p_text.is_empty() || p_text.contains(" :: ")) {
928928
return nullptr;
929929
}
930930

editor/editor_file_system.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ void EditorFileSystem::_process_file_system(const ScannedDirectory *p_scan_dir,
13851385
void EditorFileSystem::_process_removed_files(const HashSet<String> &p_processed_files) {
13861386
for (const KeyValue<String, EditorFileSystem::FileCache> &kv : file_cache) {
13871387
if (!p_processed_files.has(kv.key)) {
1388-
if (ClassDB::is_parent_class(kv.value.type, SNAME("Script"))) {
1388+
if (ClassDB::is_parent_class(kv.value.type, SNAME("Script")) || ClassDB::is_parent_class(kv.value.type, SNAME("PackedScene"))) {
13891389
// A script has been removed from disk since the last startup. The documentation needs to be updated.
13901390
// There's no need to add the path in update_script_paths since that is exclusively for updating global class names,
13911391
// which is handled in _first_scan_filesystem before the full scan to ensure plugins and autoloads can be created.
@@ -2195,6 +2195,29 @@ void EditorFileSystem::_update_script_documentation() {
21952195
continue;
21962196
}
21972197

2198+
if (path.ends_with(".tscn")) {
2199+
Ref<PackedScene> packed_scene = ResourceLoader::load(path);
2200+
if (packed_scene.is_valid()) {
2201+
Ref<SceneState> state = packed_scene->get_state();
2202+
if (state.is_valid()) {
2203+
Vector<Ref<Resource>> sub_resources = state->get_sub_resources();
2204+
for (Ref<Resource> sub_resource : sub_resources) {
2205+
Ref<Script> scr = sub_resource;
2206+
if (scr.is_valid()) {
2207+
for (const DocData::ClassDoc &cd : scr->get_documentation()) {
2208+
EditorHelp::add_doc(cd);
2209+
if (!first_scan) {
2210+
// Update the documentation in the Script Editor if it is open.
2211+
ScriptEditor::get_singleton()->update_doc(cd.name);
2212+
}
2213+
}
2214+
}
2215+
}
2216+
}
2217+
}
2218+
continue;
2219+
}
2220+
21982221
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
21992222
ScriptLanguage *lang = ScriptServer::get_language(i);
22002223
if (lang->supports_documentation() && efd->files[index]->type == lang->get_type()) {

editor/editor_help.cpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,13 +2316,32 @@ void EditorHelp::_request_help(const String &p_string) {
23162316
}
23172317

23182318
void EditorHelp::_help_callback(const String &p_topic) {
2319-
String what = p_topic.get_slicec(':', 0);
2320-
String clss = p_topic.get_slicec(':', 1);
2321-
String name;
2322-
if (p_topic.get_slice_count(":") == 3) {
2323-
name = p_topic.get_slicec(':', 2);
2319+
Vector<String> parts;
2320+
{
2321+
int from = 0;
2322+
int buffer_start = 0;
2323+
while (true) {
2324+
const int pos = p_topic.find_char(':', from);
2325+
if (pos < 0) {
2326+
parts.push_back(p_topic.substr(buffer_start));
2327+
break;
2328+
}
2329+
2330+
if (pos + 1 < p_topic.length() && p_topic[pos + 1] == ':') {
2331+
// `::` used in built-in scripts.
2332+
from = pos + 2;
2333+
} else {
2334+
parts.push_back(p_topic.substr(buffer_start, pos - buffer_start));
2335+
from = pos + 1;
2336+
buffer_start = from;
2337+
}
2338+
}
23242339
}
23252340

2341+
const String what = parts[0]; // `parts` is always non-empty.
2342+
const String clss = (parts.size() > 1) ? parts[1] : String();
2343+
const String name = (parts.size() > 2) ? parts[2] : String();
2344+
23262345
_request_help(clss); // First go to class.
23272346

23282347
int line = 0;

editor/plugins/script_editor_plugin.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ void ScriptEditor::_resave_scripts(const String &p_str) {
10091009
Ref<Resource> scr = se->get_edited_resource();
10101010

10111011
if (scr->is_built_in()) {
1012-
continue; //internal script, who cares
1012+
continue; // Internal script, who cares.
10131013
}
10141014

10151015
if (trim_trailing_whitespace_on_save) {
@@ -1089,10 +1089,9 @@ void ScriptEditor::_mark_built_in_scripts_as_saved(const String &p_parent_path)
10891089
Ref<Script> scr = edited_res;
10901090
if (scr.is_valid()) {
10911091
trigger_live_script_reload(scr->get_path());
1092-
1093-
if (scr->is_tool()) {
1094-
scr->reload(true);
1095-
}
1092+
clear_docs_from_script(scr);
1093+
scr->reload(true);
1094+
update_docs_from_script(scr);
10961095
}
10971096
}
10981097
}
@@ -1143,7 +1142,7 @@ bool ScriptEditor::_test_script_times_on_disk(Ref<Resource> p_for_script) {
11431142
}
11441143

11451144
if (edited_res->is_built_in()) {
1146-
continue; //internal script, who cares
1145+
continue; // Internal script, who cares.
11471146
}
11481147

11491148
uint64_t last_date = se->edited_file_data.last_modified_time;
@@ -2722,31 +2721,32 @@ void ScriptEditor::save_all_scripts() {
27222721
se->apply_code();
27232722
}
27242723

2724+
Ref<Script> scr = edited_res;
2725+
2726+
if (scr.is_valid()) {
2727+
clear_docs_from_script(scr);
2728+
}
2729+
27252730
if (!edited_res->is_built_in()) {
27262731
Ref<TextFile> text_file = edited_res;
2727-
Ref<Script> scr = edited_res;
2728-
27292732
if (text_file.is_valid()) {
27302733
_save_text_file(text_file, text_file->get_path());
27312734
continue;
27322735
}
27332736

2734-
if (scr.is_valid()) {
2735-
clear_docs_from_script(scr);
2736-
}
2737-
2738-
EditorNode::get_singleton()->save_resource(edited_res); //external script, save it
2739-
2740-
if (scr.is_valid()) {
2741-
update_docs_from_script(scr);
2742-
}
2737+
// External script, save it.
2738+
EditorNode::get_singleton()->save_resource(edited_res);
27432739
} else {
27442740
// For built-in scripts, save their scenes instead.
27452741
const String scene_path = edited_res->get_path().get_slice("::", 0);
27462742
if (!scene_path.is_empty() && !scenes_to_save.has(scene_path)) {
27472743
scenes_to_save.insert(scene_path);
27482744
}
27492745
}
2746+
2747+
if (scr.is_valid()) {
2748+
update_docs_from_script(scr);
2749+
}
27502750
}
27512751

27522752
if (!scenes_to_save.is_empty()) {

scene/resources/packed_scene.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,6 +1963,18 @@ Ref<Resource> SceneState::get_sub_resource(const String &p_path) {
19631963
return Ref<Resource>();
19641964
}
19651965

1966+
Vector<Ref<Resource>> SceneState::get_sub_resources() {
1967+
const String path_prefix = get_path() + "::";
1968+
Vector<Ref<Resource>> sub_resources;
1969+
for (const Variant &v : variants) {
1970+
const Ref<Resource> &res = v;
1971+
if (res.is_valid() && res->get_path().begins_with(path_prefix)) {
1972+
sub_resources.push_back(res);
1973+
}
1974+
}
1975+
return sub_resources;
1976+
}
1977+
19661978
//add
19671979

19681980
int SceneState::add_name(const StringName &p_name) {

scene/resources/packed_scene.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ class SceneState : public RefCounted {
196196

197197
Vector<NodePath> get_editable_instances() const;
198198
Ref<Resource> get_sub_resource(const String &p_path);
199+
Vector<Ref<Resource>> get_sub_resources();
199200

200201
//build API
201202

0 commit comments

Comments
 (0)