From e17b225fe055e2eb5ddd4a5b89f2b13d6001884b Mon Sep 17 00:00:00 2001 From: Brad Lewis <22850972+BradLewis@users.noreply.github.com> Date: Sat, 13 Sep 2025 19:56:30 -0400 Subject: Resolve selector completions when a selector expr within a selector call expr --- src/server/completion.odin | 2 ++ src/server/position_context.odin | 5 ++++- tests/completions_test.odin | 28 ++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/server/completion.odin b/src/server/completion.odin index aceff60..7e789f0 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -101,6 +101,8 @@ get_completion_list :: proc( if !position_in_node(selector_call.call, position_context.position) { completion_type = .Selector } + } else if selector, ok := position_context.selector_expr.derived.(^ast.Selector_Expr); ok { + completion_type = .Selector } } 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 diff --git a/src/server/position_context.odin b/src/server/position_context.odin index d5e7d33..0417df8 100644 --- a/src/server/position_context.odin +++ b/src/server/position_context.odin @@ -649,7 +649,10 @@ get_document_position_node :: proc(node: ^ast.Node, position_context: ^DocumentP } } case ^Selector_Expr: - if position_context.hint == .Definition || position_context.hint == .Hover && n.field != nil { + if position_context.hint == .Definition || + position_context.hint == .Hover || + position_context.hint == .SignatureHelp || + position_context.hint == .Completion { position_context.selector = n.expr position_context.field = n.field position_context.selector_expr = node diff --git a/tests/completions_test.odin b/tests/completions_test.odin index d3a2eb7..303fd64 100644 --- a/tests/completions_test.odin +++ b/tests/completions_test.odin @@ -4698,3 +4698,31 @@ ast_completion_struct_field_value :: proc(t: ^testing.T) { } test.expect_completion_docs(t, &source, "", {"test.Foo: struct {}"}) } + +@(test) +ast_completion_selector_within_selector_call_expr :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + + Data :: struct { + x, y: int, + } + + IFoo :: struct { + bar: proc(self: IFoo, x: int), + } + + print :: proc(self: IFoo, x: int) {} + + main :: proc() { + data := Data{} + foo := IFoo { + bar = print, + } + + foo->bar(data.x{*}) + } + `, + } + test.expect_completion_docs(t, &source, "", {"Data.x: int", "Data.y: int"}) +} -- cgit v1.2.3