diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2023-10-05 22:49:47 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-10-05 22:49:47 +0200 |
commit | 1edf0f35b151ab3a8e3140aeaef08609e011ebdb (patch) | |
tree | 38d22578c27fca972a731f0f1de31a3571b82aa6 | |
parent | 68926d591987b2036d66f5216ad0a20ee2c40590 (diff) | |
parent | 978fcaf1b45bed9522008db29b5f11ecf48dbad3 (diff) | |
download | redot-engine-1edf0f35b151ab3a8e3140aeaef08609e011ebdb.tar.gz |
Merge pull request #82326 from adeneve/gdscript_dict_highlighter_fix
Fix for GDScriptHighlighter dictionaries as function arguments
-rw-r--r-- | modules/gdscript/editor/gdscript_highlighter.cpp | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp index 2bfa191ff1..45ac142eaa 100644 --- a/modules/gdscript/editor/gdscript_highlighter.cpp +++ b/modules/gdscript/editor/gdscript_highlighter.cpp @@ -63,11 +63,13 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l bool in_lambda = false; bool in_function_name = false; - bool in_function_args = false; bool in_variable_declaration = false; bool in_signal_declaration = false; bool expect_type = false; + int in_function_args = 0; + int in_function_arg_dicts = 0; + Color keyword_color; Color color; @@ -472,12 +474,24 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l } if (is_a_symbol) { - if (in_function_name) { - in_function_args = true; - } - - if (in_function_args && str[j] == ')') { - in_function_args = false; + if (in_function_args > 0) { + switch (str[j]) { + case '(': + in_function_args += 1; + break; + case ')': + in_function_args -= 1; + break; + case '{': + in_function_arg_dicts += 1; + break; + case '}': + in_function_arg_dicts -= 1; + break; + } + } else if (in_function_name && str[j] == '(') { + in_function_args = 1; + in_function_arg_dicts = 0; } if (expect_type && (prev_is_char || str[j] == '=') && str[j] != '[' && str[j] != '.') { @@ -488,15 +502,15 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l expect_type = true; } - if (in_variable_declaration || in_function_args) { + if (in_variable_declaration || in_function_args > 0) { int k = j; - // Skip space + // Skip space. while (k < line_length && is_whitespace(str[k])) { k++; } - if (str[k] == ':') { - // has type hint + if (str[k] == ':' && in_function_arg_dicts == 0) { + // Has type hint. expect_type = true; } } |