Skip to content

Commit

Permalink
Add support for enumerated arrays in range loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielGavin committed Aug 10, 2024
1 parent 7c29d7f commit 62a7d1d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 13 deletions.
45 changes: 32 additions & 13 deletions src/server/analysis.odin
Original file line number Diff line number Diff line change
Expand Up @@ -3121,19 +3121,38 @@ get_locals_for_range_stmt :: proc(

if len(stmt.vals) >= 2 {
if ident, ok := unwrap_ident(stmt.vals[1]); ok {
store_local(
ast_context,
ident,
make_int_ast(ast_context, ident.pos, ident.end),
ident.pos.offset,
ident.name,
ast_context.local_id,
ast_context.non_mutable_only,
false,
true,
symbol.pkg,
false,
)
//Look for enumarated arrays
if len_symbol, ok := resolve_type_expression(ast_context, v.len); ok {
if _, is_enum := len_symbol.value.(SymbolEnumValue); is_enum {
store_local(
ast_context,
ident,
v.len,
ident.pos.offset,
ident.name,
ast_context.local_id,
ast_context.non_mutable_only,
false,
true,
len_symbol.pkg,
false,
)
}
} else {
store_local(
ast_context,
ident,
make_int_ast(ast_context, ident.pos, ident.end),
ident.pos.offset,
ident.name,
ast_context.local_id,
ast_context.non_mutable_only,
false,
true,
symbol.pkg,
false,
)
}
}
}
case SymbolSliceValue:
Expand Down
28 changes: 28 additions & 0 deletions tests/completions_test.odin
Original file line number Diff line number Diff line change
Expand Up @@ -2823,6 +2823,34 @@ ast_enumerated_array_index_completion :: proc(t: ^testing.T) {
test.expect_completion_labels(t, &source, ".", {"North", "East", "South", "West"})
}


@(test)
ast_enumerated_array_range_completion :: proc(t: ^testing.T) {
source := test.Source {
main = `package main
Enum :: enum {
Foo,
Bar,
Baz,
}
ARRAY :: [Enum]string{
.Foo = "foo",
.Bar = "bar",
.Baz = "baz",
}
main :: proc() {
for item, indezx in ARRAY {
indez{*}
}
}
`,
}

test.expect_completion_details(t, &source, "", {"test.indezx: Enum"})
}

@(test)
ast_raw_data_slice :: proc(t: ^testing.T) {
source := test.Source {
Expand Down

0 comments on commit 62a7d1d

Please sign in to comment.