diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2025-07-15 15:10:50 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-15 15:10:50 +0200 |
| commit | 5dcf2252629655d45ea4e3169f003b4010665fd6 (patch) | |
| tree | 9244232317b9568a4b4ab3f0f0a14d60b484b90e | |
| parent | 71f577c7b22db5e74f38b23dbc171a7c4de8113c (diff) | |
| parent | d2a6b208bf6a9d62400b9134f557658ea4ad9b83 (diff) | |
Merge pull request #749 from BradLewis/fix/proc-implicit-selector
Correctly resolve proc param type
| -rw-r--r-- | src/server/analysis.odin | 15 | ||||
| -rw-r--r-- | src/server/completion.odin | 5 | ||||
| -rw-r--r-- | tests/completions_test.odin | 20 |
3 files changed, 38 insertions, 2 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 170bf37..0c3178a 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -659,6 +659,21 @@ get_procedure_arg_count :: proc(v: SymbolProcedureValue) -> int { return total } +// Gets the call argument type at the specified index +get_proc_call_argument_type :: proc(value: SymbolProcedureValue, parameter_index: int) -> (^ast.Field, bool) { + index := 0 + for arg in value.arg_types { + for name in arg.names { + if index == parameter_index { + return arg, true + } + index += 1 + } + } + + return nil, false +} + /* Figure out which function the call expression is using out of the list from proc group */ diff --git a/src/server/completion.odin b/src/server/completion.odin index 2abf3b2..1381967 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -1171,11 +1171,12 @@ get_implicit_completion :: proc( } if proc_value, ok := symbol.value.(SymbolProcedureValue); ok { - if len(proc_value.arg_types) <= parameter_index { + arg_type, arg_type_ok := get_proc_call_argument_type(proc_value, parameter_index) + if !arg_type_ok { return } - if enum_value, ok := unwrap_enum(ast_context, proc_value.arg_types[parameter_index].type); ok { + if enum_value, ok := unwrap_enum(ast_context, arg_type.type); ok { for name in enum_value.names { item := CompletionItem { label = name, diff --git a/tests/completions_test.odin b/tests/completions_test.odin index 70e12d6..eacdc3d 100644 --- a/tests/completions_test.odin +++ b/tests/completions_test.odin @@ -3855,3 +3855,23 @@ ast_completion_struct_field_enum :: proc(t: ^testing.T) { } test.expect_completion_details(t, &source, "", {"Bar.foo: test.Foo"}) } + +@(test) +ast_completion_proc_enum_param :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + + Foo :: enum { + A, + B + } + + bar :: proc(a, b: int, foo: Foo) {} + + main :: proc() { + bar(1, 1, .{*}) + } + `, + } + test.expect_completion_details(t, &source, "", {"A", "B"}) +} |