From f4643943293c6215daa25f73df346b78cabc232d Mon Sep 17 00:00:00 2001 From: Magian Date: Sat, 17 Jun 2023 14:44:56 +0800 Subject: [PATCH] C# Go To Method for external editor --- modules/mono/csharp_script.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index f46bb7ee844..6996c934021 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -32,6 +32,7 @@ #include "godotsharp_dirs.h" #include "managed_callable.h" +#include "modules/regex/regex.h" #include "mono_gd/gd_mono_cache.h" #include "signal_awaiter_utils.h" #include "utils/macros.h" @@ -2722,7 +2723,23 @@ void CSharpScript::get_script_property_list(List *r_list) const { int CSharpScript::get_member_line(const StringName &p_member) const { // TODO omnisharp - return -1; + int p_line = -1; + RegEx pattern("\\w+\\s{0,}" + p_member + "\\s{0,}\\([^()]*\\)\\s{0,}\\{{1,}"); + Ref ref = pattern.search(get_source_code()); + if (ref != NULL) { + RegExMatch *match = ref.ptr(); + String tmp_str = match->get_string(0).split("\n")[0]; + + Vector source_code_line = get_source_code().split("\n"); + for (int i = 0; i < source_code_line.size(); i = i + 1) { + int tmp_col = source_code_line[i].find(tmp_str); + if (tmp_col > 0) { + p_line = i; + break; + } + } + } + return p_line; } const Variant CSharpScript::get_rpc_config() const {