Merge pull request #86176 from dalexeev/gds-fix-type-highlighting
GDScript: Fix type highlighting
This commit is contained in:
commit
a8cfd1436a
|
@ -63,13 +63,15 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
|
||||||
bool in_member_variable = false;
|
bool in_member_variable = false;
|
||||||
bool in_lambda = false;
|
bool in_lambda = false;
|
||||||
|
|
||||||
bool in_function_name = false;
|
bool in_function_name = false; // Any call.
|
||||||
bool in_variable_declaration = false;
|
bool in_function_declaration = false; // Only declaration.
|
||||||
|
bool in_var_const_declaration = false;
|
||||||
bool in_signal_declaration = false;
|
bool in_signal_declaration = false;
|
||||||
bool expect_type = false;
|
bool expect_type = false;
|
||||||
|
|
||||||
int in_function_args = 0;
|
int in_declaration_params = 0; // The number of opened `(` after func/signal name.
|
||||||
int in_function_arg_dicts = 0;
|
int in_declaration_param_dicts = 0; // The number of opened `{` inside func params.
|
||||||
|
int in_type_params = 0; // The number of opened `[` after type name.
|
||||||
|
|
||||||
Color keyword_color;
|
Color keyword_color;
|
||||||
Color color;
|
Color color;
|
||||||
|
@ -445,12 +447,15 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
|
||||||
|
|
||||||
if (str[k] == '(') {
|
if (str[k] == '(') {
|
||||||
in_function_name = true;
|
in_function_name = true;
|
||||||
} else if (prev_text == GDScriptTokenizer::get_token_name(GDScriptTokenizer::Token::VAR) || prev_text == GDScriptTokenizer::get_token_name(GDScriptTokenizer::Token::FOR)) {
|
if (prev_text == GDScriptTokenizer::get_token_name(GDScriptTokenizer::Token::FUNC)) {
|
||||||
in_variable_declaration = true;
|
in_function_declaration = true;
|
||||||
|
}
|
||||||
|
} else if (prev_text == GDScriptTokenizer::get_token_name(GDScriptTokenizer::Token::VAR) || prev_text == GDScriptTokenizer::get_token_name(GDScriptTokenizer::Token::FOR) || prev_text == GDScriptTokenizer::get_token_name(GDScriptTokenizer::Token::CONST)) {
|
||||||
|
in_var_const_declaration = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for lambda.
|
// Check for lambda.
|
||||||
if (in_function_name && prev_text == GDScriptTokenizer::get_token_name(GDScriptTokenizer::Token::FUNC)) {
|
if (in_function_declaration) {
|
||||||
k = j - 1;
|
k = j - 1;
|
||||||
while (k > 0 && is_whitespace(str[k])) {
|
while (k > 0 && is_whitespace(str[k])) {
|
||||||
k--;
|
k--;
|
||||||
|
@ -475,48 +480,60 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_a_symbol) {
|
if (is_a_symbol) {
|
||||||
if (in_function_args > 0) {
|
if (in_declaration_params > 0) {
|
||||||
switch (str[j]) {
|
switch (str[j]) {
|
||||||
case '(':
|
case '(':
|
||||||
in_function_args += 1;
|
in_declaration_params += 1;
|
||||||
break;
|
break;
|
||||||
case ')':
|
case ')':
|
||||||
in_function_args -= 1;
|
in_declaration_params -= 1;
|
||||||
break;
|
break;
|
||||||
case '{':
|
case '{':
|
||||||
in_function_arg_dicts += 1;
|
in_declaration_param_dicts += 1;
|
||||||
break;
|
break;
|
||||||
case '}':
|
case '}':
|
||||||
in_function_arg_dicts -= 1;
|
in_declaration_param_dicts -= 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (in_function_name && str[j] == '(') {
|
} else if ((in_function_declaration || in_signal_declaration || prev_text == GDScriptTokenizer::get_token_name(GDScriptTokenizer::Token::FUNC)) && str[j] == '(') {
|
||||||
in_function_args = 1;
|
in_declaration_params = 1;
|
||||||
in_function_arg_dicts = 0;
|
in_declaration_param_dicts = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expect_type && (prev_is_char || str[j] == '=') && str[j] != '[' && str[j] != ',' && str[j] != '.') {
|
if (expect_type) {
|
||||||
expect_type = false;
|
switch (str[j]) {
|
||||||
}
|
case '[':
|
||||||
|
in_type_params += 1;
|
||||||
if (j > 0 && str[j - 1] == '-' && str[j] == '>') {
|
break;
|
||||||
expect_type = true;
|
case ']':
|
||||||
}
|
in_type_params -= 1;
|
||||||
|
break;
|
||||||
if (in_variable_declaration || in_function_args > 0) {
|
case ',':
|
||||||
int k = j;
|
if (in_type_params <= 0) {
|
||||||
// Skip space.
|
expect_type = false;
|
||||||
while (k < line_length && is_whitespace(str[k])) {
|
}
|
||||||
k++;
|
break;
|
||||||
|
case ' ':
|
||||||
|
case '\t':
|
||||||
|
case '.':
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
expect_type = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if (str[k] == ':' && in_function_arg_dicts == 0) {
|
if (j > 0 && str[j - 1] == '-' && str[j] == '>') {
|
||||||
// Has type hint.
|
|
||||||
expect_type = true;
|
expect_type = true;
|
||||||
|
in_type_params = 0;
|
||||||
|
}
|
||||||
|
if ((in_var_const_declaration || (in_declaration_params == 1 && in_declaration_param_dicts == 0)) && str[j] == ':') {
|
||||||
|
expect_type = true;
|
||||||
|
in_type_params = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
in_variable_declaration = false;
|
in_function_declaration = false;
|
||||||
|
in_var_const_declaration = false;
|
||||||
in_signal_declaration = false;
|
in_signal_declaration = false;
|
||||||
in_function_name = false;
|
in_function_name = false;
|
||||||
in_lambda = false;
|
in_lambda = false;
|
||||||
|
@ -582,7 +599,7 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
|
||||||
color = member_color;
|
color = member_color;
|
||||||
} else if (in_function_name) {
|
} else if (in_function_name) {
|
||||||
next_type = FUNCTION;
|
next_type = FUNCTION;
|
||||||
if (!in_lambda && prev_text == GDScriptTokenizer::get_token_name(GDScriptTokenizer::Token::FUNC)) {
|
if (!in_lambda && in_function_declaration) {
|
||||||
color = function_definition_color;
|
color = function_definition_color;
|
||||||
} else {
|
} else {
|
||||||
color = function_color;
|
color = function_color;
|
||||||
|
|
Loading…
Reference in New Issue