Skip to content

Commit ffc267b

Browse files
committed
Merge pull request godotengine#92280 from dalexeev/editor-fix-built-in-script-documentation
Editor: Fix documentation for built-in scripts
2 parents 88064d8 + 0a07ae7 commit ffc267b

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
@@ -931,7 +931,7 @@ ConnectDialog::~ConnectDialog() {
931931

932932
Control *ConnectionsDockTree::make_custom_tooltip(const String &p_text) const {
933933
// If it's not a doc tooltip, fallback to the default one.
934-
if (p_text.is_empty() || p_text.contains("::")) {
934+
if (p_text.is_empty() || p_text.contains(" :: ")) {
935935
return nullptr;
936936
}
937937

editor/editor_file_system.cpp

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

2209+
if (path.ends_with(".tscn")) {
2210+
Ref<PackedScene> packed_scene = ResourceLoader::load(path);
2211+
if (packed_scene.is_valid()) {
2212+
Ref<SceneState> state = packed_scene->get_state();
2213+
if (state.is_valid()) {
2214+
Vector<Ref<Resource>> sub_resources = state->get_sub_resources();
2215+
for (Ref<Resource> sub_resource : sub_resources) {
2216+
Ref<Script> scr = sub_resource;
2217+
if (scr.is_valid()) {
2218+
for (const DocData::ClassDoc &cd : scr->get_documentation()) {
2219+
EditorHelp::add_doc(cd);
2220+
if (!first_scan) {
2221+
// Update the documentation in the Script Editor if it is open.
2222+
ScriptEditor::get_singleton()->update_doc(cd.name);
2223+
}
2224+
}
2225+
}
2226+
}
2227+
}
2228+
}
2229+
continue;
2230+
}
2231+
22092232
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
22102233
ScriptLanguage *lang = ScriptServer::get_language(i);
22112234
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
@@ -2364,13 +2364,32 @@ void EditorHelp::_request_help(const String &p_string) {
23642364
}
23652365

23662366
void EditorHelp::_help_callback(const String &p_topic) {
2367-
String what = p_topic.get_slicec(':', 0);
2368-
String clss = p_topic.get_slicec(':', 1);
2369-
String name;
2370-
if (p_topic.get_slice_count(":") == 3) {
2371-
name = p_topic.get_slicec(':', 2);
2367+
Vector<String> parts;
2368+
{
2369+
int from = 0;
2370+
int buffer_start = 0;
2371+
while (true) {
2372+
const int pos = p_topic.find_char(':', from);
2373+
if (pos < 0) {
2374+
parts.push_back(p_topic.substr(buffer_start));
2375+
break;
2376+
}
2377+
2378+
if (pos + 1 < p_topic.length() && p_topic[pos + 1] == ':') {
2379+
// `::` used in built-in scripts.
2380+
from = pos + 2;
2381+
} else {
2382+
parts.push_back(p_topic.substr(buffer_start, pos - buffer_start));
2383+
from = pos + 1;
2384+
buffer_start = from;
2385+
}
2386+
}
23722387
}
23732388

2389+
const String what = parts[0]; // `parts` is always non-empty.
2390+
const String clss = (parts.size() > 1) ? parts[1] : String();
2391+
const String name = (parts.size() > 2) ? parts[2] : String();
2392+
23742393
_request_help(clss); // First go to class.
23752394

23762395
int line = 0;

editor/plugins/script_editor_plugin.cpp

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

10501050
if (scr->is_built_in()) {
1051-
continue; //internal script, who cares
1051+
continue; // Internal script, who cares.
10521052
}
10531053

10541054
if (trim_trailing_whitespace_on_save) {
@@ -1128,10 +1128,9 @@ void ScriptEditor::_mark_built_in_scripts_as_saved(const String &p_parent_path)
11281128
Ref<Script> scr = edited_res;
11291129
if (scr.is_valid()) {
11301130
trigger_live_script_reload(scr->get_path());
1131-
1132-
if (scr->is_tool()) {
1133-
scr->reload(true);
1134-
}
1131+
clear_docs_from_script(scr);
1132+
scr->reload(true);
1133+
update_docs_from_script(scr);
11351134
}
11361135
}
11371136
}
@@ -1193,7 +1192,7 @@ bool ScriptEditor::_test_script_times_on_disk(Ref<Resource> p_for_script) {
11931192
}
11941193

11951194
if (edited_res->is_built_in()) {
1196-
continue; //internal script, who cares
1195+
continue; // Internal script, who cares.
11971196
}
11981197

11991198
uint64_t last_date = se->edited_file_data.last_modified_time;
@@ -2770,31 +2769,32 @@ void ScriptEditor::save_all_scripts() {
27702769
se->apply_code();
27712770
}
27722771

2772+
Ref<Script> scr = edited_res;
2773+
2774+
if (scr.is_valid()) {
2775+
clear_docs_from_script(scr);
2776+
}
2777+
27732778
if (!edited_res->is_built_in()) {
27742779
Ref<TextFile> text_file = edited_res;
2775-
Ref<Script> scr = edited_res;
2776-
27772780
if (text_file.is_valid()) {
27782781
_save_text_file(text_file, text_file->get_path());
27792782
continue;
27802783
}
27812784

2782-
if (scr.is_valid()) {
2783-
clear_docs_from_script(scr);
2784-
}
2785-
2786-
EditorNode::get_singleton()->save_resource(edited_res); //external script, save it
2787-
2788-
if (scr.is_valid()) {
2789-
update_docs_from_script(scr);
2790-
}
2785+
// External script, save it.
2786+
EditorNode::get_singleton()->save_resource(edited_res);
27912787
} else {
27922788
// For built-in scripts, save their scenes instead.
27932789
const String scene_path = edited_res->get_path().get_slice("::", 0);
27942790
if (!scene_path.is_empty() && !scenes_to_save.has(scene_path)) {
27952791
scenes_to_save.insert(scene_path);
27962792
}
27972793
}
2794+
2795+
if (scr.is_valid()) {
2796+
update_docs_from_script(scr);
2797+
}
27982798
}
27992799

28002800
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
@@ -1970,6 +1970,18 @@ Ref<Resource> SceneState::get_sub_resource(const String &p_path) {
19701970
return Ref<Resource>();
19711971
}
19721972

1973+
Vector<Ref<Resource>> SceneState::get_sub_resources() {
1974+
const String path_prefix = get_path() + "::";
1975+
Vector<Ref<Resource>> sub_resources;
1976+
for (const Variant &v : variants) {
1977+
const Ref<Resource> &res = v;
1978+
if (res.is_valid() && res->get_path().begins_with(path_prefix)) {
1979+
sub_resources.push_back(res);
1980+
}
1981+
}
1982+
return sub_resources;
1983+
}
1984+
19731985
//add
19741986

19751987
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)