| 3452 | } |
| 3453 | |
| 3454 | ::Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path, Object *p_owner, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_forced, String &r_call_hint) { |
| 3455 | const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\""; |
| 3456 | |
| 3457 | GDScriptParser parser; |
| 3458 | GDScriptAnalyzer analyzer(&parser); |
| 3459 | |
| 3460 | parser.parse(p_code, p_path, true); |
| 3461 | analyzer.analyze(); |
| 3462 | |
| 3463 | r_forced = false; |
| 3464 | HashMap<String, ScriptLanguage::CodeCompletionOption> options; |
| 3465 | |
| 3466 | GDScriptParser::CompletionContext completion_context = parser.get_completion_context(); |
| 3467 | if (completion_context.current_class != nullptr && completion_context.current_class->outer == nullptr) { |
| 3468 | completion_context.base = p_owner; |
| 3469 | } |
| 3470 | bool is_function = false; |
| 3471 | |
| 3472 | switch (completion_context.type) { |
| 3473 | case GDScriptParser::COMPLETION_NONE: |
| 3474 | break; |
| 3475 | case GDScriptParser::COMPLETION_ANNOTATION: { |
| 3476 | List<MethodInfo> annotations; |
| 3477 | parser.get_annotation_list(&annotations); |
| 3478 | for (const MethodInfo &E : annotations) { |
| 3479 | ScriptLanguage::CodeCompletionOption option(E.name.substr(1), ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT); |
| 3480 | if (E.arguments.size() > 0) { |
| 3481 | option.insert_text += "("; |
| 3482 | } |
| 3483 | options.insert(option.display, option); |
| 3484 | } |
| 3485 | r_forced = true; |
| 3486 | } break; |
| 3487 | case GDScriptParser::COMPLETION_ANNOTATION_ARGUMENTS: { |
| 3488 | if (completion_context.node == nullptr || completion_context.node->type != GDScriptParser::Node::ANNOTATION) { |
| 3489 | break; |
| 3490 | } |
| 3491 | const GDScriptParser::AnnotationNode *annotation = static_cast<const GDScriptParser::AnnotationNode *>(completion_context.node); |
| 3492 | _find_annotation_arguments(annotation, completion_context.current_argument, quote_style, options, r_call_hint); |
| 3493 | r_forced = true; |
| 3494 | } break; |
| 3495 | case GDScriptParser::COMPLETION_BUILT_IN_TYPE_CONSTANT_OR_STATIC_METHOD: { |
| 3496 | // Constants. |
| 3497 | { |
| 3498 | List<StringName> constants; |
| 3499 | Variant::get_constants_for_type(completion_context.builtin_type, &constants); |
| 3500 | for (const StringName &E : constants) { |
| 3501 | ScriptLanguage::CodeCompletionOption option(E, ScriptLanguage::CODE_COMPLETION_KIND_CONSTANT); |
| 3502 | bool valid = false; |
| 3503 | Variant default_value = Variant::get_constant_value(completion_context.builtin_type, E, &valid); |
| 3504 | if (valid) { |
| 3505 | option.default_value = default_value; |
| 3506 | } |
| 3507 | options.insert(option.display, option); |
| 3508 | } |
| 3509 | } |
| 3510 | // Methods. |
| 3511 | { |