You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-13 13:31:48 +00:00
Merge pull request #73196 from Vilcrow/fix-lookup-symbol
Fix jumping to function definition using `Ctrl+LMB` or the "Lookup Symbol" button
This commit is contained in:
@@ -248,12 +248,20 @@
|
|||||||
Returns the full text with char [code]0xFFFF[/code] at the caret location.
|
Returns the full text with char [code]0xFFFF[/code] at the caret location.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="get_text_for_symbol_lookup">
|
<method name="get_text_for_symbol_lookup" qualifiers="const">
|
||||||
<return type="String" />
|
<return type="String" />
|
||||||
<description>
|
<description>
|
||||||
Returns the full text with char [code]0xFFFF[/code] at the cursor location.
|
Returns the full text with char [code]0xFFFF[/code] at the cursor location.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</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">
|
<method name="has_auto_brace_completion_close_key" qualifiers="const">
|
||||||
<return type="bool" />
|
<return type="bool" />
|
||||||
<param index="0" name="close_key" type="String" />
|
<param index="0" name="close_key" type="String" />
|
||||||
|
|||||||
@@ -811,6 +811,8 @@ void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_c
|
|||||||
}
|
}
|
||||||
|
|
||||||
ScriptLanguage::LookupResult result;
|
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)) {
|
if (ScriptServer::is_global_class(p_symbol)) {
|
||||||
EditorNode::get_singleton()->load_resource(ScriptServer::get_global_class_path(p_symbol));
|
EditorNode::get_singleton()->load_resource(ScriptServer::get_global_class_path(p_symbol));
|
||||||
} else if (p_symbol.is_resource_file()) {
|
} 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);
|
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);
|
_goto_line(p_row);
|
||||||
|
|
||||||
switch (result.type) {
|
switch (result.type) {
|
||||||
@@ -944,7 +946,10 @@ void ScriptTextEditor::_validate_symbol(const String &p_symbol) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ScriptLanguage::LookupResult result;
|
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);
|
text_edit->set_symbol_lookup_word_as_valid(true);
|
||||||
} else if (p_symbol.is_relative_path()) {
|
} else if (p_symbol.is_relative_path()) {
|
||||||
String path = _get_absolute_path(p_symbol);
|
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 open_docs = false;
|
||||||
bool goto_definition = 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;
|
open_docs = true;
|
||||||
} else {
|
} else {
|
||||||
Node *base = get_tree()->get_edited_scene_root();
|
Node *base = get_tree()->get_edited_scene_root();
|
||||||
|
|||||||
@@ -1435,11 +1435,11 @@ static bool _guess_expression_type(GDScriptParser::CompletionContext &p_context,
|
|||||||
} break;
|
} break;
|
||||||
case GDScriptParser::Node::SELF: {
|
case GDScriptParser::Node::SELF: {
|
||||||
if (p_context.current_class) {
|
if (p_context.current_class) {
|
||||||
r_type.type.kind = GDScriptParser::DataType::CLASS;
|
if (p_context.type != GDScriptParser::COMPLETION_SUPER_METHOD) {
|
||||||
r_type.type.type_source = GDScriptParser::DataType::INFERRED;
|
r_type.type = p_context.current_class->get_datatype();
|
||||||
r_type.type.is_constant = true;
|
} else {
|
||||||
r_type.type.class_type = p_context.current_class;
|
r_type.type = p_context.current_class->base_type;
|
||||||
r_type.value = p_context.base;
|
}
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|||||||
@@ -2258,9 +2258,8 @@ bool CodeEdit::is_symbol_lookup_on_click_enabled() const {
|
|||||||
return symbol_lookup_on_click_enabled;
|
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 mp = get_local_mouse_pos();
|
||||||
|
|
||||||
Point2i pos = get_line_column_at_pos(mp, false);
|
Point2i pos = get_line_column_at_pos(mp, false);
|
||||||
int line = pos.y;
|
int line = pos.y;
|
||||||
int col = pos.x;
|
int col = pos.x;
|
||||||
@@ -2269,25 +2268,29 @@ String CodeEdit::get_text_for_symbol_lookup() {
|
|||||||
return String();
|
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();
|
const int text_size = get_line_count();
|
||||||
|
StringBuilder result;
|
||||||
for (int i = 0; i < text_size; i++) {
|
for (int i = 0; i < text_size; i++) {
|
||||||
String line_text = get_line(i);
|
String line_text = get_line(i);
|
||||||
|
if (i == p_line && p_column >= 0 && p_column <= line_text.size()) {
|
||||||
if (i == line) {
|
result += line_text.substr(0, p_column);
|
||||||
lookup_text += line_text.substr(0, col);
|
|
||||||
/* Not unicode, represents the cursor. */
|
/* Not unicode, represents the cursor. */
|
||||||
lookup_text += String::chr(0xFFFF);
|
result += String::chr(0xFFFF);
|
||||||
lookup_text += line_text.substr(col, line_text.size());
|
result += line_text.substr(p_column, line_text.size());
|
||||||
} else {
|
} else {
|
||||||
lookup_text += line_text;
|
result += line_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i != text_size - 1) {
|
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) {
|
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("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_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);
|
ClassDB::bind_method(D_METHOD("set_symbol_lookup_word_as_valid", "valid"), &CodeEdit::set_symbol_lookup_word_as_valid);
|
||||||
|
|
||||||
|
|||||||
@@ -455,7 +455,8 @@ public:
|
|||||||
void set_symbol_lookup_on_click_enabled(bool p_enabled);
|
void set_symbol_lookup_on_click_enabled(bool p_enabled);
|
||||||
bool is_symbol_lookup_on_click_enabled() const;
|
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);
|
void set_symbol_lookup_word_as_valid(bool p_valid);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user