Skip to content

Commit

Permalink
GDScript: Fix for expression is highlighted as type
Browse files Browse the repository at this point in the history
  • Loading branch information
dalexeev committed Mar 18, 2024
1 parent fe01776 commit c452425
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions modules/gdscript/editor/gdscript_highlighter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l

bool in_function_name = false; // Any call.
bool in_function_declaration = false; // Only declaration.
bool in_var_const_declaration = false;
bool in_signal_declaration = false;
bool is_after_func_signal_declaration = false;
bool in_var_const_declaration = false;
bool is_after_var_const_declaration = false;
bool expect_type = false;

int in_declaration_params = 0; // The number of opened `(` after func/signal name.
Expand Down Expand Up @@ -410,6 +412,8 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
col = class_names[word];
} else if (reserved_keywords.has(word)) {
col = reserved_keywords[word];
// Don't highlight `list` as a type in `for elem: Type in list`.
expect_type = false;
} else if (member_keywords.has(word)) {
col = member_keywords[word];
}
Expand Down Expand Up @@ -480,6 +484,13 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
}

if (is_a_symbol) {
if (in_function_declaration || in_signal_declaration) {
is_after_func_signal_declaration = true;
}
if (in_var_const_declaration) {
is_after_var_const_declaration = true;
}

if (in_declaration_params > 0) {
switch (str[j]) {
case '(':
Expand All @@ -495,7 +506,7 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
in_declaration_param_dicts -= 1;
break;
}
} else if ((in_function_declaration || in_signal_declaration || prev_text == GDScriptTokenizer::get_token_name(GDScriptTokenizer::Token::FUNC)) && str[j] == '(') {
} else if ((is_after_func_signal_declaration || prev_text == GDScriptTokenizer::get_token_name(GDScriptTokenizer::Token::FUNC)) && str[j] == '(') {
in_declaration_params = 1;
in_declaration_param_dicts = 0;
}
Expand Down Expand Up @@ -526,19 +537,22 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
expect_type = true;
in_type_params = 0;
}
if ((in_var_const_declaration || (in_declaration_params == 1 && in_declaration_param_dicts == 0)) && str[j] == ':') {
if ((is_after_var_const_declaration || (in_declaration_params == 1 && in_declaration_param_dicts == 0)) && str[j] == ':') {
expect_type = true;
in_type_params = 0;
}
}

in_function_name = false;
in_function_declaration = false;
in_signal_declaration = false;
in_var_const_declaration = false;
in_lambda = false;
in_member_variable = false;

if (!is_whitespace(str[j])) {
in_function_declaration = false;
in_var_const_declaration = false;
in_signal_declaration = false;
in_function_name = false;
in_lambda = false;
in_member_variable = false;
is_after_func_signal_declaration = false;
is_after_var_const_declaration = false;
}
}

Expand Down

0 comments on commit c452425

Please sign in to comment.