From d16abbdee42725116fb13751f05a4afa1e118e6b Mon Sep 17 00:00:00 2001 From: janglee Date: Sat, 28 Mar 2020 13:42:19 +0530 Subject: [PATCH] Improved go-to definition (Ctrl + Click) Co-Authored-By: Bojidar Marinov (cherry picked from commit be7a353c70812e349861a7f5314d72425ae707cb) --- editor/editor_help.cpp | 2 ++ editor/plugins/script_text_editor.cpp | 26 ++++++++++++++++++++++++++ editor/plugins/script_text_editor.h | 2 ++ modules/gdscript/gdscript_editor.cpp | 11 +++++++++++ modules/gdscript/gdscript_parser.cpp | 12 +++++++++++- scene/gui/text_edit.cpp | 2 +- 6 files changed, 53 insertions(+), 2 deletions(-) diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 9f8c03d9ea7..1d9a2f9f875 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -1040,6 +1040,7 @@ void EditorHelp::_update_doc() { class_desc->pop(); // color class_desc->pop(); // font class_desc->pop(); // cell + method_line[cd.properties[i].setter] = property_line[cd.properties[i].name]; } if (cd.properties[i].getter != "") { @@ -1057,6 +1058,7 @@ void EditorHelp::_update_doc() { class_desc->pop(); //color class_desc->pop(); //font class_desc->pop(); //cell + method_line[cd.properties[i].getter] = property_line[cd.properties[i].name]; } class_desc->pop(); // table diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index cbb7bd42ecc..90c8e5ce3a7 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -970,9 +970,35 @@ void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_c emit_signal("go_to_help", "class_global:" + result.class_name + ":" + result.class_member); } break; } + } else if (ProjectSettings::get_singleton()->has_setting("autoload/" + p_symbol)) { + //check for Autoload scenes + String path = ProjectSettings::get_singleton()->get("autoload/" + p_symbol); + if (path.begins_with("*")) { + path = path.substr(1, path.length()); + EditorNode::get_singleton()->load_scene(path); + } + } else if (p_symbol.is_rel_path()) { + // Every symbol other than absolute path is relative path so keep this condition at last. + String path = _get_absolute_path(p_symbol); + if (FileAccess::exists(path)) { + List scene_extensions; + ResourceLoader::get_recognized_extensions_for_type("PackedScene", &scene_extensions); + + if (scene_extensions.find(path.get_extension())) { + EditorNode::get_singleton()->load_scene(path); + } else { + EditorNode::get_singleton()->load_resource(path); + } + } } } +String ScriptTextEditor::_get_absolute_path(const String &rel_path) { + String base_path = script->get_path().get_base_dir(); + String path = base_path.plus_file(rel_path); + return path.replace("///", "//").simplify_path(); +} + void ScriptTextEditor::update_toggle_scripts_button() { if (code_editor != NULL) { code_editor->update_toggle_scripts_button(); diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h index 9018e9d3c28..82cfa531107 100644 --- a/editor/plugins/script_text_editor.h +++ b/editor/plugins/script_text_editor.h @@ -186,6 +186,8 @@ protected: bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); + String _get_absolute_path(const String &rel_path); + public: void _update_connected_methods(); diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index c617138fcd8..ff2e11381b6 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -3490,6 +3490,17 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol return OK; } } break; + case GDScriptParser::COMPLETION_TYPE_HINT: { + + GDScriptParser::DataType base_type = context._class->base_type; + base_type.has_type = true; + base_type.kind = GDScriptParser::DataType::CLASS; + base_type.class_type = const_cast(context._class); + + if (_lookup_symbol_from_base(base_type, p_symbol, false, r_result) == OK) { + return OK; + } + } break; default: { } } diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index b7fdcf3a9df..c9f3917d1ee 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -8551,7 +8551,13 @@ Error GDScriptParser::_parse(const String &p_base_path) { _set_error("Parse error: " + tokenizer->get_token_error()); } - if (error_set && !for_completion) { + bool for_completion_error_set = false; + if (error_set && for_completion) { + for_completion_error_set = true; + error_set = false; + } + + if (error_set) { return ERR_PARSE_ERROR; } @@ -8581,6 +8587,10 @@ Error GDScriptParser::_parse(const String &p_base_path) { // Resolve the function blocks _check_class_blocks_types(main_class); + if (for_completion_error_set) { + error_set = true; + } + if (error_set) { return ERR_PARSE_ERROR; } diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 37873a6c1ad..0acb62dbbd9 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1150,7 +1150,7 @@ void TextEdit::_notification(int p_what) { highlighted_text_col = _get_column_pos_of_word(highlighted_text, str, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, 0); if (select_identifiers_enabled && highlighted_word.length() != 0) { - if (_is_char(highlighted_word[0])) { + if (_is_char(highlighted_word[0]) || highlighted_word[0] == '.') { highlighted_word_col = _get_column_pos_of_word(highlighted_word, fullstr, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, 0); } }