Skip to content

Commit

Permalink
Support completion on comp literals for enumerated arrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielGavin committed Oct 3, 2024
1 parent 2e20163 commit 866b0ca
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/server/completion.odin
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,35 @@ get_implicit_completion :: proc(
reset_ast_context(ast_context)
}

/*
if it's comp literals for enumerated array:
asset_paths := [Asset]cstring {
.Layer0 = "assets/layer0.png",
}
Right now `core:odin/parser` is not tolerant enough, so I just look at the type and if it's a enumerated array. I can't get the field value is on the left side.
*/
if position_context.comp_lit != nil {
if symbol, ok := resolve_type_expression(ast_context, position_context.comp_lit); ok {
if symbol_value, ok := symbol.value.(SymbolFixedArrayValue); ok {
if enum_value, ok := unwrap_enum(ast_context, symbol_value.len); ok {
for enum_name in enum_value.names {
item := CompletionItem {
label = enum_name,
kind = .EnumMember,
detail = enum_name,
}

append(&items, item)
}

list.items = items[:]
return
}
}
}
}

//infer bitset and enums based on the identifier comp_lit, i.e. a := My_Struct { my_ident = . }
if position_context.comp_lit != nil {
if position_context.parent_comp_lit.type != nil {
Expand Down

0 comments on commit 866b0ca

Please sign in to comment.