diff options
-rw-r--r-- | doc/classes/CodeEdit.xml | 10 | ||||
-rw-r--r-- | editor/plugins/script_text_editor.cpp | 11 | ||||
-rw-r--r-- | modules/gdscript/gdscript_editor.cpp | 10 | ||||
-rw-r--r-- | scene/gui/code_edit.cpp | 26 | ||||
-rw-r--r-- | scene/gui/code_edit.h | 3 |
5 files changed, 39 insertions, 21 deletions
diff --git a/doc/classes/CodeEdit.xml b/doc/classes/CodeEdit.xml index db825634bc..0e829127f2 100644 --- a/doc/classes/CodeEdit.xml +++ b/doc/classes/CodeEdit.xml @@ -248,12 +248,20 @@ Returns the full text with char [code]0xFFFF[/code] at the caret location. </description> </method> - <method name="get_text_for_symbol_lookup"> + <method name="get_text_for_symbol_lookup" qualifiers="const"> <return type="String" /> <description> Returns the full text with char [code]0xFFFF[/code] at the cursor location. </description> </method> + <method name="get_text_with_cursor_char" qualifiers="const"> + <return type="String" /> + <param index="0" name="line" type="int" /> + <param index="1" name="column" type="int" /> + <description> + Returns the full text with char [code]0xFFFF[/code] at the specified location. + </description> + </method> <method name="has_auto_brace_completion_close_key" qualifiers="const"> <return type="bool" /> <param index="0" name="close_key" type="String" /> diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 0a1f735f64..fb3da52aee 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -811,6 +811,8 @@ void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_c } ScriptLanguage::LookupResult result; + String code_text = code_editor->get_text_editor()->get_text_with_cursor_char(p_row, p_column); + Error lc_error = script->get_language()->lookup_code(code_text, p_symbol, script->get_path(), base, result); if (ScriptServer::is_global_class(p_symbol)) { EditorNode::get_singleton()->load_resource(ScriptServer::get_global_class_path(p_symbol)); } else if (p_symbol.is_resource_file()) { @@ -823,7 +825,7 @@ void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_c EditorNode::get_singleton()->load_resource(p_symbol); } - } else if (script->get_language()->lookup_code(code_editor->get_text_editor()->get_text_for_symbol_lookup(), p_symbol, script->get_path(), base, result) == OK) { + } else if (lc_error == OK) { _goto_line(p_row); switch (result.type) { @@ -944,7 +946,10 @@ void ScriptTextEditor::_validate_symbol(const String &p_symbol) { } ScriptLanguage::LookupResult result; - if (ScriptServer::is_global_class(p_symbol) || p_symbol.is_resource_file() || script->get_language()->lookup_code(code_editor->get_text_editor()->get_text_for_symbol_lookup(), p_symbol, script->get_path(), base, result) == OK || (ProjectSettings::get_singleton()->has_autoload(p_symbol) && ProjectSettings::get_singleton()->get_autoload(p_symbol).is_singleton)) { + String lc_text = code_editor->get_text_editor()->get_text_for_symbol_lookup(); + Error lc_error = script->get_language()->lookup_code(lc_text, p_symbol, script->get_path(), base, result); + bool is_singleton = ProjectSettings::get_singleton()->has_autoload(p_symbol) && ProjectSettings::get_singleton()->get_autoload(p_symbol).is_singleton; + if (ScriptServer::is_global_class(p_symbol) || p_symbol.is_resource_file() || lc_error == OK || is_singleton) { text_edit->set_symbol_lookup_word_as_valid(true); } else if (p_symbol.is_relative_path()) { String path = _get_absolute_path(p_symbol); @@ -1849,7 +1854,7 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { bool open_docs = false; bool goto_definition = false; - if (word_at_pos.is_resource_file()) { + if (ScriptServer::is_global_class(word_at_pos) || word_at_pos.is_resource_file()) { open_docs = true; } else { Node *base = get_tree()->get_edited_scene_root(); diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index cd34feb8b3..5536a5d49f 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -1435,11 +1435,11 @@ static bool _guess_expression_type(GDScriptParser::CompletionContext &p_context, } break; case GDScriptParser::Node::SELF: { if (p_context.current_class) { - r_type.type.kind = GDScriptParser::DataType::CLASS; - r_type.type.type_source = GDScriptParser::DataType::INFERRED; - r_type.type.is_constant = true; - r_type.type.class_type = p_context.current_class; - r_type.value = p_context.base; + if (p_context.type != GDScriptParser::COMPLETION_SUPER_METHOD) { + r_type.type = p_context.current_class->get_datatype(); + } else { + r_type.type = p_context.current_class->base_type; + } found = true; } } break; diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index 1944b8db98..eee59606e3 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -2258,9 +2258,8 @@ bool CodeEdit::is_symbol_lookup_on_click_enabled() const { return symbol_lookup_on_click_enabled; } -String CodeEdit::get_text_for_symbol_lookup() { +String CodeEdit::get_text_for_symbol_lookup() const { Point2i mp = get_local_mouse_pos(); - Point2i pos = get_line_column_at_pos(mp, false); int line = pos.y; int col = pos.x; @@ -2269,25 +2268,29 @@ String CodeEdit::get_text_for_symbol_lookup() { return String(); } - StringBuilder lookup_text; + return get_text_with_cursor_char(line, col); +} + +String CodeEdit::get_text_with_cursor_char(int p_line, int p_column) const { const int text_size = get_line_count(); + StringBuilder result; for (int i = 0; i < text_size; i++) { String line_text = get_line(i); - - if (i == line) { - lookup_text += line_text.substr(0, col); + if (i == p_line && p_column >= 0 && p_column <= line_text.size()) { + result += line_text.substr(0, p_column); /* Not unicode, represents the cursor. */ - lookup_text += String::chr(0xFFFF); - lookup_text += line_text.substr(col, line_text.size()); + result += String::chr(0xFFFF); + result += line_text.substr(p_column, line_text.size()); } else { - lookup_text += line_text; + result += line_text; } if (i != text_size - 1) { - lookup_text += "\n"; + result += "\n"; } } - return lookup_text.as_string(); + + return result.as_string(); } void CodeEdit::set_symbol_lookup_word_as_valid(bool p_valid) { @@ -2472,6 +2475,7 @@ void CodeEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("is_symbol_lookup_on_click_enabled"), &CodeEdit::is_symbol_lookup_on_click_enabled); ClassDB::bind_method(D_METHOD("get_text_for_symbol_lookup"), &CodeEdit::get_text_for_symbol_lookup); + ClassDB::bind_method(D_METHOD("get_text_with_cursor_char", "line", "column"), &CodeEdit::get_text_with_cursor_char); ClassDB::bind_method(D_METHOD("set_symbol_lookup_word_as_valid", "valid"), &CodeEdit::set_symbol_lookup_word_as_valid); diff --git a/scene/gui/code_edit.h b/scene/gui/code_edit.h index 6933eb9392..a3c968da60 100644 --- a/scene/gui/code_edit.h +++ b/scene/gui/code_edit.h @@ -455,7 +455,8 @@ public: void set_symbol_lookup_on_click_enabled(bool p_enabled); bool is_symbol_lookup_on_click_enabled() const; - String get_text_for_symbol_lookup(); + String get_text_for_symbol_lookup() const; + String get_text_with_cursor_char(int p_line, int p_column) const; void set_symbol_lookup_word_as_valid(bool p_valid); |