diff options
| author | Bradley Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-08-11 15:54:04 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-11 15:54:04 -0400 |
| commit | 251b6bdd3fd599f8fecda2a1a80fea66eded17c9 (patch) | |
| tree | 4638e342bfc35e80bd4cea651c7821dbe67ab645 | |
| parent | 3d1b2d482f9c1e0ddb0c3acf2890724f36b51643 (diff) | |
| parent | d31fe63071eb65dd57f9fe08442ce45d3688201d (diff) | |
Merge pull request #849 from BradLewis/fix/enum-variadic-args
Completions for variadic args
| -rw-r--r-- | src/server/completion.odin | 6 | ||||
| -rw-r--r-- | src/server/symbol.odin | 4 | ||||
| -rw-r--r-- | tests/completions_test.odin | 36 |
3 files changed, 45 insertions, 1 deletions
diff --git a/src/server/completion.odin b/src/server/completion.odin index 9430235..d1a630a 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -107,7 +107,11 @@ get_completion_list :: proc( completion_type = .Selector } } - } else { + } else if _, ok := position_context.selector.derived.(^ast.Implicit_Selector_Expr); !ok { + // variadic args seem to work by setting it as an implicit selector expr, in that case + // we want an identifier (eg. foo :: proc(args: ..{*})) + + // Otherwise it's a selector completion_type = .Selector } } diff --git a/src/server/symbol.odin b/src/server/symbol.odin index 77c4cb0..cf2c4ed 100644 --- a/src/server/symbol.odin +++ b/src/server/symbol.odin @@ -557,6 +557,10 @@ get_proc_arg_count :: proc(v: SymbolProcedureValue) -> int { get_proc_arg_type_from_index :: proc(value: SymbolProcedureValue, parameter_index: int) -> (^ast.Field, bool) { index := 0 for arg in value.arg_types { + // We're in a variadic arg, so return true + if _, ok := arg.type.derived.(^ast.Ellipsis); ok { + return arg, true + } for name in arg.names { if index == parameter_index { return arg, true diff --git a/tests/completions_test.odin b/tests/completions_test.odin index 58e5c11..675002e 100644 --- a/tests/completions_test.odin +++ b/tests/completions_test.odin @@ -4287,3 +4287,39 @@ ast_completion_proc_field_names :: proc(t: ^testing.T) { } test.expect_completion_docs( t, &source, "", {"test.bar: string"}) } + +@(test) +ast_completion_enum_variadiac_args :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + Foo :: enum { + A, + B, + C, + } + + foo :: proc(foos: ..Foo) {} + + main :: proc() { + foo(.A, .{*}) + } + `, + } + test.expect_completion_docs( t, &source, "", {"A", "B", "C"}) +} + +@(test) +ast_completion_proc_variadiac_arg :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + Foo :: enum { + A, + B, + C, + } + + foo :: proc(foos: ..{*}) {} + `, + } + test.expect_completion_docs( t, &source, "", {"test.Foo: enum {..}"}) +} |