From 40fdad6b5a2ffddc464cc8ebc4e560cdfd77924d Mon Sep 17 00:00:00 2001 From: Daniel Gavin Date: Fri, 4 Nov 2022 19:16:56 +0100 Subject: Fix completion on call expr that return structs --- src/server/completion.odin | 11 ++++++----- tests/completions_test.odin | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/server/completion.odin b/src/server/completion.odin index e8c3a4a..7c3b397 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -100,7 +100,7 @@ get_completion_list :: proc( if position_context.import_stmt != nil { completion_type = .Package } - + done: if position_context.switch_type_stmt != nil && position_context.case_clause != nil { @@ -130,7 +130,7 @@ get_completion_list :: proc( if position_context.basic_lit != nil { if _, ok := position_context.basic_lit.derived.(^ast.Basic_Lit); ok { return list, true - } + } } switch completion_type { @@ -295,7 +295,8 @@ get_selector_completion :: proc( if selector.type != .Variable && selector.type != .Package && - selector.type != .Enum { + selector.type != .Enum && + selector.type != .Function { return } @@ -1042,8 +1043,8 @@ get_identifier_completion :: proc( if position_context.identifier != nil { if ident, ok := position_context.identifier.derived.(^ast.Ident); ok { lookup_name = ident.name - } - } + } + } pkgs := make([dynamic]string, context.temp_allocator) diff --git a/tests/completions_test.odin b/tests/completions_test.odin index 21b89a2..d8a5d82 100644 --- a/tests/completions_test.odin +++ b/tests/completions_test.odin @@ -2031,3 +2031,28 @@ ast_vector_with_matrix_mult :: proc(t: ^testing.T) { test.expect_completion_details(t, &source, "", {"test.my_vector: [4]f32"}) } + +@(test) +ast_completion_on_call_expr :: proc(t: ^testing.T) { + source := test.Source { + main = `package main + My_Struct :: struct { + a: int, + b: int, + } + + my_function :: proc() -> My_Struct {} + + main :: proc() { + my_function().{*} + } + `, + } + + test.expect_completion_details( + t, + &source, + ".", + {"My_Struct.a: int", "My_Struct.b: int"}, + ) +} -- cgit v1.2.3