Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDScript: Fix for expression is highlighted as type #89659

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading