Skip to content

Commit

Permalink
Named enum members now working!
Browse files Browse the repository at this point in the history
  • Loading branch information
Meorge committed Dec 5, 2024
1 parent e77d8cc commit 37b7b51
Showing 1 changed file with 17 additions and 30 deletions.
47 changes: 17 additions & 30 deletions modules/gdscript/gdscript_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,9 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base
}

while (!base_type.has_no_type()) {
// This HashMap is declared up here because it works across both
// the ENUM and BUILTIN cases.
HashMap<String, bool> enum_val_is_deprecated_map;
switch (base_type.kind) {
case GDScriptParser::DataType::CLASS: {
_find_identifiers_in_class(base_type.class_type, p_only_functions, p_types_only, base_type.is_meta_type, false, r_result, p_recursion_depth);
Expand Down Expand Up @@ -1466,15 +1469,18 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base
List<StringName> enum_values;
ClassDB::get_enum_constants(type, type_enum, &enum_values);

// NOTE: I'm not sure this is airtight. EnumDoc doesn't appear
// to have a list of constants for a given enum, so for now I
// think this is the best we can do?
HashMap<String, bool> enum_val_is_deprecated_map;
if (!class_doc_map.has(type)) {
print_error(vformat("Class \"%s\" couldn't be found in doc data by the language server", type));
if (p_base.type.class_type) {
const GDScriptParser::EnumNode *_enum = p_base.type.class_type->get_member(type_enum).m_enum;
for (const GDScriptParser::EnumNode::Value &i : _enum->values) {
enum_val_is_deprecated_map.insert(i.identifier->name, i.doc_data.is_deprecated);
}
} else {
for (const DocData::ConstantDoc &constant_doc : class_doc_map.get(type).constants) {
enum_val_is_deprecated_map.insert(constant_doc.name, constant_doc.is_deprecated);
if (!class_doc_map.has(type)) {
print_error(vformat("Class \"%s\" couldn't be found in doc data by the language server", type));
} else {
for (const DocData::ConstantDoc &constant_doc : class_doc_map.get(type).constants) {
enum_val_is_deprecated_map.insert(constant_doc.name, constant_doc.is_deprecated);
}
}
}

Expand Down Expand Up @@ -1507,28 +1513,6 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base
HashMap<String, bool> member_is_deprecated_map;
if (p_base.value.get_type() != Variant::NIL) {
p_base.value.get_property_list(&members);

// With a named enum, it is internally considered a dictionary
// How do we determine the deprecated field of a dictionary?

// Prints {"ONE"0,"TWO":1}
// so, it's just a regular dict
print_line("p_base.value json string:");
print_line(p_base.type.to_string()); // MyScene.Stuff
print_error(p_base.value.to_json_string()); // {"ONE":0,"TWO":1}

const String variant_name = Variant::get_type_name(p_base.value.get_type());
if (!class_doc_map.has(variant_name)) {
print_error(vformat("Variant \"%s\" couldn't be found in doc data by the language server", variant_name));
} else {
print_line("getting the stuff for variant name", variant_name); // Dictionary
for (const PropertyInfo &i : members) {
print_line(i.name);
}
for (const DocData::PropertyDoc &prop_doc : class_doc_map.get(variant_name).properties) {
member_is_deprecated_map.insert(prop_doc.name, prop_doc.is_deprecated);
}
}
} else {
tmp.get_property_list(&members);
}
Expand All @@ -1543,6 +1527,9 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base
if (base_type.kind == GDScriptParser::DataType::ENUM) {
// Sort enum members in their declaration order.
location += 1;
if (enum_val_is_deprecated_map.has(E.name)) {
option.deprecated = enum_val_is_deprecated_map.get(E.name);
}
}
if (GDScriptParser::theme_color_names.has(E.name)) {
option.theme_color_name = GDScriptParser::theme_color_names[E.name];
Expand Down

0 comments on commit 37b7b51

Please sign in to comment.