1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-07 12:30:27 +00:00

Autocompletion: Add arghint for annotations

This commit is contained in:
HolonProduction
2024-09-07 20:47:34 +02:00
parent 5675c76461
commit 00dfd568e0
2 changed files with 14 additions and 7 deletions

View File

@@ -864,7 +864,8 @@ static void _get_directory_contents(EditorFileSystemDirectory *p_dir, HashMap<St
} }
} }
static void _find_annotation_arguments(const GDScriptParser::AnnotationNode *p_annotation, int p_argument, const String p_quote_style, HashMap<String, ScriptLanguage::CodeCompletionOption> &r_result) { static void _find_annotation_arguments(const GDScriptParser::AnnotationNode *p_annotation, int p_argument, const String p_quote_style, HashMap<String, ScriptLanguage::CodeCompletionOption> &r_result, String &r_arghint) {
r_arghint = _make_arguments_hint(p_annotation->info->info, p_argument, true);
if (p_annotation->name == SNAME("@export_range")) { if (p_annotation->name == SNAME("@export_range")) {
if (p_argument == 3 || p_argument == 4 || p_argument == 5) { if (p_argument == 3 || p_argument == 4 || p_argument == 5) {
// Slider hint. // Slider hint.
@@ -3183,7 +3184,7 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
break; break;
} }
const GDScriptParser::AnnotationNode *annotation = static_cast<const GDScriptParser::AnnotationNode *>(completion_context.node); const GDScriptParser::AnnotationNode *annotation = static_cast<const GDScriptParser::AnnotationNode *>(completion_context.node);
_find_annotation_arguments(annotation, completion_context.current_argument, quote_style, options); _find_annotation_arguments(annotation, completion_context.current_argument, quote_style, options, r_call_hint);
r_forced = true; r_forced = true;
} break; } break;
case GDScriptParser::COMPLETION_BUILT_IN_TYPE_CONSTANT_OR_STATIC_METHOD: { case GDScriptParser::COMPLETION_BUILT_IN_TYPE_CONSTANT_OR_STATIC_METHOD: {

View File

@@ -1639,23 +1639,29 @@ GDScriptParser::AnnotationNode *GDScriptParser::parse_annotation(uint32_t p_vali
advance(); advance();
// Arguments. // Arguments.
push_completion_call(annotation); push_completion_call(annotation);
make_completion_context(COMPLETION_ANNOTATION_ARGUMENTS, annotation, 0);
int argument_index = 0; int argument_index = 0;
do { do {
make_completion_context(COMPLETION_ANNOTATION_ARGUMENTS, annotation, argument_index);
set_last_completion_call_arg(argument_index);
if (check(GDScriptTokenizer::Token::PARENTHESIS_CLOSE)) { if (check(GDScriptTokenizer::Token::PARENTHESIS_CLOSE)) {
// Allow for trailing comma. // Allow for trailing comma.
break; break;
} }
make_completion_context(COMPLETION_ANNOTATION_ARGUMENTS, annotation, argument_index);
set_last_completion_call_arg(argument_index++);
ExpressionNode *argument = parse_expression(false); ExpressionNode *argument = parse_expression(false);
if (argument == nullptr) { if (argument == nullptr) {
push_error("Expected expression as the annotation argument."); push_error("Expected expression as the annotation argument.");
valid = false; valid = false;
continue; } else {
}
annotation->arguments.push_back(argument); annotation->arguments.push_back(argument);
if (argument->type == Node::LITERAL) {
override_completion_context(argument, COMPLETION_ANNOTATION_ARGUMENTS, annotation, argument_index);
}
}
argument_index++;
} while (match(GDScriptTokenizer::Token::COMMA) && !is_at_end()); } while (match(GDScriptTokenizer::Token::COMMA) && !is_at_end());
pop_multiline(); pop_multiline();